Ignore:
Timestamp:
01/29/06 22:59:56 (19 years ago)
Author:
Nicholas Riley
Message:

setup.py: use HotKey module (shared with LocationDo) instead of
_StreamVision module

HotKeymodule.c: the aforementioned module

StreamVision.py: use HotKey module instead of _StreamVision module.
Fix StreamVision.displayTrackInfo to not crash when iTunes jealously
hides the names of iTMS tracks from us. Switch track rating keys to
shift-F10/F11 to avoid conflicting with my preferred Expose/Dashboard
key bindings on my iBook.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StreamVision/StreamVision.py

    r200 r211  
    77from PyObjCTools import AppHelper
    88from Carbon.CarbonEvt import RegisterEventHotKey, GetApplicationEventTarget
    9 from Carbon.Events import cmdKey
     9from Carbon.Events import cmdKey, shiftKey
    1010import struct
    1111import scrape
    12 import _StreamVision
     12import HotKey
    1313
    1414GROWL_APP_NAME = 'StreamVision'
     
    7575    def displayTrackInfo(self):
    7676        iTunes = iTunesApp()
    77         if iTunes.player_state.get() == k.playing:
    78             if iTunes.current_track.class_.get() == k.URL_track:
    79                 growlNotify(cleanStreamTitle(iTunes.current_stream_title.get()),
    80                             cleanStreamTrackName(iTunes.current_track.name.get()))
    81             else:
    82                 kw = {}
    83                 artwork = iTunes.current_track.artworks.get()
    84                 if artwork:
    85                     kw['pictImage'] = artwork[0].data.get()
    86                 growlNotify(iTunes.current_track.name.get() + '  ' +
    87                             '★' * (iTunes.current_track.rating.get() / 20),
    88                             iTunes.current_track.album.get() + "\n" +
    89                             iTunes.current_track.artist.get(),
    90                             **kw)
    91         else:
    92             trackName = ''
    93             if iTunes.current_track.class_.get() != k.Property:
    94                 trackName = iTunes.current_track.name.get()
    95             growlNotify("iTunes is not playing.", trackName)
     77
     78        trackClass = iTunes.current_track.class_.get()
     79        trackName = ''
     80        if trackClass != k.Property:
     81            trackName = iTunes.current_track.name.get()
     82
     83        if iTunes.player_state.get() != k.playing:
     84            growlNotify('iTunes is not playing.', trackName)
     85            return
     86        if trackClass == k.URL_track:
     87            growlNotify(cleanStreamTitle(iTunes.current_stream_title.get()),
     88                        cleanStreamTrackName(trackName))
     89            return
     90        if trackClass == k.Property:
     91           growlNotify('iTunes is playing.', '')
     92           return
     93        kw = {}
     94        # XXX iTunes doesn't let you get artwork for shared tracks
     95        if trackClass != k.shared_track:
     96            artwork = iTunes.current_track.artworks.get()
     97            if artwork:
     98                kw['pictImage'] = artwork[0].data.get()
     99        growlNotify(trackName + '  ' +
     100                    '★' * (iTunes.current_track.rating.get() / 20),
     101                    iTunes.current_track.album.get() + "\n" +
     102                    iTunes.current_track.artist.get(),
     103                    **kw)
    96104
    97105    def goToSite(self):
     
    110118                                        GetApplicationEventTarget(), 0)
    111119        self.hotKeys.append(hotKeyRef)
    112         self.hotKeyActions[_StreamVision.HotKeyAddress(hotKeyRef)] = func
     120        self.hotKeyActions[HotKey.HotKeyAddress(hotKeyRef)] = func
    113121
    114122    def incrementRatingBy(self, increment):
     
    140148        self.registerHotKey(lambda: iTunesApp().previous_track(), 109) # F10
    141149        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
     150        self.registerHotKey(lambda: self.incrementRatingBy(-20), 109, shiftKey) # shift-F10
     151        self.registerHotKey(lambda: self.incrementRatingBy(20), 103, shiftKey) # shift-F11
    144152        NSDistributedNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, self.displayTrackInfo, 'com.apple.iTunes.playerInfo', None)
    145153
Note: See TracChangeset for help on using the changeset viewer.