Exemplo n.º 1
0
 def awakeFromNib(self):
     NSDebugLog(u'awakeFromNib')
     # Set up variables
     self.fullscreen      = False
     self.lastKeyPress    = 0
     self.pickerActive    = False
     self.pickerSelection = None
     self.pickerMenuLevel = PICKER_MAINMENU
     # Set up EyeTunes
     self.eyeTunes      = EyeTunes.sharedInstance()
     self.playlistCache = ETPlaylistCache.sharedInstance()
     NSDebugLog('EyeTunes reports iTunes version: ' + 
                str(self.eyeTunes.versionString()))
     # If we could not get an iTunes version string, don't show the iTunes
     # menu as there will be nothing in it...
     if self.eyeTunes.versionString() == None:
         try:
             PICKER_MENU_MAINMENU.remove(PICKER_MENUITEM_ITUNES)
         except ValueError:
             pass # It is already not there, which is fine
     # Set up the quartz composer view
     import Quartz
     fullscreenFrame = self.theWindow.frame()
     self.theQCView = Quartz.QCView.alloc().initWithFrame_(fullscreenFrame)
     self.theWindow.contentView().addSubview_(self.theQCView)
     quartzComposition = NSBundle.mainBundle().pathForResource_ofType_(
             'Clouds', 'qtz')
     self.theQCView.loadCompositionFromFile_(quartzComposition)
     self.showFullscreenView()
     # Set up the picker window
     self.pickerDataSource = PickerDataSource.alloc().init()
     self.thePickerTable.setDataSource_(self.pickerDataSource)
     # Set up the app launcher watcher
     center = NSWorkspace.sharedWorkspace().notificationCenter()
     center = NSDistributedNotificationCenter.\
           notificationCenterForType_(NSLocalNotificationCenterType)
     center.addObserver_selector_name_object_(
             self,
             self.appLaunched_,
             #NSWorkspaceDidLaunchApplicationNotification,
             None,
             None)
     # Set up the idle timer
     self.lastIdleTime = Idling.getIdleTime()
     self.idleTimer = NSTimer.\
       timerWithTimeInterval_target_selector_userInfo_repeats_(
               0.5, self, self.idleTick_, None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(
             self.idleTimer, Foundation.NSDefaultRunLoopMode)
     NSRunLoop.currentRunLoop().addTimer_forMode_(
             self.idleTimer, AppKit.NSModalPanelRunLoopMode)
Exemplo n.º 2
0
 def idleTick_(self, timer):
     idleTime = Idling.getIdleTime()
     now      = time.time()
     #NSDebugLog('idleTick_ - %d (%d)' % (idleTime, self.lastIdleTime))
     if idleTime > IDLE_TIMEOUT and not self.fullscreen:
         NSDebugLog(u'should now show the quartz composer view')
         self.showFullscreenView()
     if self.lastIdleTime > idleTime and self.fullscreen:
         if (now - self.lastKeyPress) < 1.0:
             # We had a recent keystroke from the WiiMote, so pretend that
             # we are still idle, and don't hide the view
             self.lastIdleTime = idleTime
             return
         # This might be better done by seeing if the fullscreen
         # window is getting events? or possibly both to make the detection
         # of events in the case where the window receives them smoother
         NSDebugLog(u'should now hide the quartz composer view')
         self.hideFullscreenView()
         self.deactivatePickerWindow()
     self.lastIdleTime = idleTime
Exemplo n.º 3
0
 def buttonChanged_isPressed_(self, theType, isPressed):
     NSDebugLog(u'buttonChanged_isPressed_(%d, %d)' % (theType, isPressed))
     self.buttonStatus[theType] = isPressed
     if self.buttonStatus[WiiButtonType.WiiRemoteOneButton] and \
        self.buttonStatus[WiiButtonType.WiiRemoteTwoButton]:
         NSDebugLog(u'closing wii connetion')
         self.closeWiiMoteConnection()
         return
     elif theType == WiiButtonType.WiiRemoteOneButton and \
             isPressed == NO and not self.pickerActive:
         NSDebugLog(u'activating picker window')
         if not self.fullscreen:
             self.showFullscreenView()
         self.activatePickerWindow()
     elif self.pickerActive and isPressed == NO and \
             (theType == WiiButtonType.WiiRemoteAButton or \
             theType == WiiButtonType.WiiRemoteOneButton):
         actMenu = self.pickerDataSource.activeMenu
         idx  = self.pickerSelection
         item = self.pickerSelectedItem
         NSDebugLog(u'Menu selected: idx: %d; item: %s' % (idx, item))
         if actMenu == PICKER_MAINMENU:
             NSDebugLog(u'chaning away from main menu')
             if item == PICKER_MENUITEM_ITUNES:
                 self.pickerDataSource.setActiveMenu_(PICKER_ITUNESMENU)
                 self.thePickerTable.reloadData()
                 self.thePickerTable.selectRowIndexes_byExtendingSelection_(
                         NSIndexSet.indexSetWithIndex_(0), False)
             elif item == PICKER_MENUITEM_QUARTZ:
                 self.pickerDataSource.setActiveMenu_(PICKER_QUARTZMENU)
                 self.thePickerTable.reloadData()
                 self.thePickerTable.selectRowIndexes_byExtendingSelection_(
                         NSIndexSet.indexSetWithIndex_(0), False)
             elif item == PICKER_MENUITEM_HIDE:
                 if self.fullscreen:
                     self.hideFullscreenView()
                 self.deactivatePickerWindow()
             elif item == PICKER_MENUITEM_SLEEP:
                 NSDebugLog(u'closing wii connetion and sleeping system')
                 self.deactivatePickerWindow()
                 self.closeWiiMoteConnection()
                 Sleep.SleepSystem()
         elif actMenu == PICKER_QUARTZMENU:
             NSDebugLog(u'changing quartz composition')
             qc = self.pickerDataSource.quartzCompositions[idx]
             self.theQCView.loadCompositionFromFile_(qc)
             self.deactivatePickerWindow()
     elif self.pickerActive and isPressed == NO and \
             (theType == WiiButtonType.WiiRemoteBButton or \
             theType == WiiButtonType.WiiRemoteTwoButton):
         actMenu = self.pickerDataSource.activeMenu
         if actMenu == PICKER_MAINMENU:
             self.deactivatePickerWindow()
         if actMenu == PICKER_QUARTZMENU or actMenu == PICKER_ITUNESMENU:
             self.pickerDataSource.setActiveMenu_(PICKER_MAINMENU)
             self.thePickerTable.reloadData()
             self.thePickerTable.selectRowIndexes_byExtendingSelection_(
                     NSIndexSet.indexSetWithIndex_(actMenu), False)
     elif self.pickerActive and isPressed == YES and \
             (theType == WiiButtonType.WiiRemoteBButton or \
              theType == WiiButtonType.WiiRemoteTwoButton or \
              theType == WiiButtonType.WiiRemoteAButton):
             pass
     else:
         try:
             keyCombo = self.keymap[theType]
             self.lastKeyPress = time.time()
             if type(keyCombo) is tuple:
                 self.sendKeyboardEvent(
                         keyCombo[0], isPressed, *keyCombo[1:])
             else:
                 idleTime = Idling.getIdleTime()
                 self.lastKeyPress = time.time()
                 self.sendKeyboardEvent(keyCombo, isPressed)
         except KeyError:
             pass