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 SetWidgetColor(self, sBackgroundColor: str) -> bool: sColor = ReplaceVars(sBackgroundColor) self.uBackGroundColor = sColor self.aBackGroundColor = GetColorFromHex(sColor) if self.oObject: self.oObject.background_color = self.aBackGroundColor return True
def SetWidgetFontStyle(self,bBold:Union[bool,None],bItalic:Union[bool,None],uColor:Union[str,None]) -> bool: super().SetWidgetFontStyle(bBold,bItalic,uColor) if bBold is not None: self.bBold = bBold if self.oObject: self.oObject.bold = self.bBold if bItalic is not None: self.bItalic = bItalic if self.oObject: self.oObject.italic = self.bItalic if uColor is not None: self.aTextColor = GetColorFromHex(uColor) if self.oObject: self.oObject.color = self.aTextColor return True
def HandleIcon(self, oWidget:Union[cWidgetBase,None] = None) -> None: if oWidget is None: oWidget = self uIcon = oWidget.uCaption[5:] iPos = uIcon.find(' color:') if iPos > 0: uColor = uIcon[iPos + 7:] uIcon = uIcon[:iPos] oWidget.aTextColor = GetColorFromHex(uColor) dIcon = Globals.dIcons.get(uIcon) if dIcon: oWidget.uCaption = dIcon["char"] if dIcon["fontname"]: oWidget.uFontIndex = dIcon["fontname"] self.bIcon = True oWidget.fScale = dIcon["scale"]
def UpdateWidget(self) -> None: uH: str uS: str uV: str uR: str uG: str uB: str h: float s: float v: float r: float b: float g: float a: float = 1.0 if not self.uDestVar == u'': uH = GetVar(uVarName=self.uDestVar + u'_h') uS = GetVar(uVarName=self.uDestVar + u'_s') uV = GetVar(uVarName=self.uDestVar + u'_v') if uH != '': h = ToFloat(uH) / 255 s = ToFloat(uS) / 255 v = ToFloat(uV) / 255 r, g, b = hsv_to_rgb(h, s, v) else: uR = GetVar(uVarName=self.uDestVar + u'_r') uG = GetVar(uVarName=self.uDestVar + u'_g') uB = GetVar(uVarName=self.uDestVar + u'_b') if uR == '': r, g, b, a = GetColorFromHex( GetVar(uVarName=self.uDestVar)) else: r = ToFloat(uR) / 255 g = ToFloat(uG) / 255 b = ToFloat(uB) / 255 self.oObjectColorPicker.color = (r, g, b, a)
def __init__(self,**kwargs): super().__init__(**kwargs) self.bBold:bool = False self.bShorten:bool = False self.bItalic:bool = False self.bIcon:bool = False self.bNoTextSize:bool = False self.dActionPars:Dict[str,str] = {} # Actionpars will be passed to Actions within command set, existing pars will be replaced! self.dKwArgs:Dict = {} self.iFontSize:int = 30 self.iIconFontSize:int = 50 self.iFontSizeInit:int = 30 self.iLines:int = 0 self.aTextColor:List[float] = GetColorFromHex('#FFFFFFFF') self.uFontIndex:str = u'Sans' self.uhTextAlign:str = u'center' self.uOrgCaption:str = u'' self.uOrgSecondCaption:str = u'' self.uOrgFontIndex:str = self.uFontIndex self.uSecondCaption:str = u'' self.uvTextAlign:str = u'top' self.uCaption:str = u''
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 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