Changeset 211 for trunk


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.

Location:
trunk/StreamVision
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/StreamVision/HotKeymodule.c

    r193 r211  
    1313
    1414static PyObject
    15 *StreamVision_HotKeyAddress(PyObject *self, PyObject *args) {
     15*HotKey_HotKeyAddress(PyObject *self, PyObject *args) {
    1616  PyObject *v;
    1717  if (!PyArg_ParseTuple(args, "O", &v))
     
    2424}
    2525
    26 static PyMethodDef _StreamVisionmodule_methods[] = {
    27   {"HotKeyAddress", StreamVision_HotKeyAddress, METH_VARARGS,
     26static PyMethodDef HotKeymodule_methods[] = {
     27  {"HotKeyAddress", HotKey_HotKeyAddress, METH_VARARGS,
    2828   "HotKeyAddress(_CarbonEvt.EventHotKeyRef) -> integer\n\n"
    2929   "Return the address of the underlying EventHotKeyRef (passed as data1 in hot key NSEvents)."},
     
    3232
    3333PyMODINIT_FUNC
    34 init_StreamVision(void) {
    35   (void)Py_InitModule("_StreamVision", _StreamVisionmodule_methods);
     34initHotKey(void) {
     35  (void)Py_InitModule("HotKey", HotKeymodule_methods);
    3636}
  • 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
  • trunk/StreamVision/setup.py

    r188 r211  
    1717setup(
    1818    app=["StreamVision.py"],
    19     ext_modules=[Extension('_StreamVision',
    20                            sources=['_StreamVisionmodule.c'],
     19    ext_modules=[Extension('HotKey',
     20                           sources=['HotKeymodule.c'],
    2121                           extra_link_args=['-framework', 'Carbon'])],
    2222    data_files=["English.lproj"],
Note: See TracChangeset for help on using the changeset viewer.