Exemple #1
0
    def SourceSelect(self,oCodesetCode,oSetting,uRetVar,bNoLogOut):

        #detect the new source string
        uCheck=''
        oAction= self.oAction
        if oAction.aActionPars['commandname']=="source tv/sat":
            uCheck="satellite"
        if oAction.aActionPars['commandname']=="source tv/cbl":
            uCheck="tv"
        elif oAction.aActionPars['commandname']=="source hdmi 1":
            uCheck="hdmi1"
        elif oAction.aActionPars['commandname']=="source hdmi 2":
            uCheck="hdmi2"
        elif oAction.aActionPars['commandname']=="source hdmi 3":
            uCheck="hdmi3"
        elif oAction.aActionPars['commandname']=="source hdmi 4":
            uCheck="hdmiside"
        elif oAction.aActionPars['commandname']=="source component":
            uCheck="ypbpr"
        elif oAction.aActionPars['commandname']=="source aux 1":
            uCheck="vga"
        elif oAction.aActionPars['commandname']=="source aux 2":
            uCheck="ext1"
        elif oAction.aActionPars['commandname']=="source aux 3":
            uCheck="ext2"

        #we first siwtch to ZV , as otherwise the TV might return complete bullshit of its curent source
        oSetting.uCurrentSource=self.SendCommandHelper(u'source tv',oSetting,bNoLogOut)
        fSleep(3)

        oSetting.uCurrentSource=self.SendCommandHelper(u'getsource',oSetting,bNoLogOut)

        # check the position in the Sources list for the current source
        iPosNew=-1
        iPosCurrent=-1
        for i in range(len(oSetting.aSourcesPos)):
            if oSetting.aSourcesPos[i]==oSetting.uCurrentSource:
                iPosCurrent=i
                break
            
        # check the position in the Sources list for the new source
        for i in range(len(oSetting.aSourcesPos)):
            if oSetting.aSourcesPos[i]==uCheck:
                iPosNew=i
                break

        # And move the osd!
        if iPosNew!=-1 and iPosCurrent!=-1:
            iSteps = abs(iPosNew-iPosCurrent)
            if iSteps != 0:
                if iPosNew > iPosCurrent:
                    uAction=u"right"
                else:
                    uAction=u"left"

                self.OSDSourceSelect(oCodesetCode,oSetting,iSteps,uAction,uRetVar,bNoLogOut)

        else:
            self.ShowDebug ('Can''t detect current source position or new source position')
Exemple #2
0
 def on_onlinestatechecked(self, *largs):
     """ called, wehn the tsated has been checked """
     Logger.debug("Checking for network connectivity online state checked")
     if not self.bIsWaiting:
         return
     if not self.bIsOnline:
         Clock.schedule_once(self.StartNextThread, 0)
         fSleep(0.6)
         return
     self.StopWait()
 def on_permissionschecked(self, *largs):
     """ called, wehn the tsated has been checked """
     # Logger.debug("Checking permissions")
     if not self.bIsWaiting:
         return
     if not self.bHasPermissions:
         Clock.schedule_once(self.StartNextThread, 0)
         fSleep(fSeconds=0.6)
         return
     self.StopWait()
Exemple #4
0
 def Disconnect(self):
     fSleep(0.05,True)
     self.bStopThreadEvent=True
     if not cBaseInterFaceSettings.Disconnect(self):
         self.ShowDebug(u'Interface Disconnect #1: Connection is already closed, no further actions')
         return False
     self.ShowDebug(u'Interface Disconnect #2:Closing Connection')
     
     #force close of socket, even if in thrad it will be close again
     try:
         self.oSocket.close()
     except Exception as e:
         pass
     self.bOnError = False
Exemple #5
0
    def StopApp(self):
        """
        Stops the ORAC App
        """
        Logger.debug("Quit App on request")
        # self.DeInit()
        Globals.oSound.PlaySound('shutdown')
        fSleep(0.5)

        if Globals.oPathUserDownload:
            Globals.oFnLog.Copy(oNewFile=cFileName(Globals.oPathUserDownload) +
                                'orca.log')
        self.stop()
        sys.exit(0)
Exemple #6
0
        def IsConnected(self):
            if self.oCodesetCodePing==None:
                return True

            uMsg=self.oCodesetCodePing.uCmd
            try:
                self.bPingAnswer=False
                self.oSocket.sendall(uMsg) 
                for i in range(200):
                    if self.bPingAnswer:
                        break
                    fSleep(0.05,True)
                return self.bPingAnswer
            except Exception as e:
                pass
            return False
Exemple #7
0
        def Disconnect(self):
            fSleep(0.05, True)
            self.bStopThreadEvent = True
            if not cBaseInterFaceSettings.Disconnect(self):
                self.ShowDebug(
                    u'Interface Disconnect #1: Connection is already closed, no further actions'
                )
                return False
            self.ShowDebug(u'Interface Disconnect #2:Closing Connection')

            #force close of socket, even if in thrad it will be close again
            try:
                self.oSocket.close()
            except Exception as e:
                pass
            self.bOnError = False
Exemple #8
0
def GetLocalIPV4_FallBack() -> str:
    """ gets the local IP by opening a socket to itself """
    def udp_listening_server() -> str:
        """ the server component """
        bMsg: bytes
        tAddress: Tuple
        try:
            oInSocket: socket.socket = socket.socket(socket.AF_INET,
                                                     socket.SOCK_DGRAM)
            oInSocket.bind(("0.0.0.0", 18888))
            oInSocket.setblocking(False)
            while True:
                tResult: Tuple = select.select([oInSocket], [], [])
                bMsg, tAddress = tResult[0][0].recvfrom(1024)
                if bMsg == b'ORCAIPREQUEST':
                    aIP.append(tAddress[0])
                    break
            oInSocket.close()
        except Exception as exc:
            LogError(uMsg=u'GetLocalIp:udp_listening_server:', oException=exc)
            return u'127.0.0.0'

    try:
        Logger.debug("Using Fallback to detect V4 IP Address")
        aIP: List = []
        oThread: threading.Thread = threading.Thread(
            target=udp_listening_server)
        oThread.aIP = aIP
        oThread.start()
        oOutSocket: socket.socket = socket.socket(socket.AF_INET,
                                                  socket.SOCK_DGRAM)
        oOutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        i: int = 0
        while len(aIP) == 0:
            oOutSocket.sendto(b'ORCAIPREQUEST', ("255.255.255.255", 18888))
            fSleep(fSeconds=0.1)
            i += 1
            if i == 10:
                break
        oOutSocket.close()
        if len(aIP) > 0:
            return aIP[0]
        else:
            return u'127.0.0.0'
    except Exception as e:
        LogError(uMsg='GetLocalIpV4:', oException=e)
        return u'127.0.0.0'
Exemple #9
0
def GetLocalIPV4_FallBack():
    """ gets the local IP by opening a socket to itself """
    def udp_listening_server():
        """ the server component """
        try:
            oInSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            #s.bind(('<broadcast>', 8888))
            oInSocket.bind(("0.0.0.0", 18888))
            oInSocket.setblocking(0)
            while True:
                result = select.select([oInSocket], [], [])
                msg, address = result[0][0].recvfrom(1024)
                if msg == b'ORCAIPREQUEST':
                    IP.append(address[0])
                    break
            oInSocket.close()
        except Exception as e:
            LogError(u'GetLocalIp:udp_listening_server:', e)
            return

    try:
        IP = []
        thread = threading.Thread(target=udp_listening_server)
        thread.IP = IP
        thread.start()
        oOutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        oOutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        i = 0
        while len(IP) == 0:
            oOutSocket.sendto(b'ORCAIPREQUEST', ("255.255.255.255", 18888))
            fSleep(0.1)
            i += 1
            if i == 10:
                break
        oOutSocket.close()
        if len(IP) > 0:
            return IP[0]
        else:
            return u'127.0.0.0'
    except Exception as e:
        LogError('GetLocalIpV4:', e)
        return u'127.0.0.0'
Exemple #10
0
        def IsConnected(self):
            return False
            if self.oCodesetCodePing==None:
                return True
                

            uMsg=self.oCodesetCodePing.uCmd
            uMsg=uMsg[:-1]+",\"id\":\"" +self.uID+"\"}"
            self.bPingAnswer=False
            try:
                self.oSocket.sendall(uMsg) 
                for i in range(200):
                    if self.bPingAnswer:
                        break
                    fSleep(0.05,True)
                return self.bPingAnswer

            except Exception as e:
                pass
            return False
Exemple #11
0
    def WriteWikiPages(self):
        """ Write all wiki entries to wikipedia """

        oSite = None

        try:
            oSite = mwclient.Site(self.uHost,
                                  path=self.uWikiPath,
                                  force_login=True)
            oSite.login(self.uUser, self.uPassword)

            try:
                for uImageKey in self.dImageFileList:
                    oFnImage = self.dImageFileList[uImageKey]
                    Logger.debug("Uploading Image:" + oFnImage.string)
                    jRec = oSite.upload(open(oFnImage.string, 'rb'),
                                        filename=oFnImage.basename,
                                        description='')
                    # print (jRec["warnings"].keys()[0]," ",jRec["warnings"][jRec["warnings"].keys()[0]])
                    dWarnings = jRec.get("warnings")
                    if dWarnings is not None:
                        if "was-deleted" in dWarnings.keys()[0]:
                            Logger.error(
                                "You need Undelete File in Mediawiki:" +
                                oFnImage.basename)
                        if "exists" in dWarnings.keys()[0]:
                            jRec = oSite.upload(open(oFnImage.string, 'rb'),
                                                filename=oFnImage.basename,
                                                description='',
                                                ignore=True)

            except Exception as e:
                Logger.error("Error writing image:" + str(e))

            for oPage in self.aDocs:
                if oPage.uPage:
                    oPage.WriteWiki(oSite)
                    fSleep(1.0)

        except Exception as e:
            Logger.error("Error writing page:" + str(e))
Exemple #12
0
def StartWait(iWaitTime:int=-1) -> None:
    """
    wait function for interfaces / and to stop the queue if necessary
    iWaitTime 0: Stops Wait and let the status pass thought
    iWaittime -1: Sets the App on Pause
    iWaittime > 0: Holds the queue for the given time
    """

    if iWaitTime == -1:
        ORCA.utils.wait.Globals.bOnPause = True
        Logger.debug("System start wait")
        return

    ORCA.utils.wait.Globals.oWaitLock.acquire()  # will block if lock is already held

    if iWaitTime == 0:
        ORCA.utils.wait.Globals.oWaitEndTime = ORCA.utils.wait.Globals.oWaitZeroTime
        fSleep(fSeconds=0.01)
    else:
        ORCA.utils.wait.Globals.oWaitEndTime = datetime.now() + timedelta(milliseconds=iWaitTime)

    ORCA.utils.wait.Globals.oWaitLock.release()
Exemple #13
0
def IsWaiting():
    """
    returns if we are in a interface wait state or app wait state
    """

    if ORCA.utils.wait.Globals.bOnPause:
        fSleep(0.001)
        return True

    ORCA.utils.wait.Globals.oWaitLock.acquire()

    if ORCA.utils.wait.Globals.fWaitEndTime == 0:
        ORCA.utils.wait.Globals.oWaitLock.release()
        return False
    if datetime.now() > ORCA.utils.wait.Globals.fWaitEndTime:
        Logger.warning("Interface waiting timed out!!")
        ORCA.utils.wait.Globals.fWaitEndTime = 0
        ORCA.utils.wait.Globals.oWaitLock.release()
        return False
    fSleep(0.01)
    ORCA.utils.wait.Globals.oWaitLock.release()
    return True
Exemple #14
0
    def OSDSourceSelect(self,oCodesetCode,oSetting,iSteps,uAction,uRetVar,bNoLogOut):

        self.SendCommandHelper(u'source',oSetting,bNoLogOut)
        fSleep(4)
        for i in range(iSteps):
             self.SendCommandHelper(uAction,oSetting,bNoLogOut)
             fSleep(1)
        fSleep(1)
        self.SendCommandHelper(u'ok',oSetting,bNoLogOut)
Exemple #15
0
    def NLSPage(self,uCmd,oOrgAction,oCodesetCode):


        if uCmd=='NLSpgup':
            iSteps=self.iCursorPos-(self.iCntNLS+1)-1
            iSteps=(self.iCursorPos*-1)-1
        else:
            iSteps=(self.iCntNLS+1)-self.iCursorPos-1
            if iSteps==0:
                iSteps=1
            

        Logger.error('Cmd:'+uCmd+" count:"+str(self.iCntNLS)+" Pos:"+str(self.iCursorPos)+ " Steps:"+str(iSteps))

        if iSteps>0:
            oOrgAction.aActionPars['commandname']=u'down'
            for i in range(iSteps):
                fSleep(0.3,True)
                self.DoAction(oOrgAction)
        else:
            oOrgAction.aActionPars['commandname']=u'up'
            for i in range(abs(iSteps)):
                fSleep(0.3,True)
                self.DoAction(oOrgAction)
Exemple #16
0
        def Receive(self):
            #Main Listening Thread to receive json messages

            #Loop until closed by external flag
            try:
                while not self.bStopThreadEvent:
                    if self.oSocket is not None:
                        ready = select.select([self.oSocket], [], [], 1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            self.bHandled = False
                            sResponses = self.oSocket.recv(self.iBufferSize)
                            uResponses = ToUnicode(sResponses)
                            # there could be more than one response, so we need to split them
                            # unfortunately, there is no end char in a json respone
                            aResponses = uResponses.split('}{')
                            if not len(aResponses) == 1:
                                i = 0
                                while i < len(aResponses):
                                    if i == 0:
                                        aResponses[i] += '}'
                                    else:
                                        aResponses[i] = u'{' + aResponses[i]
                                    i += 1
                            uID = 0
                            for uResponse in aResponses:
                                if not uResponse == u'':
                                    if '"result":"pong"' in uResponse:
                                        pass
                                    else:

                                        # Get the Command and the payload
                                        # If the returned Command is a response to the send message
                                        uCommand, uID = self.oInterFace.ParseResult_JsonHeader(
                                            uResponse)
                                        if uID == self.uID:

                                            uCmd, uRetVal = self.oInterFace.ParseResult(
                                                self.oAction, uResponse, self)

                                            self.ShowDebug(
                                                u'Parsed Respones:' + uRetVal)

                                            if not self.uRetVar == u'' and not uRetVal == u'':
                                                SetVar(uVarName=self.uRetVar,
                                                       oVarValue=uRetVal)
                                            # We do not need to wait for an response anymore
                                            StartWait(0)
                                            self.bHandled = True

                                        if not self.bHandled:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            oActionTrigger = self.GetTrigger(
                                                uCommand)
                                            if oActionTrigger is not None:
                                                self.CallTrigger(
                                                    oActionTrigger, uResponse)
                                            else:
                                                self.ShowDebug(
                                                    u'Discard message:' +
                                                    uCommand + ':' + uResponse)
                            #print "LEAVE PARSE"
                            fSleep(0.01)

            except Exception as e:
                if self.bIsConnected:
                    self.ShowError(u'Error Receiving Response:', e)
                self.bIsConnected = False
            try:
                if self.oSocket is not None:
                    self.ShowDebug(u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(u'Error closing socket in Thread', e)
Exemple #17
0
    def SendCommand(self,oCodesetCode,oSetting,uRetVar,bNoLogOut=False):

        oSetting.oCodesetCode=oCodesetCode
        
        if uRetVar!="":
            oCodesetCode.uGlobalDestVar=uRetVar

        oSetting.SetContextVar('Host',oCodesetCode.uHost)
        oSetting.SetContextVar('Port',oCodesetCode.uPort)

        iTryCount=0
        iRet=1
        #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount<2:
            iTryCount+=1
            oSetting.Connect()
            # we need to verify if we are really connected, as the connection might have died
            # and .sendall will not return on error in this case
            bIsConnected=oSetting.IsConnected()
            if not bIsConnected:
                self.ShowDebug(u'Connection has died, need to reconnect...')
                oSetting.bOnError=True
                oSetting.Disconnect()
                oSetting.Connect()

            if oSetting.bIsConnected:
                uMsg=oCodesetCode.uCmd
                try:

                    uMsg=ReplaceVars(uMsg,self.uInterFaceName+'/'+oSetting.uConfigName)
                    uMsg=ReplaceVars(uMsg)
                    oCodesetCode.uGetVar         = ReplaceVars(oCodesetCode.uGetVar,self.uInterFaceName+'/'+oSetting.uConfigName)
                    oCodesetCode.uGetVar         = ReplaceVars(oCodesetCode.uGetVar)

                    uMsg=uMsg[:-1]+",\"id\":\"" +oSetting.uID+"\"}"
                    oSetting.uMsg=uMsg
                    oSetting.uRetVar=uRetVar
                    oSetting.oCodesetCode=oCodesetCode
                    oSetting.uRetVar=uRetVar
                    self.ShowInfo (u'Sending Command: '+uMsg + ' to '+oCodesetCode.uHost+':'+oCodesetCode.uPort,oSetting.uConfigName)
                    #All response comes to receiver thread, so we should hold the queue until vars are set
                    if oSetting.oCodesetCode.bWaitForResponse==True:
                        oORCA.StartWait(self.iWaitMs)
                    oSetting.oSocket.sendall(uMsg) 
                    fSleep(0.01)
                    iRet=0
                    break
                except Exception as e:
                    self.ShowError(u'Can\'t send message',oSetting.uConfigName,e)
                    iRet=1
                    oSetting.Disconnect()
                    oSetting.bOnError=True
                    if not uRetVar==u'':
                        SetVar(uRetVar,u"Error")
            else:
                if not uRetVar==u'':
                    SetVar(uRetVar,u"Error")
                
        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose==0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose!=-1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(oSetting.FktDisconnect, oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
Exemple #18
0
        def Receive(self):
            #Main Listening Thread to receive json messages

            #Loop until closed by external flag
            try:
                while self.bStopThreadEvent==False:
                    if not self.oSocket==None:
                        ready = select.select([self.oSocket], [], [],1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            self.bHandled=False
                            sResponses = self.oSocket.recv(self.iBufferSize)
                            uResponses = ToUnicode(sResponses)
                            # there could be more than one response, so we need to split them
                            # unfortunately, there is no end char in a json respone
                            aResponses=uResponses.split('}{')
                            if not len(aResponses)==1:
                                i=0
                                while i<len(aResponses):
                                    if i==0:
                                        aResponses[i]+='}'
                                    else:
                                        aResponses[i]=u'{'+aResponses[i]
                                    i+=1
                            uID=0
                            for uResponse in aResponses:
                                if not uResponse==u'':
                                    if '"result":"pong"' in uResponse:
                                        self.bPingAnswer=True
                                    else:
                                        
                                        # Get the Command and the payload
                                        # If the returned Command is a response to the send message
                                        uCommand,uID=self.oInterFace.ParseResult_JsonHeader(uResponse)
                                        if uID==self.uID:
                                        
                                            uCmd,uRetVal=self.oInterFace.ParseResult(self.oCodesetCode,uResponse,self)

                                            self.ShowDebug(u'Parsed Respones:'+uRetVal)
                                        
                                            if not self.uRetVar==u'' and not uRetVal==u'':
                                                SetVar(self.uRetVar,uRetVal)
                                            # We do not need to wait for an response anymore
                                            oORCA.StartWait(0)
                                            self.bHandled=True


                                        if self.bHandled==False:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            oActionTrigger=self.GetTrigger(uCommand)
                                            if not oActionTrigger==None:
                                                self.CallTrigger(oActionTrigger,uResponse)
                                            else:
                                                self.ShowDebug(u'Discard message:'+uCommand +':'+uResponse)
                            #print "LEAVE PARSE"
                            fSleep(0.01)
                
            except Exception as e:
                if self.bIsConnected:
                    self.ShowError(u'Error Receiving Response:',e)
                self.bIsConnected=False
            try:
                if not self.oSocket==None:
                    self.ShowDebug(u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(u'Error closing socket in Thread',e)
Exemple #19
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        iTryCount = 0
        iRet = 1
        #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            # we need to verify if we are really connected, as the connection might have died
            # and .sendall will not return on error in this case
            #bIsConnected=oSetting.IsConnected()

            if oSetting.bIsConnected:
                uMsg = oAction.uCmd
                try:

                    uMsg = ReplaceVars(
                        uMsg, self.uInterFaceName + '/' + oSetting.uConfigName)
                    uMsg = ReplaceVars(uMsg)
                    oAction.uGetVar = ReplaceVars(
                        oAction.uGetVar,
                        self.uInterFaceName + '/' + oSetting.uConfigName)
                    oAction.uGetVar = ReplaceVars(oAction.uGetVar)

                    oSetting.uMsg = uMsg
                    oSetting.uRetVar = uRetVar
                    oSetting.uRetVar = uRetVar
                    self.ShowInfo(
                        u'Sending Command: ' + uMsg + ' to ' +
                        oSetting.aInterFaceIniSettings.uHost + ':' +
                        oSetting.aInterFaceIniSettings.uPort,
                        oSetting.uConfigName)
                    #All response comes to receiver thread, so we should hold the queue until vars are set
                    if oSetting.oAction.bWaitForResponse:
                        StartWait(self.iWaitMs)
                    oSetting.oWebSocket.send(uMsg)
                    fSleep(0.01)
                    iRet = 0
                    break
                except Exception as e:
                    self.ShowError(u'Can\'t send message',
                                   oSetting.uConfigName, e)
                    iRet = 1
                    oSetting.Disconnect()
                    oSetting.bOnError = True
                    if not uRetVar == u'':
                        SetVar(uVarName=uRetVar, oVarValue=u"Error")
            else:
                if not uRetVar == u'':
                    SetVar(uVarName=uRetVar, oVarValue=u"Error")

        if oSetting.bIsConnected:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet
Exemple #20
0
    def ExecuteActionShowPage(self, oAction):
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-ShowPage
        WikiDoc:TOCTitle:showpage
        The showpage action shows a specific page. You need to provide the name of the page as defined in your page definition. Do not mix file name and page name. If page name is 'settings' , the settings dialog will be  shown. For android devices, the settings dialog will be shown, if you press the settings button of your Android device.
        You can also set, how a page is displayed. For this, you can pass the same parameter as described in 'setpageeffect'. This is optional, if you don't pass this the last global effects are used. Passing effect types here will not change global settings.
        If a page get shown, the pagestop actions for the leaving page and the pagestart actions for the new page are executed. This will not happen if the new page/leaving page is a popup. If you want to get the pagestop actions/pagestart actions executed, if you show a popup, you have to set the enforce parameter. Pagestop actions and pagestart actions of the popup page are always executed
        You also could use a short form, where the pagename is added directly to the string. eg. string="showpage $(LASTPAGE)"

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |showpage
        |-
        |pagename
        |Page name, name of the page to display
        |-
        |effect
        |Page effect (optional)
        |-
        |direction
        |Page effect direction (optional)
        |-
        |enforce
        |Force pagestop actions & pagestop actions on popup call.
         Valid options are
         * ENFORCESTARTACTIONS
         * ENFORCESTOPACTIONS
        |}</div>
        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="gotolastpage" string="showpage" pagename="$var(LASTPAGE)" />
        </syntaxhighlight></div>
        WikiDoc:End
        """

        self.oEvenDispatcher.LogAction(u'ShowPage', oAction)
        uEffect = ReplaceVars(oAction.dActionPars.get("effect", ""))
        uDirection = ReplaceVars(oAction.dActionPars.get("direction", ""))
        uPageName = ReplaceVars(oAction.dActionPars.get("pagename", ""))
        uCurrentEffect = ""
        if uEffect:
            uCurrentEffect = Globals.oTheScreen.uCurrentEffect
        if uDirection:
            uCurrentDirection = Globals.oTheScreen.uCurrentEffectDirection
        if uEffect or uDirection:
            self.ExecuteActionSetPageEffect(oAction)

        iRet = Globals.oTheScreen.ShowPage(uPageName)
        if uEffect:
            Globals.oTheScreen.SetPageEffect(uCurrentEffect)
        if uDirection:
            Globals.oTheScreen.SetPageEffectDirection(
                uDirection=uCurrentDirection)
        self.oEvenDispatcher.bDoNext = False
        fSleep(0.1)

        return iRet
Exemple #21
0
    def WorkOnQueue(self, bForce: bool, *largs) -> Union[eReturnCode, None]:
        """ runs the queue, until finished """

        oAction: cAction
        self.bForceState = bForce
        eRet: eReturnCode = eReturnCode.Nothing
        eRetReal: eReturnCode

        # We need to ensure, that only actions in the last queue will be executed
        # All other Queues are still scheduled, so just skip them
        if not self == aActiveQueueStack[-1]:
            return None
        if IsWaiting() and not self.bForceState:
            Clock.schedule_once(partial(self.WorkOnQueue, bForce))
            return None

        if Globals.oTheScreen.bIntransition and not self.bForceState:
            Clock.schedule_once(partial(self.WorkOnQueue, bForce))
            return None

        fNextFrame: float = 0.0
        #fNextFrame=0.0001
        fStart = time.time()

        while True:
            if self.iActionQueuePos < len(self.aActionQueue):
                oAction = self.aActionQueue[self.iActionQueuePos]
                Globals.oEvents.bDoNext = True
                eRetReal = self.WorkOnQueueDoAction(oAction=oAction)
                if eRetReal != eReturnCode.Nothing:
                    eRet = eRetReal
                self.iActionQueuePos += 1
                if not self == aActiveQueueStack[-1]:
                    #Logger.debug ("Not own queue")
                    return eRet
                if oAction.iActionId == Globals.oActions.oActionType.Wait:
                    '''
                    fWait=ToFloat(ReplaceVars(oAction.dActionPars.get('time','1')))
                    Globals.oEvents.LogAction(u'Wait',oAction)
                    if not self.bForceState:
                        fNextFrame = fWait/1000.0
                        Globals.oEvents.bDoNext = False
                    else:
                        fSleep (fWait/1000.0)
                    '''
                    fWait = ToFloat(
                        ReplaceVars(oAction.dActionPars.get('time', '1')))
                    Globals.oEvents.LogAction(uTxt=u'Wait', oAction=oAction)
                    Globals.oEvents.bDoNext = False
                    fSleep(fSeconds=fWait / 1000)  # Todo: Check division
                    Globals.oEvents.LogAction(uTxt=u'Wait2', oAction=oAction)

                #We will execute some basic Actions like Var manipulation immediately, to make it faster
                #If we wait, then prevent fast execution
                if IsWaiting():
                    Globals.oEvents.bDoNext = False

                # to ensure, that we get screen updates and detect touches, even on long queues
                if time.time() - fStart > 0.2:
                    Globals.oEvents.bDoNext = False
                    fStart = time.time()

                #If we do not force working the queue and nothing to accelerate, the next execution is not next frame (to ensure screen updates)
                if not self.bForceState and not Globals.oEvents.bDoNext:
                    if not bStop:
                        if Globals.bOnSleep:
                            fNextFrame = 0.5  # if we are on sleep , we switch to timed minimum queue activity
                        Clock.schedule_once(partial(self.WorkOnQueue, False),
                                            fNextFrame)
                    return eRet
            else:
                del self.aActionQueue[:]
                self.iActionQueuePos = 0
                if not len(aActiveQueueStack) == 1:
                    aInActiveQueueStack.append(aActiveQueueStack.pop())
                    if not self.bForceState:
                        if not bStop:
                            Clock.schedule_once(
                                partial(GetActiveQueue().WorkOnQueue, bForce),
                                fNextFrame)
                return eRet
Exemple #22
0
 def Disconnect(self):
     self.bStopThreadEvent=True
     if not cBaseInterFaceSettings.Disconnect(self):
         return False
     fSleep(0.05,True)
     self.bOnError = False
Exemple #23
0
    def WorkOnQueue(self, bForce, *largs):
        """ runs the queue, until finished """

        self.bForceState = bForce
        iRet = -2

        # We need to ensure, that only actions in the last queue will be executed
        # All other Queues are still scheduled, so just skip them
        if not self == aActiveQueueStack[-1]:
            return
        if IsWaiting() and not self.bForceState:
            Clock.schedule_once(partial(self.WorkOnQueue, bForce))
            return

        if Globals.oTheScreen.bIntransition and not self.bForceState:
            Clock.schedule_once(partial(self.WorkOnQueue, bForce))
            return

        #fNextFrame=0.0
        fNextFrame = 0.0001
        while True:
            if self.iActionQueuePos < len(self.aActionQueue):
                oAction = self.aActionQueue[self.iActionQueuePos]
                Globals.oEvents.bDoNext = True
                iRetReal = Globals.oEvents.WorkOnQueueDoAction(oAction)
                if iRetReal != -2:
                    iRet = iRetReal
                self.iActionQueuePos = self.iActionQueuePos + 1
                if not self == aActiveQueueStack[-1]:
                    #Logger.debug ("Not own queue")
                    return iRet
                if oAction.iActionId == Globals.oActions.oActionType.Wait:
                    '''
                    fWait=ToFloat(ReplaceVars(oAction.dActionPars.get('time','1')))
                    Globals.oEvents.LogAction(u'Wait',oAction)
                    if not self.bForceState:
                        fNextFrame = fWait/1000.0
                        Globals.oEvents.bDoNext = False
                    else:
                        fSleep (fWait/1000.0)
                    '''
                    fWait = ToFloat(
                        ReplaceVars(oAction.dActionPars.get('time', '1')))
                    Globals.oEvents.LogAction(u'Wait', oAction)
                    Globals.oEvents.bDoNext = False
                    fSleep(fWait / 1000)
                    Globals.oEvents.LogAction(u'Wait2', oAction)

                #We will execute some basic Actions like Var manipulation immediatly, to make it faster
                #If we wait, then prevent fast execution
                if IsWaiting():
                    Globals.oEvents.bDoNext = False

                #If we do not force working the queue and nothing to accelerate, the next execution is not next frame (to ensure screen updates)
                if not self.bForceState and not Globals.oEvents.bDoNext:
                    if not bStop:
                        if Globals.bOnSleep:
                            fNextFrame = 0.5  # if we are on sleep , we switch to timed minimum queue activity
                        Clock.schedule_once(partial(self.WorkOnQueue, False),
                                            fNextFrame)
                    return iRet
            else:
                del self.aActionQueue[:]
                self.iActionQueuePos = 0
                if not len(aActiveQueueStack) == 1:
                    aInActiveQueueStack.append(aActiveQueueStack.pop())
                    if not self.bForceState:
                        if not bStop:
                            Clock.schedule_once(
                                partial(GetActiveQueue().WorkOnQueue, bForce),
                                fNextFrame)
                return iRet
        return iRet
Exemple #24
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        iTryCount = 0
        eRet: eReturnCode = eReturnCode.Error
        #Logger.info ('Interface '+self.sInterFaceName+': Sending Command: '+sCommand + ' to '+oSetting.sHost+':'+oSetting.sPort)
        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            # we need to verify if we are really connected, as the connection might have died
            # and .sendall will not return on error in this case
            #bIsConnected=oSetting.IsConnected()

            if oSetting.bIsConnected:
                uMsg = oAction.uCmd
                try:

                    uMsg = ReplaceVars(
                        uMsg, self.uObjectName + '/' + oSetting.uConfigName)
                    uMsg = ReplaceVars(uMsg)
                    oAction.uGetVar = ReplaceVars(
                        oAction.uGetVar,
                        self.uObjectName + '/' + oSetting.uConfigName)
                    oAction.uGetVar = ReplaceVars(oAction.uGetVar)

                    oSetting.uMsg = uMsg
                    oSetting.uRetVar = uRetVar
                    oSetting.uRetVar = uRetVar
                    self.ShowInfo(uMsg=u'Sending Command: ' + uMsg + ' to ' +
                                  oSetting.aIniSettings.uHost + ':' +
                                  oSetting.aIniSettings.uPort,
                                  uParConfigName=oSetting.uConfigName)
                    #All response comes to receiver thread, so we should hold the queue until vars are set
                    if oSetting.oAction.bWaitForResponse:
                        StartWait(self.iWaitMs)
                    oSetting.oWebSocket.send(uMsg)
                    fSleep(fSeconds=0.01)
                    eRet = eReturnCode.Success
                    break
                except Exception as e:
                    self.ShowError(uMsg=u'Can\'t send message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
                    oSetting.Disconnect()
                    oSetting.bOnError = True
                    if not uRetVar == u'':
                        SetVar(uVarName=uRetVar, oVarValue=u"Error")
            else:
                if not uRetVar == u'':
                    SetVar(uVarName=uRetVar, oVarValue=u"Error")

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet