def InitWidgetFromXml(self,*,oXMLNode:Element,oParentScreenPage:cScreenPage, uAnchor:str) -> bool: uCaption:str = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag="caption",bMandatory=False,vDefault="") bRet:bool = super().InitWidgetFromXml(oXMLNode=oXMLNode,oParentScreenPage=oParentScreenPage, uAnchor=uAnchor) bDummy:bool oXMLNode.set("caption", uCaption) if bRet: self.aFrameColor = GetColorFromHex(GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'framecolor',bMandatory=False,vDefault=u'$var(dimmed)')) # uFramewidth:str = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'framewidth', bMandatory=False,vDefault=str(int((self.oDef.iDefMaxX/self.fRationX)*0.03))) uFramewidth:str = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'framewidth', bMandatory=False,vDefault=str(int((self.oDef.iDefMaxX/self.fRationX)*0.05))) self.iFrameWidth,bDummy = self.CalculateWidth(uWidth=uFramewidth,iAnchorWidth=self.iWidth) self.iFrameWidth = self.iFrameWidth / self.fRationX self.aCaptions = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'captions', bMandatory=False,vDefault=u'unknown').split(u',') self.aActionNames = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'actions', bMandatory=False,vDefault=u'').split(u',') self.aOrgActionNames = copy(self.aActionNames) self.bSorted = GetXMLBoolAttribute(oXMLNode=oXMLNode,uTag=u'sorted', bMandatory=False,bDefault=False) self.bSetCaption = GetXMLBoolAttribute(oXMLNode=oXMLNode,uTag=u'setcaption', bMandatory=False,bDefault=False) self.oXMLNode = oXMLNode # this is a little bit tricky # we should parse all dropdown button here as well, but then, # updatewidget for the dropdown would not work # so we do it in create, but at that time, the dimensions of the anchor is lost # so, we need to save the anchor dimensions here self.iTmpAnchorWidth = self.oTmpAnchor.iWidth self.iTmpAnchorHeight = self.oTmpAnchor.iHeight return bRet
def InitWidgetFromXml(self, *, oXMLNode: Element, oParentScreenPage: cScreenPage, uAnchor: str) -> bool: """ Reads further Widget attributes from a xml node """ self.bIsClock = GetXMLBoolAttribute(oXMLNode=oXMLNode, uTag=u'clock', bMandatory=False, bDefault=False) self.bIsDate = GetXMLBoolAttribute(oXMLNode=oXMLNode, uTag=u'date', bMandatory=False, bDefault=False) return self.ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor)
def InitWidgetFromXml(self, *, oXMLNode: Element, oParentScreenPage: cScreenPage, uAnchor: str) -> bool: """ Reads further Widget attributes from a xml node """ bRet: bool = self.ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor) if bRet: self.SetPictureNormal( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'picturenormal', bMandatory=False, vDefault=u'')) self.SetPicturePressed( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'picturepressed', bMandatory=False, vDefault=u'')) #self.SetPictureDisabled (GetXMLTextAttribute(oXMLNode,u'picturedisabled', False,u'')) self.bAutoHide = GetXMLBoolAttribute(oXMLNode=oXMLNode, uTag=u'autohide', bMandatory=False, bDefault=False) if self.bAutoHide: if self.uCaption == u'': self.EnableWidget(bEnable=False) if not self.oFnButtonPictureNormal.string.rfind('*') == -1: if self.oFnButtonPicturePressed.IsEmpty(): self.oFnButtonPicturePressed.ImportFullPath( uFnFullName=self.oFnButtonPictureNormal.string.replace( u'*', u' pressed')) self.oFnButtonPictureNormal.ImportFullPath( uFnFullName=self.oFnButtonPictureNormal.string.replace( u'*', u' normal')) return bRet
def InitWidgetFromXml(self, oXMLNode, oParentScreenPage, uAnchor): uCaption = GetXMLTextAttribute(oXMLNode, "caption", False, "") bRet = super(cWidgetDropDown, self).InitWidgetFromXml(oXMLNode, oParentScreenPage, uAnchor) oXMLNode.set("caption", uCaption) if bRet: self.tFrameColor = GetColorFromHex( GetXMLTextAttribute(oXMLNode, u'framecolor', False, u'$var(dimmed)')) self.iFrameWidth = GetXMLIntAttribute( oXMLNode, u'framewidth', False, self.oDef.iDefMaxX / self.fRationX) * 0.02 self.aCaptions = GetXMLTextAttribute(oXMLNode, u'captions', False, u'unknown').split(u',') self.aActionNames = GetXMLTextAttribute(oXMLNode, u'actions', False, u'').split(u',') self.aOrgActionNames = copy(self.aActionNames) self.bSorted = GetXMLBoolAttribute(oXMLNode, u'sorted', False, False) self.oXMLNode = oXMLNode # this is a little bit tricky # we should parse all dropdown button here as well, but then, # updatewidget for the dropdown would not work # so we do it in create, but at that time, the dimensions of the achor is losr # so, we need to save the anchor dimensions here self.iTmpAnchorWidth = self.oTmpAnchor.iWidth self.iTmpAnchorHeight = self.oTmpAnchor.iHeight return bRet
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)
def InitWidgetFromXml(self,oXMLNode,oParentScreenPage, uAnchor): """ Reads further Widget attributes from a xml node """ bRet=self.ParseXMLBaseNode(oXMLNode,oParentScreenPage , uAnchor) if bRet: self.SetPictureNormal (GetXMLTextAttribute(oXMLNode,u'picturenormal', False,u'')) self.SetPicturePressed (GetXMLTextAttribute(oXMLNode,u'picturepressed', False,u'')) #self.SetPictureDisabled (GetXMLTextAttribute(oXMLNode,u'picturedisabled', False,u'')) self.bAutoHide = GetXMLBoolAttribute(oXMLNode,u'autohide',False,False) if self.bAutoHide: if self.uCaption == u'': self.bEnabled = False if not self.oFnButtonPictureNormal.string.rfind('*')==-1: if self.oFnButtonPicturePressed.IsEmpty(): self.oFnButtonPicturePressed.ImportFullPath(self.oFnButtonPictureNormal.string.replace(u'*',u' pressed')) self.oFnButtonPictureNormal.ImportFullPath(self.oFnButtonPictureNormal.string.replace(u'*',u' normal')) return bRet
def __GetUsedDefinitions_Sub(self, uDefinitionName, bImportActions, bImportLanguages, bImportPages, bImportSettings, uParentDefinitionName, uParentDefinitionAlias, aDefinitionVarsFromParent, uAlias): aAdditionalDefVars = {} if not uAlias in self.dDefinitionList_Dict: oDefinitionPathes = cDefinitionPathes(uDefinitionName) SetVar(uVarName="DEFINITIONPATH[%s]" % (uDefinitionName), oVarValue=oDefinitionPathes.oPathDefinition.string) SetVar( uVarName="DEFINITIONPATHSKINELEMENTS[%s]" % (uDefinitionName), oVarValue=oDefinitionPathes.oPathDefinitionSkinElements.string) Globals.dDefinitionPathes[uDefinitionName] = oDefinitionPathes SetDefinitionPathes(uDefinitionName) oFnDefinition = Globals.oDefinitionPathes.oFnDefinition Logger.debug(u'TheScreen: Load Definition XmlFile:' + oFnDefinition) oDefinition = cDefinition(uDefinitionName, self) oDefinition.uParentDefinitionName = uParentDefinitionName oDefinition.bImportActions = bImportActions oDefinition.bImportLanguages = bImportLanguages oDefinition.bImportPages = bImportPages oDefinition.bImportSettings = bImportSettings oDefinition.oDefinitionVarsFromParent = aDefinitionVarsFromParent #we read the definitionvars first with raw funtions sET_Data = CachedFile(Globals.oDefinitionPathes.oFnDefinition) oET_Root = fromstring(sET_Data) oRef = oET_Root.find('def_parameter') # And merge / Replace the existing Vars oDefinition.oDefinitionVars.clear() oDefinition.oDefinitionVars.update( ToOrderedDic( GetXMLTextValue(oRef, u'definitionvars', False, u'{}'))) if len(aDefinitionVarsFromParent) > 0: for uVarName in oDefinition.oDefinitionVars: if uVarName in oDefinition.oDefinitionVarsFromParent: oDefinition.oDefinitionVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] else: Logger.warning( "Importing definition %s from %s: Definition varname not passed: '%s', using default %s" % (oDefinition.uName, uParentDefinitionName, uVarName, oDefinition.oDefinitionVars[uVarName])) for uVarName in aDefinitionVarsFromParent: if not uVarName in oDefinition.oDefinitionVars: oDefinition.oDefinitionVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] aAdditionalDefVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] for uKey in oDefinition.oDefinitionVars: uVar = oDefinition.oDefinitionVars[uKey] if "$cookie(" in uVar: uValue = GetCookieValue(uVar) oDefinition.oDefinitionVars[uKey] = uValue if uAlias == u'': # this works on all python versions for uKey in oDefinition.oDefinitionVars: uAlias = oDefinition.oDefinitionVars[uKey] break if uAlias == '': uAlias = uDefinitionName oDefinition.uDefPublicTitle = uDefinitionName #create a default alias def var uAliasDefVar = "definition_alias_" + uAlias if oDefinition.oDefinitionVars.get(uAliasDefVar) is None: SetDefVar(uVarName=uAliasDefVar, uVarValue=uAlias, dArray=oDefinition.oDefinitionVars) else: oDefinition.uDefPublicTitle = "%s [%s]" % (uAlias, uDefinitionName) oDefinition.uAlias = uAlias if not uAlias in self.dDefinitionList_Dict: # create defvars for import pages aTmpDefinitionVars = copy(oDefinition.oDefinitionVars) for uVar in aTmpDefinitionVars: if not uVar.endswith("_IMPORTPAGES"): if bImportPages: SetDefVar(uVarName=uVar + "_IMPORTPAGES", uVarValue="1", dArray=oDefinition.oDefinitionVars) else: SetDefVar(uVarName=uVar + "_IMPORTPAGES", uVarValue="0", dArray=oDefinition.oDefinitionVars) #and now again with adjusted definitionvars oET_Root = Orca_FromString(sET_Data, oDefinition, "root") oDefinition.oET_Root = oET_Root oDefinition.sET_Data = sET_Data self.AddDefinition(oDefinition) oXMLIncludes = oET_Root.find('definitionimports') if oXMLIncludes is not None: for oXMLInclude in oXMLIncludes.findall('definition'): uDefinitionNameImp = GetXMLTextValue( oXMLInclude, u'', True, '') bImportActionsImp = GetXMLBoolAttribute( oXMLInclude, u'importactions', False, False) bImportLanguagesImp = GetXMLBoolAttribute( oXMLInclude, u'importlanguages', False, False) bImportPagesImp = GetXMLBoolAttribute( oXMLInclude, u'importpages', False, False) bImportSettingsImp = GetXMLBoolAttribute( oXMLInclude, u'importsettings', False, False) uAliasImp = GetXMLTextAttribute( oXMLInclude, u'alias', False, '') aDefinitionVarsImp = cDefinitionVars() aDefinitionVarsImp.update( ToDic( GetXMLTextAttribute(oXMLInclude, u'definitionvars', False, {}))) # Pass Through of additional Definitionvars for uVarName in aAdditionalDefVars: if not uVarName in aDefinitionVarsImp: aDefinitionVarsImp[ uVarName] = aAdditionalDefVars[uVarName] self.__GetUsedDefinitions_Sub( uDefinitionNameImp, bImportActionsImp, bImportLanguagesImp, bImportPagesImp, bImportSettingsImp, oDefinition.uName, oDefinition.uAlias, aDefinitionVarsImp, uAliasImp) else: Logger.debug( u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' % (uAlias, uDefinitionName)) else: Logger.debug( u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' % (uAlias, uDefinitionName))
def InitWidgetFromXml(self,*,oXMLNode:Element,oParentScreenPage:cScreenPage, uAnchor:str) -> bool: """ Reads further Widget attributes from a xml node """ self.oPathStart = cPath(GetVar(uVarName = "filebrowserfile")) self.uActionNameCancel = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'actioncancel',bMandatory=False,vDefault=u'') self.bDirSelect = GetXMLBoolAttribute(oXMLNode=oXMLNode,uTag=u'dirselect', bMandatory=False,bDefault=False) return self.ParseXMLBaseNode(oXMLNode,oParentScreenPage , uAnchor)
def ParseXMLBaseNode(self, oXMLNode: Element, oParentScreenPage: cScreenPage, uAnchor: str) -> bool: uDefinitionContext: str uAlias: str oDef: Union[cDefinition, None] iAnchorWidth: int iAnchorHeight: int bApplyWidth: bool fVar: float i: int bAnchorEnabled: bool = True global uContainerContext try: global oLastWidget self.GetWidgetTypeFromXmlNode(oXMLNode) self.uFileName = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'linefilename', bMandatory=False, vDefault="unknown file") self.uFileNames = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'linefilenames', bMandatory=False, vDefault="Unknown File") uDefinitionContext = GetXMLTextAttribute( oXMLNode=oXMLNode, uTag=u'definitioncontext', bMandatory=False, vDefault=Globals.uDefinitionContext) uAlias = oXMLNode.get('definitionalias') oDef = None if uAlias is not None: oDef = Globals.oDefinitions[uAlias] self.oDef = oDef self.uDefinitionContext = uDefinitionContext self.uName = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'name', bMandatory=True, vDefault=u'NoName') self.oParentScreenPage = oParentScreenPage self.uPageName = self.oParentScreenPage.uPageName #default anchor is screen self.iAnchorPosX = 0 self.iAnchorPosY = 0 self.iAnchorWidth = self.oDef.iDefMaxX self.iAnchorHeight = self.oDef.iDefMaxY self.iGapX = oDef.iGapX self.iGapY = oDef.iGapY self.fRationX = oDef.fRationX self.fRationY = oDef.fRationY self.uAnchorName = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'anchor', bMandatory=False, vDefault=u'') if self.uAnchorName == u'': self.uAnchorName = uAnchor if self.uAnchorName: # we use only the last Anchor with that name aTmpAnchors = self.oParentScreenPage.dWidgets[self.uAnchorName] if aTmpAnchors: self.oTmpAnchor = aTmpAnchors[-1] # oTmpAnchor is already aligned to screen size self.iAnchorPosX = self.oTmpAnchor.iPosX self.iAnchorPosY = self.oTmpAnchor.iPosY self.iAnchorWidth = self.oTmpAnchor.iWidth self.iAnchorHeight = self.oTmpAnchor.iHeight bAnchorEnabled = self.oTmpAnchor.bIsEnabled else: self.oTmpAnchor = None # We parse for Text and change later to integer uWidth = ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'width', bMandatory=False, vDefault=u'')) uHeight = ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'height', bMandatory=False, vDefault=u'')) iAnchorWidth = self.iAnchorWidth iAnchorHeight = self.iAnchorHeight self.iWidth, bApplyWidth = self.CalculateWidth( uWidth, iAnchorWidth) self.iHeight = self.CalculateHeight(uHeight, iAnchorHeight) if bApplyWidth: self.iWidth = self._ParseDimPosValue(uWidth) self.bIsEnabled = GetXMLBoolAttribute(oXMLNode=oXMLNode, uTag=u'enabled', bMandatory=False, bDefault=bAnchorEnabled) self.uContainer = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'container', bMandatory=False, vDefault=u'') if (self.eWidgetType == eWidgetType.ScrollContainer or self.eWidgetType == eWidgetType.ScrollList) and self.uContainer == u'': self.uContainer = ''.join( random.choice(string.ascii_lowercase) + str(i) for i in range(20)) if self.uContainer == u'': self.uContainer = uContainerContext self.uBackGroundColor = GetXMLTextAttribute( oXMLNode=oXMLNode, uTag=u'backgroundcolor', bMandatory=False, vDefault=u'#00000000') self.aBackGroundColor = GetColorFromHex( ReplaceVars(self.uBackGroundColor)) uPosY: str = ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'posy', bMandatory=False, vDefault=u'top')) self.iPosY = self.CalculatePosY(uPosY) uPosX: str = ReplaceVars( GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'posx', bMandatory=False, vDefault=u'left')) self.iPosX = self.CalculatePosX(uPosX) self.uInterFace = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'interface', bMandatory=False, vDefault=u'') self.uConfigName = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'configname', bMandatory=False, vDefault=u'') if oLastWidget: self.uLastWidgetID = oLastWidget.uID if not hasattr(self, 'bIsDropButton'): oLastWidget = self self.iPosXInit = self.iPosX self.iPosYInit = self.iPosY self.iWidthInit = self.iWidth self.iHeightInit = self.iHeight return super().ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor) except Exception as e: LogError(uMsg=u'Error parsing widget from element:[%s] [%s]' % (self.uName, self.uFileNames), oException=e, bTrackStack=True) return False
def InitWidgetFromXml(self,oXMLNode,oParentScreenPage, sAnchor): """ Reads further Widget attributes from a xml node """ self.bIsClock = GetXMLBoolAttribute(oXMLNode,u'clock', False,False) self.bIsDate = GetXMLBoolAttribute(oXMLNode,u'date', False,False) return self.ParseXMLBaseNode(oXMLNode,oParentScreenPage , sAnchor)
def ParseXMLBaseNode (self,oXMLNode:Element,oParentScreenPage:cScreenPage, uAnchor:str) -> bool: try: super().ParseXMLBaseNode(oXMLNode, oParentScreenPage, uAnchor) self.uCaption = u'' self.uhTextAlign = GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'htextalign', bMandatory=False, vDefault=u'center') self.uvTextAlign = GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'vtextalign', bMandatory=False, vDefault=u'middle') self.bShorten = GetXMLBoolAttribute (oXMLNode=oXMLNode,uTag=u'shorten', bMandatory=False, bDefault=False) self.bBold = GetXMLBoolAttribute (oXMLNode=oXMLNode,uTag=u'bold', bMandatory=False, bDefault=False) self.bItalic = GetXMLBoolAttribute (oXMLNode=oXMLNode,uTag=u'italic', bMandatory=False, bDefault=False) self.iLines = GetXMLIntAttribute (oXMLNode=oXMLNode,uTag=u'lines', bMandatory=False, iDefault=0) self.uFontIndex = GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'fontid', bMandatory=False, vDefault=self.oDef.uDefaultFont) self.uOrgFontIndex = self.uFontIndex uFontSize:str = GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'fontsize', bMandatory=False, vDefault='0') uIconFontSize:str = GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'iconfontsize', bMandatory=False, vDefault=uFontSize) self.aTextColor = GetColorFromHex(GetXMLTextAttribute (oXMLNode=oXMLNode,uTag=u'textcolor',bMandatory=False, vDefault=uColorUndefined)) self.SetCaption(GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'caption', bMandatory=False, vDefault=u'')) self.uOrgSecondCaption = GetXMLTextAttribute(oXMLNode=oXMLNode,uTag=u'secondcaption', bMandatory=False, vDefault=u'') Globals.oTheScreen.oFonts.dUsedFonts[self.uFontIndex]=True if self.aTextColor == aColorUndefined: if self.eWidgetType == eWidgetType.Button or self.eWidgetType == eWidgetType.DropDown or self.eWidgetType == eWidgetType.Switch: self.aTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get('color font button') elif self.eWidgetType == eWidgetType.TextField or self.eWidgetType == eWidgetType.TextInput or self.eWidgetType == eWidgetType.Slider: self.aTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get('color font text') elif self.eWidgetType == eWidgetType.FileViewer or self.eWidgetType == eWidgetType.Settings: self.aTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get('color font file') elif self.eWidgetType == eWidgetType.BackGround: self.aTextColor = GetColorFromHex(u'#FFFFFFFF') if self.aTextColor == aColorUndefined: self.aTextColor = GetColorFromHex(u'#FFFFFFFF') if uFontSize == "0": if self.eWidgetType == eWidgetType.Button or self.eWidgetType == eWidgetType.DropDown or self.eWidgetType == eWidgetType.Switch: uFontSize = self.oDef.uFontSize_Button elif self.eWidgetType == eWidgetType.TextField or self.eWidgetType == eWidgetType.TextInput or self.eWidgetType == eWidgetType.Slider: uFontSize = self.oDef.uFontSize_Text elif self.eWidgetType == eWidgetType.FileViewer or self.eWidgetType == eWidgetType.Settings: uFontSize = self.oDef.uFontSize_File if uIconFontSize == "0": if self.eWidgetType == eWidgetType.Button or self.eWidgetType == eWidgetType.DropDown or self.eWidgetType == eWidgetType.Switch: uIconFontSize = self.oDef.uFontSize_Button elif self.eWidgetType == eWidgetType.TextField or self.eWidgetType == eWidgetType.TextInput or self.eWidgetType == eWidgetType.Slider: uIconFontSize = self.oDef.uFontSize_Text elif self.eWidgetType == eWidgetType.FileViewer or self.eWidgetType == eWidgetType.Settings: uIconFontSize = self.oDef.uFontSize_File # todo: check where to scale fonts if uFontSize[0] == u'd': self.iFontSize = dp(uFontSize[1:]) *self.fRationX elif uFontSize[0] == u's': self.iFontSize = sp(uFontSize[1:]) *self.fRationX elif uFontSize.startswith(u'%h'): self.iFontSize = ((int(uFontSize[2:])*self.iHeight)/100) # *self.fRationY elif uFontSize.startswith(u'%w'): self.iFontSize = ((int(uFontSize[2:])*self.iWidth)/100) # *self.fRationX else: self.iFontSize = ToInt(uFontSize) if self.iFontSize != 0: Logger.warning("Depreciated absolute fontsize used:"+self.uName+ " from:"+self.uPageName) if uIconFontSize[0] == u'd': self.iIconFontSize = dp(uIconFontSize[1:]) *self.fRationX elif uIconFontSize[0] == u's': self.iIconFontSize = sp(uIconFontSize[1:]) *self.fRationX elif uIconFontSize.startswith(u'%h'): self.iIconFontSize = ((int(uIconFontSize[2:])*self.iHeight)/100) # *self.fRationY elif uIconFontSize.startswith(u'%w'): self.iIconFontSize = ((int(uIconFontSize[2:])*self.iWidth)/100) # *self.fRationX else: self.iIconFontSize = ToInt(uIconFontSize) if self.iIconFontSize != 0: Logger.warning("Depreciated absolute fontsize used:"+self.uName+ " from:"+self.uPageName) self.iFontSizeInit = self.iFontSize return True except Exception as e: LogError(uMsg=u'Error parsing widget from element (Text):['+self.uName+"",oException=e) return False
def ParseXMLBaseNode(self, oXMLNode, oParentScreenPage, uAnchor): try: global oLastWidget self.GetWidgetTypeFromXmlNode(oXMLNode) uDefinitionContext = GetXMLTextAttribute( oXMLNode, u'definitioncontext', False, Globals.uDefinitionContext) uAlias = oXMLNode.get('definitionalias') oDef = None if uAlias is not None: oDef = Globals.oDefinitions.dDefinitionList_Dict[uAlias] self.oDef = oDef self.uDefinitionContext = uDefinitionContext self.uName = GetXMLTextAttribute(oXMLNode, u'name', True, u'NoName') self.oParentScreenPage = oParentScreenPage self.uPageName = self.oParentScreenPage.uPageName #default anchor is screen self.iAnchorPosX = 0 self.iAnchorPosY = 0 self.iAnchorWidth = self.oDef.iDefMaxX self.iAnchorHeight = self.oDef.iDefMaxY self.iGapX = oDef.iGapX self.iGapY = oDef.iGapY self.fRationX = oDef.fRationX self.fRationY = oDef.fRationY self.uAnchorName = GetXMLTextAttribute(oXMLNode, u'anchor', False, u'') if self.uAnchorName == u'': self.uAnchorName = uAnchor if self.uAnchorName: self.oTmpAnchor = self.oParentScreenPage.dWidgets.get( self.uAnchorName) if self.oTmpAnchor is not None: # oTmpAnchor is already aligned to screen size self.iAnchorPosX = self.oTmpAnchor.iPosX self.iAnchorPosY = self.oTmpAnchor.iPosY self.iAnchorWidth = self.oTmpAnchor.iWidth self.iAnchorHeight = self.oTmpAnchor.iHeight # We parse for Text and change later to integer self.iWidth = ReplaceVars( GetXMLTextAttribute(oXMLNode, u'width', False, u'')) self.iHeight = ReplaceVars( GetXMLTextAttribute(oXMLNode, u'height', False, u'')) iAnchorWidth = (self.iAnchorWidth) iAnchorHeight = (self.iAnchorHeight) bApplyWidth = False if self.iWidth == u'': self.iWidth = iAnchorWidth elif self.iWidth.startswith('of:height:self'): bApplyWidth = True elif self.iWidth.startswith('of:toleft'): bApplyWidth = True elif self.iWidth.startswith('of:'): self.iWidth = self._ParseDimPosValue(self.iWidth) elif self.iWidth[0] == u'%': fPercentage = float(self.iWidth[1:]) self.iWidth = ((fPercentage / 100) * iAnchorWidth) elif self.iWidth[0] == u'd': # we define: First Value is dp value, # second value is absolute value (unscaled) # eg d20:50 would result either d20 or 50, whatever is larger tTmp = SplitMax(self.iWidth[1:]) if tTmp[1] == 0: uVar = dp(tTmp[0]) else: uVar = max(dp(tTmp[0]), tTmp[1]) self.iWidth = uVar else: #Logger.warning("Depriciated absolute width used:"+self.uName+ " from:"+self.uPageName) self.iWidth = int(self.iWidth) if self.iHeight == u'': self.iHeight = iAnchorHeight elif self.iHeight[0] == u'%': fPercentage = float(self.iHeight[1:]) self.iHeight = ((fPercentage / 100) * iAnchorHeight) elif self.iHeight.startswith('of:'): if not bApplyWidth: self.iHeight = self._ParseDimPosValue(self.iHeight) else: self.iHeight = self._ParseDimPosValue(self.iHeight) elif self.iHeight[0] == u'd': # we define: First Value is dp value, # second value is absolute value (unscaled) tTmp = SplitMax(self.iHeight[1:]) if tTmp[1] == 0: uVar = dp(tTmp[0]) else: uVar = max(dp(tTmp[0]), tTmp[1]) self.iHeight = uVar else: #Logger.warning("Depriciated absolute height used:"+self.uName+ " from:"+self.uPageName) self.iHeight = int(self.iHeight) if bApplyWidth: self.iWidth = self._ParseDimPosValue(self.iWidth) #We parse for Text and change later to integer self.iPosX = ReplaceVars( GetXMLTextAttribute(oXMLNode, u'posx', False, u'left')) self.iPosY = ReplaceVars( GetXMLTextAttribute(oXMLNode, u'posy', False, u'top')) self.bEnabled = GetXMLBoolAttribute(oXMLNode, u'enabled', False, True) self.uCaption = u'' self.uBackGroundColor = GetXMLTextAttribute( oXMLNode, u'backgroundcolor', False, u'#00000000') self.tBackGroundColor = GetColorFromHex( ReplaceVars(self.uBackGroundColor)) self.uActionName = GetXMLTextAttribute(oXMLNode, u'action', False, u'') self.uActionNameDoubleTap = GetXMLTextAttribute( oXMLNode, u'actiondoubletap', False, u'') self.uActionNameLongTap = GetXMLTextAttribute( oXMLNode, u'actionlongtap', False, u'') self.uActionNameDownOnly = GetXMLTextAttribute( oXMLNode, u'actiondownonly', False, u'') self.uActionNameUpOnly = GetXMLTextAttribute( oXMLNode, u'actionuponly', False, u'') self.uInterFace = GetXMLTextAttribute(oXMLNode, u'interface', False, u'') self.uConfigName = GetXMLTextAttribute(oXMLNode, u'configname', False, u'') uActionPars = GetXMLTextAttribute(oXMLNode, u'actionpars', False, u'{}') if uActionPars.startswith("$var("): uActionPars = ReplaceVars(uActionPars) self.dActionPars = ToDic(uActionPars) if self.uActionName.startswith("SendCommand "): if len(self.dActionPars) == 0: self.dActionPars = {"commandname": self.uActionName[12:]} self.uActionName = "Send" if not self.uInterFace == u'': Globals.oInterFaces.dUsedInterfaces[self.uInterFace] = True fPercentage = -1.0 if not self.iPosY == u'': if self.iPosY == u'bottom': fPercentage = 100.0 elif self.iPosY.startswith('of:'): self.iPosY = self._ParseDimPosValue(self.iPosY) elif self.iPosY == u'top': fPercentage = 0.0 elif self.iPosY == u'middle': fPercentage = 50.0 elif self.iPosY.isdigit(): Logger.warning("Depriciated absolute PosY used:" + self.uName + " from:" + self.uPageName) self.iPosY = (int(self.iPosY) + self.iAnchorPosY) elif self.iPosY[0] == u'%': fPercentage = float(self.iPosY[1:]) elif self.iPosY[0] == u'd': self.iPosY = dp(float(self.iPosY[1:])) + self.iAnchorPosY self.iPosY = Globals.iAppHeight - self.iHeight - self.iPosY elif self.iPosY[0] == u's': self.iPosY = sp(float(self.iPosY[1:])) + self.iAnchorPosY self.iPosY = Globals.iAppHeight - self.iHeight - self.iPosY else: LogError(u'WidgetBase: Fatal Error:Wrong ypos:' + self.uName) self.iPosY = 0 if not fPercentage == -1.0: self.iPosY = self.iAnchorPosY + ( (fPercentage / 100) * self.iAnchorHeight) - (self.iHeight * (fPercentage / 100)) fPercentage = -1.0 if not self.iPosX == u'': if self.iPosX == u'right': fPercentage = 100.0 elif self.iPosX.startswith('of:'): self.iPosX = self._ParseDimPosValue(self.iPosX) elif self.iPosX == u'left': fPercentage = 0.0 elif self.iPosX == u'center': fPercentage = 50.0 elif self.iPosX.isdigit(): Logger.warning("Depriciated absolute PosX used:" + self.uName + " from:" + self.uPageName) self.iPosX = (int(self.iPosX)) + self.iAnchorPosX elif self.iPosX[0] == u'%': fPercentage = float(self.iPosX[1:]) elif self.iPosX[0] == u'd': self.iPosX = dp(float(self.iPosX[1:])) + self.iAnchorPosX elif self.iPosX[0] == u's': self.iPosX = sp(float(self.iPosX[1:])) + self.iAnchorPosX else: LogError(u'WidgetBase: Fatal Error:Wrong xpos:' + self.uName + " " + str(self.iPosX)) self.iPosX = 0 if not fPercentage == -1.0: self.iPosX = self.iAnchorPosX + ( (fPercentage / 100) * self.iAnchorWidth) - (self.iWidth * (fPercentage / 100)) if self.bHasText: self.uhTextAlign = GetXMLTextAttribute(oXMLNode, u'htextalign', False, u'center') self.uvTextAlign = GetXMLTextAttribute(oXMLNode, u'vtextalign', False, u'middle') self.bBold = GetXMLBoolAttribute(oXMLNode, u'bold', False, False) self.bItalic = GetXMLBoolAttribute(oXMLNode, u'italic', False, False) self.uFontIndex = GetXMLTextAttribute(oXMLNode, u'fontid', False, oDef.uDefaultFont) self.uOrgFontIndex = self.uFontIndex sFontSize = GetXMLTextAttribute(oXMLNode, u'fontsize', False, '0') sIconFontSize = GetXMLTextAttribute(oXMLNode, u'iconfontsize', False, sFontSize) self.tTextColor = GetXMLTextAttribute(oXMLNode, u'textcolor', False, u'') self.SetCaption( GetXMLTextAttribute(oXMLNode, u'caption', False, u'')) self.uOrgSecondCaption = GetXMLTextAttribute( oXMLNode, u'secondcaption', False, u'') Globals.oTheScreen.oFonts.dUsedFonts[self.uFontIndex] = True if self.tTextColor == u'': if self.iWidgetType == oWidgetType.Button or self.iWidgetType == oWidgetType.DropDown or self.iWidgetType == oWidgetType.Switch: self.tTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get( 'fontcolor button') elif self.iWidgetType == oWidgetType.TextField or self.iWidgetType == oWidgetType.TextInput or self.iWidgetType == oWidgetType.Slider: self.tTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get( 'fontcolor text') elif self.iWidgetType == oWidgetType.FileViewer or self.iWidgetType == oWidgetType.Settings: self.tTextColor = Globals.oTheScreen.oSkin.dSkinAttributes.get( 'fontcolor file') elif self.iWidgetType == oWidgetType.BackGround: self.tTextColor = GetColorFromHex(u'#FFFFFFFF') if self.tTextColor is None or self.tTextColor == u'': self.tTextColor = GetColorFromHex(u'#FFFFFFFF') else: self.tTextColor = GetColorFromHex(self.tTextColor) if sFontSize == "0": if self.iWidgetType == oWidgetType.Button or self.iWidgetType == oWidgetType.DropDown or self.iWidgetType == oWidgetType.Switch: sFontSize = str(oDef.iFontSize_Button) elif self.iWidgetType == oWidgetType.TextField or self.iWidgetType == oWidgetType.TextInput or self.iWidgetType == oWidgetType.Slider: sFontSize = str(oDef.iFontSize_Text) elif self.iWidgetType == oWidgetType.FileViewer or self.iWidgetType == oWidgetType.Settings: sFontSize = str(oDef.iFontSize_File) if sIconFontSize == "0": if self.iWidgetType == oWidgetType.Button or self.iWidgetType == oWidgetType.DropDown or self.iWidgetType == oWidgetType.Switch: sIconFontSize = str(oDef.iFontSize_Button) elif self.iWidgetType == oWidgetType.TextField or self.iWidgetType == oWidgetType.TextInput or self.iWidgetType == oWidgetType.Slider: sIconFontSize = str(oDef.iFontSize_Text) elif self.iWidgetType == oWidgetType.FileViewer or self.iWidgetType == oWidgetType.Settings: sIconFontSize = str(oDef.iFontSize_File) # todo: check where to scale fonts if sFontSize[0] == u'd': self.iFontSize = dp(sFontSize[1:]) * self.fRationX elif sFontSize[0] == u's': self.iFontSize = sp(sFontSize[1:]) * self.fRationX elif sFontSize.startswith(u'%h'): self.iFontSize = ((int(sFontSize[2:]) * self.iHeight) / 100 ) # *self.fRationY elif sFontSize.startswith(u'%w'): self.iFontSize = ((int(sFontSize[2:]) * self.iWidth) / 100 ) # *self.fRationX else: self.iFontSize = ToInt(sFontSize) if self.iFontSize != 0: Logger.warning("Depriciated absolute fontsize used:" + self.uName + " from:" + self.uPageName) if sIconFontSize[0] == u'd': self.iIconFontSize = dp(sIconFontSize[1:]) * self.fRationX elif sIconFontSize[0] == u's': self.iIconFontSize = sp(sIconFontSize[1:]) * self.fRationX elif sIconFontSize.startswith(u'%h'): self.iIconFontSize = ( (int(sIconFontSize[2:]) * self.iHeight) / 100 ) # *self.fRationY elif sIconFontSize.startswith(u'%w'): self.iIconFontSize = ( (int(sIconFontSize[2:]) * self.iWidth) / 100 ) # *self.fRationX else: self.iIconFontSize = ToInt(sIconFontSize) if self.iIconFontSize != 0: Logger.warning("Depriciated absolute fontsize used:" + self.uName + " from:" + self.uPageName) if not hasattr(self, 'bIsDropButton'): oLastWidget = self self.iPosXInit = self.iPosX self.iPosYInit = self.iPosY self.iWidthInit = self.iWidth self.iHeightInit = self.iHeight self.iFontSizeInit = self.iFontSize return True except Exception as e: LogError(u'Error parsing widget from element:[' + self.uName + "", e) return False