예제 #1
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)
예제 #2
0
    def SaveRepositoryXML(self, uType, uDescription):
        """ Saves the main repository directory xml """
        oPath = Globals.oPathTmp + "RepManager"
        oPath.Create()
        oPath = oPath + "repositories"
        oPath.Create()
        oPath = oPath + uType
        oPath.Create()
        oFnXml = cFileName(oPath) + 'repository.xml'

        oXMLRoot = Element('repository')
        oVal = SubElement(oXMLRoot, 'version')
        oVal.text = '1.00'
        oVal = SubElement(oXMLRoot, 'type')
        oVal.text = uType
        oVal = SubElement(oXMLRoot, 'description')
        oVal.text = uDescription

        oXMLEntries = SubElement(oXMLRoot, 'entries')

        for oEntry in self.oRepManagerEntries:
            Logger.debug('Saving Repository-Entry [%s]' %
                         oEntry.oFnEntry.string)

            oEntry.oRepEntry.WriteToXMLNode(oXMLEntries)
            for oSource in oEntry.oRepEntry.aSources:
                bZipParentDir = cPath.CheckIsDir(oSource.uLocal)
                # Create according Zip
                if bZipParentDir:
                    uUpper1 = os.path.split(
                        os.path.abspath(oSource.uSourceFile))[0]
                    uUpper2 = os.path.split(os.path.abspath(uUpper1))[0]
                    uUpper = uUpper1[len(uUpper2) + 1:]
                    uUpper = os.path.basename(oSource.uLocal)
                    uUpper = os.path.basename(oSource.uSourceFile)
                    uFinalPath = uType
                    oDest = cFileName().ImportFullPath(
                        '%s/RepManager/repositories/%s/%s' %
                        (Globals.oPathTmp.string, uFinalPath, uUpper))
                    uUpper1 = os.path.split(os.path.abspath(oSource.uLocal))[0]
                    uRoot = '%s/%s/' % (Globals.oPathRoot.string, uType)
                    uRoot = AdjustPathToOs(ReplaceVars(uUpper1) + '/')
                    self.aZipFiles.append({
                        'filename':
                        oSource.uLocal,
                        'dstfilename':
                        oDest.string,
                        'removepath':
                        uRoot,
                        'skipfiles':
                        ToUnicode(oEntry.oRepEntry.aSkipFileNames)
                    })
                else:
                    uDest = AdjustPathToOs(
                        '%s/RepManager/repositories/%s/%s.zip' %
                        (Globals.oPathTmp.string, uType,
                         os.path.splitext(os.path.basename(
                             oSource.uLocal))[0]))
                    uRoot = AdjustPathToOs(Globals.oPathRoot.string + "/" +
                                           oSource.uTargetPath)
                    self.aZipFiles.append({
                        'filename': oSource.uLocal,
                        'dstfilename': uDest,
                        'removepath': uRoot
                    })

        oFSFile = open(oFnXml.string, 'w')
        uContent = XMLPrettify(oXMLRoot)
        uContent = ReplaceVars(uContent)
        if PY2:
            oFSFile.write(uContent.encode('utf8'))
        else:
            oFSFile.write(EscapeUnicode(uContent))
        oFSFile.close()
예제 #3
0
def OrcaConfigParser_On_Setting_Change(config, section, key, value):

    uValue = ToUnicode(value)

    if section == "ORCA":
        if   key == u'button_clear_atlas':
            ClearAtlas()
        elif key == u"button_notification":
            uNotification = value.split("_")[-1]
            Globals.oNotifications.SendNotification(uNotification,**{"key":key,"value":value})
        elif key == u'button_discover_rediscover':
            if uValue == u'button_discover_rediscover':
                Globals.oInterFaces.DiscoverAll()
            else:
                Globals.oInterFaces.DiscoverAll(bForce=True)
        elif key == u'button_discover_results':
            from ORCA.utils.Discover import cDiscover_List
            Globals.oApp.oDiscoverList = cDiscover_List()
            Globals.oApp.oDiscoverList.ShowList()
        elif key == u'button_getonline':
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_Settings_Download')
        elif key == u'button_installed_reps':
            Globals.oDownLoadSettings.LoadDirect(uValue, True)
        elif key == u'button_show_installationhint':
            Var_DeleteCookie('SHOWINSTALLATIONHINT', Globals.uDefinitionName)
            Globals.oTheScreen.AddActionToQueue([{'string': 'call', 'actionname': 'Fkt ShowInstallationHint'}])
        elif key == u'button_show_licensefile':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(LICENSEFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_credits':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(CREDITSFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_logfile':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(LOGFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_powerstati':
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_PowerStati')
        elif key == u'button_updateallreps':
            Globals.oDownLoadSettings.UpdateAllInstalledRepositories(True)
        elif key == u'language':
            # Changes the languages, reloads all strings and reloads the settings dialog
            Globals.uLanguage = uValue
            Globals.oApp.InitPathes()
            Globals.oNotifications.SendNotification("on_language_change")
        elif key == u'locales':
            Globals.uLocalesName = uValue
            Globals.oTheScreen.LoadLocales()
        elif key == u'startrepeatdelay':
            Globals.fStartRepeatDelay = float(uValue)
        elif key == u'longpresstime':
            Globals.fLongPressTime = float(uValue)
        elif key == u'contrepeatdelay':
            Globals.fContRepeatDelay = float(uValue)
        elif key == u'clockwithseconds':
            Globals.bClockWithSeconds = (uValue == '1')
        elif key == u'longdate':
            Globals.bLongDate = (uValue == '1')
        elif key == u'longday':
            Globals.bLongDay = (uValue == '1')
        elif key == u'longmonth':
            Globals.bLongMonth = (uValue == '1')
        elif key == u'checkfornetwork':
            Globals.bConfigCheckForNetwork = (uValue == '1')
        elif key == u'vibrate':
            Globals.bVibrate = (uValue == '1')
        elif key == u'interface':
            if uValue == 'select':
                return
            Globals.oTheScreen.uInterFaceToConfig = uValue
            if Globals.oInterFaces.dInterfaces.get(uValue) is None:
                Globals.oInterFaces.LoadInterface(uValue)
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_InterfaceSettings')
            Globals.oOrcaConfigParser.set(u'ORCA', key, u'select')
            Globals.oOrcaConfigParser.write()
        elif key == u'script':
            if uValue == 'select':
                return
            uScript = u''
            Globals.oOrcaConfigParser.set(u'ORCA', key, 'select')
            Globals.oOrcaConfigParser.write()

            tValue = uValue.split(':')
            uValue = tValue[0]
            if len(tValue) > 1:
                uScript = tValue[1]

            # Configure
            if uValue == ReplaceVars('$lvar(516)'):
                Globals.oTheScreen.uScriptToConfig = uScript
                Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ScriptSettings')

            # Run
            if uValue == ReplaceVars('$lvar(517)'):
                kwargs = {"caller": "settings"}
                Globals.oScripts.RunScript(uScript,**kwargs)
            Globals.oOrcaConfigParser.set(u'ORCA', key, u'select')
            Globals.oOrcaConfigParser.write()

        elif key == u'definition':
            ShowQuestionPopUp(uTitle='$lvar(599)', uMessage='$lvar(5026)', fktYes=Globals.oApp.on_config_change_change_definition, uStringYes='$lvar(5001)', uStringNo='$lvar(5002)')
        elif key == u'skin':
            Globals.oApp.ReStart()
        elif key == u'rootpath':
            if not Globals.bInit:
                Globals.oApp.close_settings()
                Globals.oApp._app_settings = None
                kivyConfig.write()
                Clock.schedule_once(Globals.oApp.Init_ReadConfig, 0)
            else:
                ShowMessagePopUp(uMessage=u'$lvar(5011)')
        elif key.startswith(u'soundvolume_'):
            uSoundName = key[12:]
            Globals.oSound.SetSoundVolume(uSoundName, ToInt(uValue))
            Globals.oSound.PlaySound(uSoundName)
        elif key == u'button_changedefinitionsetting':
            Globals.uDefinitionToConfigure = uValue[7:]
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_DefinitionSettings')
        else:
            ShowMessagePopUp(uMessage=u'$lvar(5011)')

        # todo: check , if this required anymore
    elif section == Globals.uDefinitionName:
        if key in Globals.oDefinitions.aDefinitionSettingVars:
            SetVar(uVarName = key, oVarValue = value)
        ShowMessagePopUp(uMessage=u'$lvar(5011)')
예제 #4
0
 def SetContextVar(self, uVarName, uVarPar):
     """ Sets a var within the script context """
     SetVar(uVarName=uVarName,
            oVarValue=ToUnicode(uVarPar),
            uContext=self.oScript.uScriptName + u'/' + self.uConfigName)
예제 #5
0
    def ExecuteActionGetWidgetAttribute(self,oAction):
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-GetWidgetAttribute
        WikiDoc:TOCTitle:getwidgetattribute
        = getwidgetattribute =
        Gets some attributes of widgets

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |getwidgetattribute
        |-
        |widgetname
        |Name of the widget, which attribute should be returned
        |-
        |attributename
        |Name of the attribute to return. You can get the following attributes:
        *'bold': Get the "bold" attribute of a font (0/1)
        *'italic': Get the "italic" attribute of a font (0/1)
        *'textcolor': Gets the text color (hex RGBA)
        *'fontsize': Gets the font size of text
        *'caption': Gets the caption of text
        *'enabled': Gets the Enable/Disable attribute of a widget (0/1)
        *'picturenormal': Gets the picture name of a BUTTON or PICTURE.
        *'picturepressed': Gets the pressed picture name of a BUTTON.
        *'color': Gets the background color (hex RGBA), (RECTANGLE, CIRCLE only)
        *'transparency': Gets the transparency of a widget
        *'action': Gets the action of a widget
        *'startangle': For Circles: Gets the start angle of the circe
        *'endangle': For Circles: Gets the end angle of the circe
        *'exists': Returns, if the widget exists (0/1)
        |-
        |retvar
        |the varname, which should hold the return value
        |-
        |ignoremissing
        |Dont raise an error if widget is missing
        |-
        |touchtype
        |For action attribute: the touch type of the action
        * (nothing = Standard action)
        * Other options are 'double', 'up', 'down'
        |}</div>
        A short example:
        WikiDoc:End
        """

        self.oEvenDispatcher.LogAction(u'GetWidgetAttribute',oAction)

        uWidgetName       = ReplaceVars(oAction.dActionPars.get("widgetname",""))
        uAttributeName    = ReplaceVars(oAction.dActionPars.get("attributename",""))
        uRetVar           = ReplaceVars(oAction.dActionPars.get("retvar",""))
        uTouchType        = ReplaceVars(oAction.dActionPars.get("touchtype",""))
        bIgnoreMissing    = ToBool(ReplaceVars(oAction.dActionPars.get("ignoremissing","0")))

        uRet = "error"
        iRet = 0
        bIgnoreError      = (uAttributeName == u'exists')

        try:
            uPageName=u''
            if oAction.oParentWidget is not None:
                uPageName=oAction.oParentWidget.oParentScreenPage.uPageName

            aWidgets=Globals.oTheScreen.FindWidgets(uPageName=uPageName,uWidgetName=uWidgetName, bIgnoreError=(bIgnoreError | bIgnoreMissing))
            if len(aWidgets)==1:
                oWidget=aWidgets[0]
                bRet=True
                if uAttributeName==u'bold' or uAttributeName==u'italic' or uAttributeName==u'textcolor':
                    uRet = oWidget.GetWidgetFontStyle(uAttributeName)
                elif uAttributeName==u'caption':
                    uRet =  oWidget.uCaption
                elif uAttributeName==u'picturenormal':
                    uRet =  oWidget.uPictureNormal.string
                elif uAttributeName==u'picturepressed':
                    uRet =  oWidget.oButtonPicturePressed.string
                elif uAttributeName==u'color':
                    uRet =  oWidget.uBackGroundColor
                elif uAttributeName==u'fontsize':
                    uRet =  ToUnicode(oWidget.oObject.font_size)
                elif uAttributeName==u'transparancy':
                    uRet =  ToUnicode(oWidget.fOrgOpacity )
                elif uAttributeName==u'filename':
                    uRet =  oWidget.uFileName
                elif uAttributeName==u'enabled':
                    uRet = u"0"
                    if oWidget.bEnabled:
                        uRet= u"1"
                elif uAttributeName==u'startangle':
                    uRet = ToUnicode(oWidget.fStartAngle)
                elif uAttributeName==u'endangle':
                    uRet = ToUnicode(oWidget.iWidgetType)
                elif uAttributeName==u'action':
                    uRet=oWidget.uActionName
                elif uAttributeName == u'exists':
                    uRet = "1"
                else:
                    uMsg=u'Action: GetWidgetAttribute: Attribute not Found %s %s' %(uWidgetName,uAttributeName)
                    Logger.error (uMsg)
                    ShowErrorPopUp(uTitle='Warning',uMessage=uMsg)
                    iRet = 1
            else:
                if uAttributeName == u'exists':
                    uRet="0"
                else:
                    iRet = 1

        except Exception as e:
            uMsg=LogError('Action: GetWidgetAttribute: Could not set Attribut: %s:%s' % (uWidgetName,uAttributeName),e)
            ShowErrorPopUp(uTitle='Warning',uMessage=uMsg)
            iRet = 1

        SetVar(uRetVar,uRet)
        return iRet
예제 #6
0
 def OnSliderMoved(self, instance, touch):
     """ updates the text value, whne the slider is moved """
     self.textvalue.text = ToUnicode(Round(instance.value, self.iRoundPos))
예제 #7
0
 def _validate(self, instance):
     """ returns the value of the slider """
     self._dismiss()
     self.value = ToUnicode(Round(self.slider.value, self.iRoundPos))
예제 #8
0
    def ExecuteActionRemoveDefinitionSetting(self, oAction):
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-RemoveDefinitionSetting
        WikiDoc:TOCTitle:removedefinitionsetting
        = removedefinitionsetting =
        Removes a definitionsetting from a definition.
        Must be called in appstartactions or in definitionstartactions.

        This function removes either
        * a single setting within a settings of a definition
        * a set of settings which are identified by the title of the section
        * all settings of a definition

        This function is usefull, when you import a definition with it's settings, but not all settings apply to the parent setting. Remarks: Using this function will replace all variable names in the settings at this time.

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |removedefinitionsetting
        |-
        |definitionname
        |If empty, the whole definitionsetting will be removed
         If given, this is variable name of the single setting within the definitionsetting to remove: Variablenames will be replaced
         If you want to remove a complete section you need to pass the title name as the variable name
        |}</div>
        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="Remove the Numberpad settings from the imported setting" string="removedefinitionsetting" definitionname="kodi_mediaplayer_template" settingname="$lvar(mediaplayertemplate_10070) ($dvar(definition_alias_mediaplayer_template))"/>
        </syntaxhighlight></div>
        WikiDoc:End
        """

        self.oEvenDispatcher.LogAction(u'RemoveDefinitionSetting', oAction)
        uDefinitionName = ReplaceVars(
            oAction.dActionPars.get("definitionname", ""))
        uSettingVar = ReplaceVars(oAction.dActionPars.get("settingname", ""))
        uSettingVarOrg = oAction.dActionPars.get("settingname", "")
        bFound = False

        oDef = Globals.oDefinitions[uDefinitionName]
        if oDef:
            if uSettingVar == u'':
                oDef.dDefinitionSettingsJSON.clear()
                bFound = True
            elif self.RemoveSettingSection(uSettingVarOrg, oDef):
                bFound = True
            else:
                import json
                for uVisSection in oDef.dDefinitionSettingsJSON:
                    aDefinitionSettingsJSON = json.loads(
                        ReplaceVars(oDef.dDefinitionSettingsJSON[uVisSection]))
                    aDefinitionSettingsJSON2 = json.loads(
                        ReplaceVars(oDef.dDefinitionSettingsJSON[uVisSection]))
                    iStart = -1
                    for aLine in aDefinitionSettingsJSON2:
                        iStart += 1
                        if aLine.get('key') is not None:
                            if aLine.get('key') == uSettingVar or aLine.get(
                                    'key') == uSettingVarOrg:
                                aDefinitionSettingsJSON.remove(aLine)
                                bFound = True
                                break
                        else:
                            if aLine.get('type') == 'title':
                                if aLine.get('title') == uSettingVar:
                                    bFound = True
                                    iEnd = iStart
                                    for aLine2 in aDefinitionSettingsJSON2[
                                            iStart + 1:]:
                                        if aLine2.get('key') is not None:
                                            iEnd += 1
                                        else:
                                            break
                                    del aDefinitionSettingsJSON[iStart:iEnd +
                                                                1]
                                    break
                    oDef.dDefinitionSettingsJSON[uVisSection] = ToUnicode(
                        json.dumps(aDefinitionSettingsJSON))

        else:
            LogError(
                u'Action: RemoveDefinitionSetting: Wrong definition name:' +
                uDefinitionName)
            Globals.oDefinitions.DumpDefinitionList()
            return 1
        if not bFound:
            LogError(
                u'Action: RemoveDefinitionSetting: Cannot remove setting (not found) : %s [%s] [%s]'
                % (uSettingVar, uSettingVarOrg, uDefinitionName))
        return 0