def __init__(self, tasks):
     Thread.__init__(self)
     self.tasks = tasks
     self.callbacks = { 'task_done' : {}}
     self.daemon = True
     self.start()
     self.connectionString = None
     self.SocketErrNo = Observable(0)
     self.SocketErrMsg = Observable("")
     self.log = logging.getLogger("JrpcServerthreadPool.SqueezeConnectionWorker")
     self.conn = None
    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": {},
        }
class SqueezeConnectionWorker(Thread):
    """Thread executing tasks from a given tasks queue"""
    def __init__(self, tasks):
        Thread.__init__(self)
        self.tasks = tasks
        self.callbacks = { 'task_done' : {}}
        self.daemon = True
        self.start()
        self.connectionString = None
        self.SocketErrNo = Observable(0)
        self.SocketErrMsg = Observable("")
        self.log = logging.getLogger("JrpcServerthreadPool.SqueezeConnectionWorker")
        self.conn = None
    def cbAddTaskDone(self,funct):
        self.callbacks['task_done'][funct] = 1
            
    def taskDone(self,request):
        self.tasks.task_done()
        self.log.debug( 'taskDone')
        for func in self.callbacks['task_done']:
            func(request)
        # Now process nicely   
        return
    def processRequest(self,request):
        params = request['params']
        if self.connectionString == None:
            self.log.debug('Connection is none')
            return
        if self.conn == None:
            self.log.debug('Connection creating = "%s"' % (self.connectionString))
            self.conn = httplib.HTTPConnection(self.connectionString,timeout=10)
        try:
            #self.log.debug(type(params))
            self.conn.request("POST", "/jsonrpc.js", unicode(params))
        except socket.error, E:
            errorNumber = 99
            try:
                errorNumber = E.errno
            except TypeError:
                pass
            self.SocketErrNo.set(errorNumber)
            self.SocketErrMsg.set(unicode(E.strerror))
            self.conn = None
            self.log.error("Socket error.=%s" % (self.connectionString))
            return
        except httplib.CannotSendRequest, E:
            self.conn = None
            self.log.error("Cannot Send Request, resetting connection.=%s" % (params))
            return
 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" : {},
         
     }
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()
Beispiel #6
0
 def __init__(self):
     self.updateNeeded = True
     self.toolTipCache = Observable(None)
     self.iconNameCache = Observable(None)
     self.knowledge = {}
     self.log = logging.getLogger("viewWxToolBarSrc")
Beispiel #7
0
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 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()
Beispiel #9
0
 def __init__(self):
     self.updateNeeded = True
     self.toolTipCache = Observable(None)
     self.iconNameCache = Observable(None)
     self.knowledge = {}
     self.log = logging.getLogger("viewWxToolBarSrc")
Beispiel #10
0
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()