Exemple #1
0
    def UpdateWidget(self) -> None:
        """ Updates the silder pos, based on the assigned Var """

        uValue: str
        fMax: float
        fMin: float

        super().UpdateWidget()

        if not self.uDestVar == u'':
            uValue = GetVar(uVarName=self.uDestVar)
            fNewValue = ToFloat(uValue)

            if GetVar(uVarName=self.uMax) != u'':
                fMax = ToFloat(GetVar(uVarName=self.uMax))
            else:
                fMax = self.fMax

            if GetVar(uVarName=self.uMin) != u'':
                fMin = ToFloat(GetVar(uVarName=self.uMin))
            else:
                fMin = self.fMin

            if fNewValue > fMax:
                fNewValue = fMax
            if fNewValue < fMin:
                fNewValue = fMin
            if self.oObject:
                self.oObject.SetValue(fNewValue)
            self.fValue = Round(fNewValue, self.iRoundPos)
        self.UpdateVars()
Exemple #2
0
def Var_Power(uVarName: str, uPower: str) -> str:
    """
    Exponentiate a given variable value.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uPower: The value to exponentiate the original value with, can be a variable itself
    :return: The changed variable value
    """

    try:
        uValue: str = GetVar(uVarName=uVarName)
        uValueOrg: str = uValue
        if uValue == u'':
            return u''

        uPowerToUse: str = GetVar(uVarName=uPower)
        if uPowerToUse == u'':
            uPowerToUse = uPower
        uPowerToUse = ReplaceVars(uPowerToUse)
        fPower: float = ToFloat(uPowerToUse)
        fValue: float = ToFloat(uValue)
        fValue = fValue**fPower
        uValue = ToUnicode(fValue)
        uValue = Var_NormalizeInt(uValue)
        SetVar(uVarName=uVarName, oVarValue=uValue)
        Logger.debug(
            u'Var_Power: [%s] ^ [%s] returned [%s]  (stored in [%s])' %
            (uValueOrg, uPowerToUse, uValue, uVarName))
        return uValue
    except Exception as e:
        LogError(uMsg=u'Var_Power: Invalid Argument', oException=e)
        return u'Error'
Exemple #3
0
def Var_Hex2Int(uVarName):
    """
    Converts a Variable which represents an hex value to a string of an Int value
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """

    uValue = u''
    try:
        uValue = GetVar(uVarName=uVarName)

        if uValue == '':
            return u'0'
        if uValue == 'Error':
            return u'0'

        if uValue.lower().startswith('0x'):
            iValue = int(uValue, 0)
        else:
            iValue = int(uValue, 16)

        uValue = ToUnicode(iValue)
        uValue = Var_NormalizeInt(uValue)
        SetVar(uVarName=uVarName, oVarValue=uValue)
    except Exception as e:
        LogError(u'Var_Hex2Int: Invalid Argument (%s):' % uValue, e)
        return u'0'
    return uValue
Exemple #4
0
def Var_Round(uVarName: str, uPos: str) -> str:
    """
    Rounds a var value to the given round position.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)
    Example: Round(1.81,0) return 2. Round(1.81,1) returns 1.80

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uPos: The round position
    :return: The changed variable value
    """

    uValue: str = GetVar(uVarName=uVarName)

    try:
        if uValue == u'':
            return u''

        uPosToUse: str = GetVar(uVarName=uPos)
        if uPosToUse == u'':
            uPosToUse = uPos
        iPos: int = int(uPosToUse)
        uValue = ToUnicode(Round(ToFloat(uValue), iPos))
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue

    except Exception as e:
        LogError(uMsg=u'Var_Round: Invalid Argument [' + uVarName + u'=' +
                 uValue + u']:',
                 oException=e)
        return u'Error'
Exemple #5
0
def Var_Find(uVarName, uFindVar, uDestVar):
    """
    Finds the posiion of a substring in a variable value.
    The changed variable value will be returned and stored in the destination var (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :param string uFindVar: The string to search for
    :param string uDestVar: The name of the variable for the result (the Position) If not found, '-1' will be returned
    :return: The position of the substring
    """

    uValue = GetVar(uVarName=uVarName)
    uValue = uVarName
    if uValue == u'':
        uValue = uVarName
    uValue = ReplaceVars(uValue)

    uFindVar = ReplaceVars(uFindVar)
    iPos = uValue.find(uFindVar)
    uResult = ToUnicode(iPos)
    SetVar(uVarName=uDestVar, oVarValue=uResult)
    Logger.debug(u'Var_Find: [%s] in [%s] returned [%s]  (stored in [%s])' %
                 (uFindVar, uValue, uResult, uDestVar))
    return uResult
Exemple #6
0
 def FindDefinitionAliasForInterfaceConfiguration(self, uInterFaceName,
                                                  uConfigName):
     for oDefinition in self.aDefinitionList_List:
         uAddVar = oDefinition.uAlias
         uDefinitionInterFace = GetVar(uAddVar + "_INTERFACE_MAIN")
         if uDefinitionInterFace == uInterFaceName:
             uDefinitionConfig = GetVar(uAddVar + "_CONFIGNAME_MAIN")
             if uDefinitionConfig == uConfigName:
                 return oDefinition.uAlias
     return ""
Exemple #7
0
 def ImportOrcaFiles(self, *args, **kwargs) -> None:
     """
         Import all ORCA files from a given location
         """
     oPath: cPath = cPath(GetVar(uVarName="filebrowserfile"))
     oFnCheckFile: cFileName = cFileName(oPath + 'actions') + 'actions.xml'
     if oFnCheckFile.Exists():
         if not Globals.bProtected:
             oPath.Copy(oDest=Globals.oPathRoot)
             if GetVar(uVarName="CHECKBOX_IMPORT_CHANGE_LOCATION") == "1":
                 Globals.oOrcaConfigParser.set("ORCA", u'rootpath', '')
                 Globals.oOrcaConfigParser.write()
Exemple #8
0
 def FindDefinitionAliasForInterfaceConfiguration(self, *,
                                                  uInterFaceName: str,
                                                  uConfigName: str) -> str:
     for uDefinitionKey in self:
         oDefinition: cDefinition = cast(cDefinition, self[uDefinitionKey])
         uAddVar: str = oDefinition.uAlias
         uDefinitionInterFace: str = GetVar(uAddVar + "_INTERFACE_MAIN")
         if uDefinitionInterFace == uInterFaceName:
             uDefinitionConfig: str = GetVar(uAddVar + "_CONFIGNAME_MAIN")
             if uDefinitionConfig == uConfigName:
                 return oDefinition.uAlias
     return ""
Exemple #9
0
 def ExportOrcaFiles(self, *args, **kwargs) -> None:
     """
     Export all Orca Files a given location
     """
     oPath: cPath = cPath(
         GetVar(uVarName="filebrowserfile")) + "/OrcaExport"
     oPath.Delete()
     if not Globals.oPathRoot.string in oPath.string:
         fIgnore = ignore_patterns('*.ini', 'ORCA', '*.py*')
         Globals.oPathRoot.Copy(oDest=oPath, fIgnoreFiles=fIgnore)
         if GetVar(uVarName="CHECKBOX_EXPORT_CHANGE_LOCATION") == "1":
             Globals.oOrcaConfigParser.set("ORCA", u'rootpath',
                                           oPath.string)
             Globals.oOrcaConfigParser.write()
Exemple #10
0
def Var_HexStringToString(uVarName):
    """
    Converts a var value which represents a hex string to a string which represents the number.
    The changed variable value will be returned and stored in the destination var (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """

    uValue = GetVar(uVarName=uVarName)
    uValue = uValue.decode("hex")
    SetVar(uVarName=uVarName, oVarValue=uValue)
    return uValue
Exemple #11
0
def Var_Trim(uVarName):
    """
    Removes trailing a leading spaces from a var value.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """

    uValue = GetVar(uVarName=uVarName)
    uValue = uValue.strip()
    SetVar(uVarName=uVarName, oVarValue=uValue)
    return uValue
Exemple #12
0
def Var_LowerCase(uVarName):
    """
    Converts a variable value to lowercase.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """

    uValue = GetVar(uVarName=uVarName)
    uValue = uValue.lower()
    SetVar(uVarName=uVarName, oVarValue=uValue)
    return uValue
Exemple #13
0
    def UpdateWidget(self):

        if not self.uDestVar==u'':

            h=GetVar(uVarName = self.uDestVar+u'_h')
            s=GetVar(uVarName = self.uDestVar+u'_s')
            v=GetVar(uVarName = self.uDestVar+u'_v')

            r=''

            if h!='':
                h=ToFloat(h)/255
                s=ToFloat(s)/255
                v=ToFloat(v)/255
                r,g,b=hsv_to_rgb(h,s,v)
            else:
                r=GetVar(uVarName = self.uDestVar+u'_r')
                g=GetVar(uVarName = self.uDestVar+u'_g')
                b=GetVar(uVarName = self.uDestVar+u'_b')

            if r=='':
                oColor=GetColorFromHex(GetVar(uVarName = self.uDestVar))
                if len(oColor)==0:
                    oColor= Color(1, 1, 1, 1)
                else:
                    r,g,b,a=GetColorFromHex(GetVar(uVarName = self.uDestVar))

            if r!='':
                r = ToFloat(r) / 255
                g = ToFloat(g) / 255
                b = ToFloat(b) / 255
                self.oObjectColorPicker.color=(r,g,b,1)
Exemple #14
0
def Var_Part(uVarName: str, uStart: str, uEnd: str) -> str:
    """
    Extracts a part of a variable value.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uStart: The start position within the var value
    :param str uEnd: The end position within the var value
    :return: The changed variable value
    """

    try:
        uValue: str = GetVar(uVarName=uVarName)
        if uValue == u'':
            return u''
        if not uStart == '':
            if not uEnd == '':
                uValue = uValue[int(uStart):int(uEnd)]
            else:
                uValue = uValue[int(uStart):]
        else:
            uValue = uValue[:int(uEnd)]
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue
    except Exception as e:
        LogError(uMsg='Var_Part: Invalid Argument', oException=e)
        return u'Error'
Exemple #15
0
def Var_Int2Hex(uVarName: str, uFormat: str = '{0:0>2X}') -> str:
    """
    Converts a Variable which represents an int value to a string of a hex value
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uFormat: The format to use for the conversion
    :return: The changed variable value
    """

    uValue: str = GetVar(uVarName=uVarName)
    try:

        if uValue == '':
            return u'0'
        if uValue == 'Error':
            return u'0'

        uValue = uFormat.format(int(uValue))
        uValue = ToUnicode(uValue)
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue
    except Exception as e:
        LogError(uMsg=u'Var_Int2Hex: Invalid Argument (%s):' % uValue,
                 oException=e)
        return u'0'
Exemple #16
0
def Var_Format(uVarName: str, uFormat: str):
    """
    Formats a variable content to a given format
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uFormat: The format to use (python syntax)
    :return: The changed variable value
    """

    try:
        uValue: str = GetVar(uVarName=uVarName)
        if uValue is None:
            return u''
        uFormatToUse: str = ORCA.vars.Globals.dUserVars.get(uFormat)
        if uFormatToUse is None:
            uFormatToUse = uFormat

        if uFormatToUse.startswith('(int)'):
            uFormatToUse = uFormatToUse[5:]
            uValue = uFormatToUse.format(int(ToFloat(uValue)))
        elif uFormatToUse.startswith('(float)'):
            uFormatToUse = uFormatToUse[7:]
            uValue = uFormatToUse.format(ToFloat(uValue))
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue
    except Exception as e:
        LogError(uMsg=u'Var_Format: Invalid Argument', oException=e)
        return u''
Exemple #17
0
 def Invert(self, instance: cTouchButton) -> None:
     """ Inverts the button state """
     if self.uGroup == '':
         self.InvertSwitch(instance)
         return
     if GetVar(uVarName=self.uDestVar) == '1':
         return
     self.InvertSwitch(instance)
Exemple #18
0
 def InitWidgetFromXml(self,*,oXMLNode:Element,oParentScreenPage:cScreenPage, uAnchor:str) -> bool:
     """ Reads further Widget attributes from a xml node """
     bRet:bool = super(cWidgetTextInput, self).InitWidgetFromXml(oXMLNode=oXMLNode,oParentScreenPage=oParentScreenPage, uAnchor=uAnchor)
     self.uDestVar = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'destvar', bMandatory=False,vDefault=u'inputstring')
     uTmp:str = GetVar(uVarName = self.uDestVar)
     if uTmp:
         self.uCaption=uTmp
     return bRet
Exemple #19
0
 def InitWidgetFromXml(self, oXMLNode, oParentScreenPage, uAnchor):
     """ Reads further Widget attributes from a xml node """
     self.oPathStart = cPath(GetVar(uVarName="filebrowserfile"))
     self.uActionNameCancel = GetXMLTextAttribute(oXMLNode, u'actioncancel',
                                                  False, u'')
     self.bDirSelect = GetXMLBoolAttribute(oXMLNode, u'dirselect', False,
                                           False)
     return self.ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor)
Exemple #20
0
def Var_Concatenate(uVarName: str, uAddVar: str) -> str:
    """
    Adds a string to a variable value.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :param str uVarName: The variable name for the action, from where the value is pulled
    :param str uAddVar: The string to add to the var value, can be a variable itself
    :return: The changed variable value
    """

    uValue: str = GetVar(uVarName=uVarName)
    uValueAdd: str = GetVar(uVarName=uAddVar)
    if uValueAdd == u'':
        uValueAdd = uAddVar
    uValue += uValueAdd
    SetVar(uVarName=uVarName, oVarValue=uValue)
    return uValue
Exemple #21
0
 def ExportOrcaFiles(self, *args, **kwargs):
     """
     Export all Orca Files a given location
     """
     oPath = cPath(GetVar(uVarName="filebrowserfile")) + "/OrcaExport"
     oPath.Delete()
     if not Globals.oPathRoot.string in oPath.string:
         fIgnore = ignore_patterns('*.ini', 'ORCA', '*.py*')
         Globals.oPathRoot.Copy(oPath, fIgnore)
Exemple #22
0
 def ImportOrcaFiles(self, *args, **kwargs):
     """
     Import all ORCA files from a given location
     """
     oPath = cPath(GetVar(uVarName="filebrowserfile"))
     oFnCheckFile = cFileName(oPath + 'actions') + 'actions.xml'
     if oFnCheckFile.Exists():
         if not Globals.bProtected:
             oPath.Copy(Globals.oPathRoot)
Exemple #23
0
    def ConfigureKivySettingsForDiscoverParameter(
            self, oKivySetting: KivySettings,
            uConfigName: str) -> Union[KivyConfigParser, None]:
        """
        Create the JSON string for all discover scripts and applies it to a kivy settings object

        :param setting oKivySetting:
        :param string uConfigName:
        :return: The KivySetting object
        """

        uSettingsJSON: str
        uKey: str
        uDictKey: str

        SetVar(uVarName=u'ObjectConfigSection', oVarValue=uConfigName)
        self.uConfigName = uConfigName
        RegisterSettingTypes(oKivySetting)
        oSetting: cBaseInterFaceSettings = self.oInterFace.GetSettingObjectForConfigName(
            uConfigName=uConfigName)
        dSettingsJSON: Dict[str, Dict] = self.CreateSettingJsonCombined(
            oSetting=oSetting)
        if len(dSettingsJSON) == 0:
            return None
            # return self.On_SettingsClose(None)

        # add the jSon to the Kivy Setting

        dTarget: Dict[str, Dict] = {}
        for uKey in dSettingsJSON:
            uDictKey = dSettingsJSON[uKey]['scriptsection']
            if dTarget.get(uDictKey) is None:
                dTarget[uDictKey] = {}
            dTarget[uDictKey][uKey] = dSettingsJSON[uKey]

        for uKey in dTarget:
            if not uKey.startswith('discover'):
                uSettingsJSON = SettingDictToString2(dTarget[uKey])
                uSettingsJSON = ReplaceVars(uSettingsJSON)
                if uSettingsJSON != u'[]':
                    oKivySetting.add_json_panel(ReplaceVars(uKey),
                                                self.oConfigParser,
                                                data=uSettingsJSON)

        for uKey in dTarget:
            if uKey.startswith('discover'):
                if uKey in GetVar("DISCOVERSCRIPTLIST"):
                    uSettingsJSON = SettingDictToString2(dTarget[uKey])
                    uSettingsJSON = ReplaceVars(uSettingsJSON)
                    if uSettingsJSON != u'[]':
                        oKivySetting.add_json_panel(uKey[9:].upper(),
                                                    self.oConfigParser,
                                                    data=uSettingsJSON)

        # Adds the action handler
        oKivySetting.bind(on_config_change=self.On_ConfigChange)
        return oKivySetting
Exemple #24
0
    def _ExecuteActions(self,aActions, oParentWidget):
        """ This functions just adds the action commands to the queue and calls the scheduler at the end """

        oQueue = GetActiveQueue()

        for aTmpAction in aActions:
            oAction = copy(aTmpAction)
            oAction.oParentWidget = oParentWidget

            iActionId=oAction.iActionId

            ''' this enables to any function to call without call statement from an macro, as long as the action exists'''
            if iActionId==Globals.oActions.oActionType.NoAction:
                if oAction.uActionString.lower()!="noaction":
                    oAction.iActionId=-1
                    aTmpActions = Globals.oActions.GetActionList(uActionName = oAction.uActionString, bNoCopy = True)
                    if aTmpActions is not None:
                        iActionId=aTmpActions[0].iActionId

            if iActionId == Globals.oActions.oActionType.SendCommand:
                oTmpAction = copy(aTmpAction)
                oTmpAction.dActionPars['string']='enabletransmitterpicture'
                oTmpAction.iActionId = GetActionID(oTmpAction.dActionPars['string'])
                self.__InsertToQueue(oTmpAction, oQueue)
            if iActionId == Globals.oActions.oActionType.ShowPage:
                oTmpAction = copy(aTmpAction)
                oTmpAction.dActionPars['string'] = 'call'
                oTmpAction.dActionPars['actionname'] = 'PAGESTOPACTIONS'
                oTmpAction.iActionId = GetActionID(oTmpAction.dActionPars['string'])
                self.__InsertToQueue(oTmpAction, oQueue)

            self.__InsertToQueue(oAction, oQueue)

            if iActionId == Globals.oActions.oActionType.ShowPage:
                oTmpAction = copy(aTmpAction)
                uPagenameToCall = oAction.dActionPars.get('pagename','')
                if uPagenameToCall == "":
                    if oAction.oParentWidget is not None:
                        uPagenameToCall = oAction.oParentWidget.dActionPars.get('pagename','')
                oTmpAction.dActionPars['string'] = 'call'
                oTmpAction.dActionPars['actionname'] = 'PAGESTARTACTIONS'
                oTmpAction.dActionPars['pagename'] = uPagenameToCall
                oTmpAction.dActionPars['currentpagename'] = GetVar(uVarName = 'CURRENTPAGE')
                #oTmpAction.dActionPars['currentpagename'] = GetVar('LASTPAGE')
                oTmpAction.iActionId = GetActionID(oTmpAction.dActionPars['string'])
                self.__InsertToQueue(oTmpAction, oQueue)
            if iActionId == Globals.oActions.oActionType.SendCommand:
                oTmpAction = copy(aTmpAction)
                oTmpAction.dActionPars['string'] = 'disabletransmitterpicture'
                oTmpAction.iActionId = GetActionID(oTmpAction.dActionPars['string'])
                self.__InsertToQueue(oTmpAction, oQueue)

        oQueue = GetActiveQueue()
        if not oQueue.bForceState:
            Clock.schedule_once(partial(oQueue.WorkOnQueue,oQueue.bForceState), 0)
        else:
            return oQueue.WorkOnQueue(oQueue.bForceState)
Exemple #25
0
def Var_Increase(uVarName, uStep='1', uMax=''):
    """
    Increase a given variable value.
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :param string uStep: The value to added to the original value, can be a variable itself
    :param string uMax: The maximum value, which can't be exceeded, can be a variable itself, If empty, no limit is used
    :return: The changed variable value
    """

    uValue = u''
    try:
        uValue = GetVar(uVarName=uVarName)
        uValueOrg = uValue

        if uValue == u'':
            uValue = '0'
        uStepToUse = GetVar(uVarName=uStep)
        if uStepToUse == u'':
            uStepToUse = uStep
        uStepToUse = ReplaceVars(uStepToUse)
        uMaxToUse = GetVar(uVarName=uMax)
        if uMaxToUse == u'':
            uMaxToUse = uMax

        fValue = ToFloat(uValue)
        fValue += ToFloat(uStepToUse)
        if not uMaxToUse == u'':
            fMaxToUse = ToFloat(uMaxToUse)
            if fValue > fMaxToUse:
                fValue = fMaxToUse
        uValue = ToUnicode(fValue)
        uValue = Var_NormalizeInt(uValue)
        SetVar(uVarName=uVarName, oVarValue=uValue)
        Logger.debug(
            u'Var_Increase: [%s] plus [%s] returned [%s]  (stored in [%s])' %
            (uValueOrg, uStepToUse, uValue, uVarName))
    except Exception as e:
        LogError(u'Var_Increase: Invalid Argument', e)
        return u'Error'

    return uValue
Exemple #26
0
def Var_Invert(uVarName):
    """
    Inverts a given variable value.
    Converts the following values
    [0|1]
    [false:true] [False:True] [FALSE:TRUE]
    [off:on][Off:On][OFF:ON]
    The changed variable value will be return and stored in the user vars (Triggers raised if set)

    :rtype: string
    :param string uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """

    uValue = GetVar(uVarName=uVarName)

    uVarNameOrg = uVarName

    if uValue is not None:
        if uValue == u'0':
            uValue = u'1'
        elif uValue == u'1':
            uValue = u'0'
        elif uValue == u'false':
            uValue = u'true'
        elif uValue == u'true':
            uValue = u'false'
        elif uValue == u'False':
            uValue = u'True'
        elif uValue == u'True':
            uValue = u'False'
        elif uValue == u'FALSE':
            uValue = u'TRUE'
        elif uValue == u'TRUE':
            uValue = u'FALSE'
        elif uValue == u'OFF':
            uValue = u'ON'
        elif uValue == u'ON':
            uValue = u'OFF'
        elif uValue == u'off':
            uValue = u'on'
        elif uValue == u'on':
            uValue = u'off'
        elif uValue == u'Off':
            uValue = u'On'
        elif uValue == u'On':
            uValue = u'Off'
        elif uValue == u'':
            uValue = u'1'
    SetVar(uVarName=uVarName, oVarValue=uValue)

    uVarNameOrg = uVarName
    Logger.debug(u'Var_Invert: [%s] returned [%s]  (stored in [%s])' %
                 (uVarNameOrg, uValue, uVarName))

    return uValue
Exemple #27
0
 def UpdateWidget(self):
     """ Updates the switch states based on the vars """
     if self.uGroup:
         if GetVar(uVarName=self.uDestVar) == '1':
             self.GroupSwitch()
             # return
     Var_Invert(self.uDestVar)
     self.InvertSwitch(None)
     super().UpdateWidget()
     return
Exemple #28
0
def Var_StringToHexString(uVarName: str) -> str:
    """
    Converts a var value to a hex string.
    The changed variable value will be returned and stored in the destination var (Triggers raised if set)
    eg: "paul" to "7061756c"

    :param str uVarName: The variable name for the action, from where the value is pulled
    :return: The changed variable value
    """
    uValue = GetVar(uVarName=uVarName)
    try:
        uValue = ToUnicode(uValue.encode("utf-8").hex())
        SetVar(uVarName=uVarName, oVarValue=uValue)
        return uValue
    except Exception as e:
        LogError(uMsg=u'Var_StringToHexString: Invalid Argument [' + uVarName +
                 u'=' + uValue + u']:',
                 oException=e)
        return u'Error'
Exemple #29
0
 def InvertSwitch(self, instance: Union[cTouchButton, None]) -> None:
     """ Inverts and button and the var """
     if GetVar(uVarName=self.uDestVar) == '1':
         SetVar(uVarName=self.uDestVar, oVarValue='0')
         self.SetPictureNormal(self.oFnButtonPictureNormalOrg.string, True)
         self.SetPicturePressed(self.oFnButtonPicturePressedOrg.string)
     else:
         SetVar(uVarName=self.uDestVar, oVarValue='1')
         self.SetPictureNormal(self.oFnButtonPicturePressedOrg.string, True)
         self.SetPicturePressed(self.oFnButtonPictureNormalOrg.string)
Exemple #30
0
def Var_Save(*, uVarName: str, uPrefix: str) -> None:
    """ Saves a var to a cookie """
    uValue: str = GetVar(uVarName=uVarName)
    oFN: cFileName = CookieName(uVarName=uVarName, uPrefix=u'var_' + uPrefix)
    try:
        oFile = open(oFN.string, 'w')
        oFile.write(uValue)
        oFile.close()
    except Exception as e:
        LogError(uMsg=u'Var_Save: can\'t safe var', oException=e)