Ignore:
Timestamp:
11/10/05 05:21:07 (19 years ago)
Author:
Nicholas Riley
Message:

StreamVision.py: XTension support for turning on/off stereo (can't
restrict to only if APX is enabled, unfortunately); rating support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StreamVision/StreamVision.py

    r195 r199  
    5858    return name
    5959
    60 def iTunesApp():
    61     return app(id='com.apple.iTunes')
     60def iTunesApp(): return app(id='com.apple.iTunes')
     61def XTensionApp(): return app(creator='SHEx')
     62
     63HAVE_XTENSION = False
     64try:
     65    XTensionApp()
     66    HAVE_XTENSION = True
     67except:
     68    pass
    6269
    6370class StreamVision(NSApplication):
     
    7784                if artwork:
    7885                    kw['pictImage'] = artwork[0].data.get()
    79                 growlNotify(iTunes.current_track.name.get(),
     86                growlNotify(iTunes.current_track.name.get() + '  ' +
     87                            '★' * (iTunes.current_track.rating.get() / 20),
    8088                            iTunes.current_track.album.get() + "\n" +
    8189                            iTunes.current_track.artist.get(),
     
    104112        self.hotKeyActions[_StreamVision.HotKeyAddress(hotKeyRef)] = func
    105113
     114    def incrementRatingBy(self, increment):
     115        iTunes = iTunesApp()
     116        rating = iTunes.current_track.rating.get()
     117        rating += increment
     118        if rating < 0:
     119            rating = 0
     120            NSBeep()
     121        elif rating > 100:
     122            rating = 100
     123            NSBeep()
     124        iTunes.current_track.rating.set(rating)
     125
     126    def playPause(self):
     127        iTunes = iTunesApp()
     128        iTunes.playpause()
     129        if HAVE_XTENSION:
     130            if iTunes.player_state() == k.playing:
     131                XTensionApp().turnon('Stereo')
     132            else:
     133                XTensionApp().turnoff('Stereo')
     134
    106135    def finishLaunching(self):
    107136        super(StreamVision, self).finishLaunching()
    108137        self.registerHotKey(self.displayTrackInfo, 100) # F8
    109138        self.registerHotKey(self.goToSite, 100, cmdKey) # cmd-F8
    110         self.registerHotKey(lambda: iTunesApp().playpause(), 101) # F9
     139        self.registerHotKey(self.playPause, 101) # F9
    111140        self.registerHotKey(lambda: iTunesApp().previous_track(), 109) # F10
    112141        self.registerHotKey(lambda: iTunesApp().next_track(), 103) # F11
     142        self.registerHotKey(lambda: self.incrementRatingBy(-20), 109, cmdKey) # cmd-F10
     143        self.registerHotKey(lambda: self.incrementRatingBy(20), 103, cmdKey) # cmd-F11
    113144        NSDistributedNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, self.displayTrackInfo, 'com.apple.iTunes.playerInfo', None)
    114145
Note: See TracChangeset for help on using the changeset viewer.