class PopupMenuPresentor(object): def __init__(self, Model, View, squeezecmd, interactor): self.Model = Model self.View = View self.squeezeConCtrl = squeezecmd interactor.install(self, self.View) self.player = Observable(None) self._cb_settings = [] self.callbacks = { "on_exit": {}, "on_settings": {}, } def doCbExit(self): results = {} for item in self.callbacks["on_exit"]: results[item] = item() return results def doCbSettings(self): results = {} for item in self.callbacks["on_settings"]: results[item] = item() return results def cbAddOnExit(self, func): self.callbacks['on_exit'][func] = 1 def cbAddOnSettings(self, func): self.callbacks['on_settings'][func] = 1 def GetSqueezeServerPlayer(self): return self.player.get() def onScPause(self): player = self.GetSqueezeServerPlayer() #print "player",player if player != None: self.squeezeConCtrl.Pause(player) else: self.on_settings() def onScPlay(self): player = self.GetSqueezeServerPlayer() if player != None: self.squeezeConCtrl.Play(player) else: self.on_settings() def onScNext(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_Index(player,1) self.squeezeConCtrl.Index(player, 1) else: self.on_settings() def onScPrevious(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_Index(player,-1) self.squeezeConCtrl.Index(player, -1) else: self.on_settings() def onScRandom(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_randomplay(player) self.squeezeConCtrl.PlayRandomSong(player) else: self.on_settings() def on_settings(self): self.doCbSettings() def ChangePlayer(self, player): oldPlayer = self.player.get() if oldPlayer != player: self.player.set(player) def on_exit(self): self.doCbExit()
class PopupMenuPresentor(object): def __init__(self, Model, View,squeezecmd, interactor): self.Model = Model self.View = View self.squeezeConCtrl = squeezecmd interactor.install(self,self.View) self.player = Observable(None) self._cb_settings = [] self.callbacks = { "on_exit" : {}, "on_settings" : {}, } def doCbExit(self): results = {} for item in self.callbacks["on_exit"]: results[item] = item() return results def doCbSettings(self): results = {} for item in self.callbacks["on_settings"]: results[item] = item() return results def cbAddOnExit(self,func): self.callbacks['on_exit'][func] = 1 def cbAddOnSettings(self,func): self.callbacks['on_settings'][func] = 1 def GetSqueezeServerPlayer(self): return self.player.get() def onScPause(self): player = self.GetSqueezeServerPlayer() #print "player",player if player != None: self.squeezeConCtrl.Pause(player) else: self.on_settings() def onScPlay(self): player = self.GetSqueezeServerPlayer() if player != None: self.squeezeConCtrl.Play(player) else: self.on_settings() def onScNext(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_Index(player,1) self.squeezeConCtrl.Index(player,1) else: self.on_settings() def onScPrevious(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_Index(player,-1) self.squeezeConCtrl.Index(player,-1) else: self.on_settings() def onScRandom(self): player = self.GetSqueezeServerPlayer() if player != None: #self.squeezecmd.squeezecmd_randomplay(player) self.squeezeConCtrl.PlayRandomSong(player) else: self.on_settings() def on_settings(self): self.doCbSettings() def ChangePlayer(self,player): oldPlayer = self.player.get() if oldPlayer != player: self.player.set(player) def on_exit(self): self.doCbExit()
class viewWxToolBarSrc(): def __init__(self): self.updateNeeded = True self.toolTipCache = Observable(None) self.iconNameCache = Observable(None) self.knowledge = {} self.log = logging.getLogger("viewWxToolBarSrc") def install(self, src): self.src = src self.src.connected.addCallback(self.on_connected) #self.src.Players.addCallback(self.on_connected) self.src.CbPlayersAvailableAdd(self.on_players) self.src.playersCount.addCallback(self.on_connected) def updateToolTipManyPlayers(self): newToolTip = unicode() for index in range(len(self.src.playerList)): playerName = self.src.playerList[index].name.get() if playerName == None: continue newToolTip += unicode(playerName) CurrentOperationMode = self.src.playerList[ index].operationMode.get() if CurrentOperationMode != None: newToolTip += ":%s" % (CurrentOperationMode) CurrentTrackTitle = self.src.playerList[ index].CurrentTrackTitle.get() if CurrentTrackTitle != None: newToolTip += "\nTrack:%s" % (CurrentTrackTitle) CurrentTrackArtist = self.src.playerList[ index].CurrentTrackArtist.get() if CurrentTrackArtist != None: newToolTip += "\nArtist:%s" % (CurrentTrackArtist) CurrentTrackEnds = self.src.playerList[index].CurrentTrackEnds.get( ) #print "CurrentTrackEnds=%s" % (CurrentTrackEnds) if CurrentTrackEnds != None: seconds = timedelta2str(CurrentTrackEnds - datetime.datetime.now()) newToolTip += "\nRemaining:%s" % (seconds) newToolTip += '\n' #print newToolTip #self.log.warn("ffoo%sooff" % ( newToolTip.strip()) ) self.toolTipCache.update(newToolTip) #self.log.warn("xxx%sxxx" % (self.toolTipCache.get() ) ) return self.toolTipCache.get() def updateToolTip(self): self.log.debug("updateToolTip") newToolTip = unicode() playerlistLen = len(self.src.playerList) if playerlistLen > 0: return self.updateToolTipManyPlayers() if self.src.connected: self.toolTipCache.update("Connected") return self.toolTipCache.get() def update(self): if not self.updateNeeded: pass #return else: self.updateNeeded = False self.updateToolTip() connected = self.src.connected.get() #print "connected", self.toolTipCache.get() self.knowledge['connected'] = connected if self.knowledge['connected'] == True: self.iconNameCache.update("ART_APPLICATION_STATUS_CONNECTED") def on_connected(self, value): self.updateNeeded = True if value != True: self.iconNameCache.update("ART_APPLICATION_STATUS_DISCONECTED") def on_players(self): self.log.debug("on_players") self.updateNeeded = True #self.availablePlayers foundPlayers = set() for index in range(len(self.src.playerList)): playerName = self.src.playerList[index].name.get() self.src.playerList[index].name.addCallback(self.on_player_name) self.src.playerList[index].CurrentTrackTitle.addCallback( self.on_player_track) self.src.playerList[index].CurrentTrackArtist.addCallback( self.on_player_artist) def on_player_name(self, value): self.updateNeeded = True def on_player_track(self, value): self.log.debug('on_player_track') self.updateNeeded = True def on_player_artist(self, value): self.log.debug('on_player_artist') self.updateNeeded = True def gettoolTip(self): self.update() return self.toolTipCache.get() def getIconName(self): self.update() return self.iconNameCache.get()
class viewWxToolBarSrc(): def __init__(self): self.updateNeeded = True self.toolTipCache = Observable(None) self.iconNameCache = Observable(None) self.knowledge = {} self.log = logging.getLogger("viewWxToolBarSrc") def install(self, src): self.src = src self.src.connected.addCallback(self.on_connected) #self.src.Players.addCallback(self.on_connected) self.src.CbPlayersAvailableAdd(self.on_players) self.src.playersCount.addCallback(self.on_connected) def updateToolTipManyPlayers(self): newToolTip = unicode() for index in range(len(self.src.playerList)): playerName = self.src.playerList[index].name.get() if playerName == None: continue newToolTip += unicode(playerName) CurrentOperationMode = self.src.playerList[index].operationMode.get() if CurrentOperationMode != None: newToolTip += ":%s" % (CurrentOperationMode) CurrentTrackTitle = self.src.playerList[index].CurrentTrackTitle.get() if CurrentTrackTitle != None: newToolTip += "\nTrack:%s" % (CurrentTrackTitle) CurrentTrackArtist = self.src.playerList[index].CurrentTrackArtist.get() if CurrentTrackArtist != None: newToolTip += "\nArtist:%s" % (CurrentTrackArtist) CurrentTrackEnds = self.src.playerList[index].CurrentTrackEnds.get() #print "CurrentTrackEnds=%s" % (CurrentTrackEnds) if CurrentTrackEnds != None: seconds = timedelta2str(CurrentTrackEnds - datetime.datetime.now()) newToolTip += "\nRemaining:%s" % (seconds) newToolTip += '\n' #print newToolTip #self.log.warn("ffoo%sooff" % ( newToolTip.strip()) ) self.toolTipCache.update(newToolTip) #self.log.warn("xxx%sxxx" % (self.toolTipCache.get() ) ) return self.toolTipCache.get() def updateToolTip(self): self.log.debug("updateToolTip") newToolTip = unicode() playerlistLen = len(self.src.playerList) if playerlistLen > 0: return self.updateToolTipManyPlayers() if self.src.connected: self.toolTipCache.update("Connected") return self.toolTipCache.get() def update(self): if not self.updateNeeded: pass #return else: self.updateNeeded = False self.updateToolTip() connected = self.src.connected.get() #print "connected", self.toolTipCache.get() self.knowledge['connected'] = connected if self.knowledge['connected'] == True: self.iconNameCache.update("ART_APPLICATION_STATUS_CONNECTED") def on_connected(self, value): self.updateNeeded = True if value != True: self.iconNameCache.update("ART_APPLICATION_STATUS_DISCONECTED") def on_players(self): self.log.debug("on_players") self.updateNeeded = True #self.availablePlayers foundPlayers = set() for index in range(len(self.src.playerList)): playerName = self.src.playerList[index].name.get() self.src.playerList[index].name.addCallback(self.on_player_name) self.src.playerList[index].CurrentTrackTitle.addCallback(self.on_player_track) self.src.playerList[index].CurrentTrackArtist.addCallback(self.on_player_artist) def on_player_name(self, value): self.updateNeeded = True def on_player_track(self, value): self.log.debug('on_player_track') self.updateNeeded = True def on_player_artist(self, value): self.log.debug( 'on_player_artist') self.updateNeeded = True def gettoolTip(self): self.update() return self.toolTipCache.get() def getIconName(self): self.update() return self.iconNameCache.get()