def LoadFurtherXmlFile(self, oFnXml): # Loads pages from a further XML File sET_Data = CachedFile(oFnXml) sET_Data = ReplaceDefVars(sET_Data, self.oDefinitionVars) oET_Root = Orca_FromString(sET_Data, self, oFnXml.string) Orca_include(oET_Root, orca_et_loader) if self.bImportPages: # get a list of all pages and add Them oXMLPages = oET_Root.find('pages') for oXMLPage in oXMLPages.findall('page'): Globals.oTheScreen.oScreenPages.AddPageFromXmlNode(oXMLPage)
def LoadActions(self): """ parses the definition specific actions """ Logger.info (u'Loading Actions for script:'+self.uScriptName) if self.oFnAction.Exists(): sET_Data = CachedFile(self.oFnAction) oET_Root = Orca_FromString(sET_Data, None, self.oFnAction.string) Globals.oActions.LoadActionsSub(oET_Root,u'actions', u'action', Globals.oActions.dActionsCommands, self.oFnAction.string)
def LoadParameter(self): """ Loads the Parameter from the definition XML File """ Logger.info( u'Load Definition Parameter [%s] %s:' % (self.uAlias, self.oDefinitionPathes.oPathDefinition.string)) oET_Root = self.oET_Root #Get Definition Wide Setting oRef = oET_Root.find('def_parameter') self.iFontSize_Button = GetXMLTextValue(oRef, u'fontsize_button', False, '%h100') self.iFontSize_Text = GetXMLTextValue(oRef, u'fontsize_text', False, '%h100') self.iFontSize_File = GetXMLTextValue(oRef, u'fontsize_file', False, 'd11') # we replace the custom definition vars and reparse the xml again self.sET_Data = ReplaceDefVars(self.sET_Data, self.oDefinitionVars) self.oET_Root = Orca_FromString(self.sET_Data, self, "root2") self.uDefaultFont = GetXMLTextValue( oRef, u'defaultfont', True, Globals.oTheScreen.oSkin.dSkinAttributes['defaultfont']) if not self.uDefaultFont: self.uDefaultFont = Globals.oTheScreen.oSkin.dSkinAttributes[ 'defaultfont'] if self.uName == Globals.uDefinitionName: self.oDefinitions.uDefinitionSupport = GetXMLTextValue( oRef, u'support', False, u'') uInstallationHint = GetXMLTextValue(oRef, u'installationhint', False, u'') if uInstallationHint != '': self.oDefinitions.dInstallationsHints[self.uName] = ( "[b][color=#FFFF00]" + self.uDefPublicTitle + u"[/color][/b]\n\n" + uInstallationHint + u"\n\n") if Globals.uStretchMode == "CENTER" or Globals.uStretchMode == "TOPLEFT": fRatio = float( float(Globals.iAppWidth) / float(Globals.iAppHeight)) / float( float(self.iDefMaxX) / float(self.iDefMaxY)) if fRatio < 1: fShouldHeight = float(Globals.iAppWidth) / ( float(self.iDefMaxX) / float(self.iDefMaxY)) self.fRationY = float(self.iDefMaxY) / fShouldHeight if Globals.uStretchMode == "CENTER": self.iGapY = int((( (Globals.iAppHeight * self.fRationX) - self.iDefMaxY) / self.fRationX) / 2) else: fShouldWidth = float(Globals.iAppHeight) / ( float(self.iDefMaxY) / float(self.iDefMaxX)) self.fRationX = float(self.iDefMaxX) / fShouldWidth if Globals.uStretchMode == "CENTER": self.iGapX = int((( (Globals.iAppWidth * self.fRationY) - self.iDefMaxX) / self.fRationY) / 2) return True
def LoadActions(self): """ parses the definition specific actions """ Logger.info(u'Loading Actions for definition:' + self.uDefPublicTitle) SetDefinitionContext(self.uName) if Globals.oFnAction.Exists(): sET_Data = CachedFile(Globals.oFnAction) sET_Data = ReplaceDefVars(sET_Data, self.oDefinitionVars) oET_Root = Orca_FromString(sET_Data, self, Globals.oFnAction.string) Orca_include(oET_Root, orca_et_loader) SetDefinitionContext(self.uName) Globals.oActions.LoadActionsSub(oET_Root, u'pagestartactions', u'pagestartaction', Globals.oActions.dActionsPageStart, Globals.oFnAction) Globals.oActions.LoadActionsSub(oET_Root, u'pagestartactions', u'pagestopaction', Globals.oActions.dActionsPageStop, Globals.oFnAction) Globals.oActions.LoadActionsSub(oET_Root, u'actions', u'action', Globals.oActions.dActionsCommands, Globals.oFnAction) SetVar(uVarName=u'ORCASTANDARDPAGESTARTACTIONSINCLUDED', oVarValue=u"1") SetVar(uVarName=u'ORCASTANDARDACTIONSINCLUDED', oVarValue=u"1") RestoreDefinitionContext() return
def ReplaceElement(self, uFnElement, uReplaceWidgetName, oDefinition): """ Replaces an element at runtime in a page: the page must not be initalized :param string uFnElement: FileName of element to load :param string uReplaceWidgetName: The Widgetname to be replaced :param cDefinition oDefinition: Target Definition :rtype: bool :return: True if successful, otherwise False """ uFnFile = '' try: uFnFile = (cFileName(u'').ImportFullPath(uFnElement)).string SetVar(uVarName='ORCA_INCLUDEFILE', oVarValue=uFnFile) if oDefinition is None: oDef = self.oWidgetBackGround.oDef else: oDef = oDefinition sET_Data = CachedFile(Globals.oFnElementIncludeWrapper) sET_Data = ReplaceDefVars(sET_Data, oDef.oDefinitionVars) oET_Root = Orca_FromString(sET_Data, oDef, uFnFile) Orca_include(oET_Root, orca_et_loader) self._ReplaceElements(oXMLNode=oET_Root, uReplaceWidgetName=uReplaceWidgetName) return True except Exception as e: uMsg = LogError( "Can''t load element (replace): %s (%s):" % (uFnElement, uFnFile), e) ShowErrorPopUp(uMessage=uMsg) return False
def LoadElement(self, uFnElement, uAnchor, oDefinition): """ Load an element at runtime to a page: the page must not be initalized :param string uFnElement: FileName of element to load :param string uAnchor: Target Anchor in Page to place the element into :param cDefinition oDefinition: Target Definition :rtype: bool :return: True if successful, otherwise False """ oFnElement = None try: oFnElement = cFileName('').ImportFullPath(uFnElement) SetVar(uVarName='ORCA_INCLUDEFILE', oVarValue=oFnElement.string) if oDefinition is None: oDef = self.oWidgetBackGround.oDef else: oDef = oDefinition sET_Data = CachedFile(Globals.oFnElementIncludeWrapper) sET_Data = ReplaceDefVars(sET_Data, oDef.oDefinitionVars) oET_Root = Orca_FromString(sET_Data, oDef, oFnElement.string) Orca_include(oET_Root, orca_et_loader) oWidget = self._AddElements(oXMLNode=oET_Root, uAnchor=uAnchor) if self.bIsInit: if oWidget is not None: oWidget.Create(self.oWidgetBackGround.oObject) return True except Exception as e: uMsg = LogError("Can''t load element: %s:" % oFnElement.string, e) ShowErrorPopUp(uMessage=uMsg) return False
def LoadXMLLanguageFont(self, oFnFile): iCountFonts = 0 try: sET_Data = CachedFile(oFnFile) oET_Root = Orca_FromString(sET_Data,None,oFnFile.string) iCountFonts = Globals.oTheScreen.oFonts.ParseFontFromXMLNode(oET_Root) Globals.oTheScreen.oFonts.ParseIconsFromXMLNode(oET_Root) except Exception as e: uMsg=LogError(u'Language: Fatal Error:Load Fonts from XmlFile:'+oFnFile.string,e) ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=False) return iCountFonts
def LoadActions(self) -> None: """ parses the definition specific actions """ Logger.info(u'Loading Actions for script:' + self.uObjectName) if self.oFnAction.Exists(): uET_Data = CachedFile(oFileName=self.oFnAction) oET_Root: Element = Orca_FromString( uET_Data=uET_Data, oDef=None, uFileName=self.oFnAction.string) Globals.oActions.LoadActionsSub( oET_Root=oET_Root, uSegmentTag=u'actions', uListTag=u'action', dTargetDic=Globals.oActions.dActionsCommands, uFileName=self.oFnAction.string)
def LoadXMLLanguageFont(self, oFnFile:cFileName) -> int: """ Loads the Font definitions from an xml file :param cFileName oFnFile: The filename of the xml font definition :return: The number of fonts loaded from the file """ iCountFonts:int = 0 try: uET_Data = CachedFile(oFileName=oFnFile) oET_Root:Element = Orca_FromString(uET_Data=uET_Data,oDef=None,uFileName=oFnFile.string) iCountFonts = Globals.oTheScreen.oFonts.ParseFontFromXMLNode(oXMLNode=oET_Root) Globals.oTheScreen.oFonts.ParseIconsFromXMLNode(oXMLNode=oET_Root) except Exception as e: uMsg:str=LogError(uMsg=u'Language: Fatal Error:Load Fonts from XmlFile:'+oFnFile.string,oException=e) ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=False) return iCountFonts
def ExecuteActionLoadActionFile(self,oAction:cAction) -> eReturnCode: """ loadactionfile: Load as specific action file Parameter: actionfilename: Full path to the action file """ self.oEventDispatcher.LogAction(uTxt=u'LoadActionFile',oAction=oAction) oFnAction:cFileName=cFileName().ImportFullPath(uFnFullName=oAction.dActionPars.get("actionfilename","")) if oFnAction.Exists(): uET_Data = CachedFile(oFileName=oFnAction) oET_Root:Element = Orca_FromString(uET_Data=uET_Data, oDef=None, uFileName=str(oFnAction)) Globals.oActions.LoadActionsSub(oET_Root=oET_Root,uSegmentTag=u'actions',uListTag=u'action',dTargetDic=Globals.oActions.dActionsCommands,uFileName=oFnAction.string) return eReturnCode.Nothing
def LoadFurtherXmlFile(self, *, oFnXml: cFileName) -> None: """ Loads pages from a further XML File :param cFileName oFnXml: The filename of the xml to load :return: None """ uET_Data = CachedFile(oFileName=oFnXml) uET_Data = ReplaceDefVars(uET_Data, self.oDefinitionVars) oET_Root: Element = Orca_FromString(uET_Data=uET_Data, oDef=self, uFileName=oFnXml.string) Orca_include(oET_Root, orca_et_loader) if self.bImportPages: # get a list of all pages and add Them oXMLPages: Element = oET_Root.find('pages') for oXMLPage in oXMLPages.findall('page'): Globals.oTheScreen.oScreenPages.AddPageFromXmlNode( oXMLPage=oXMLPage)
def _LoadXmlFile(self,oFnFile): """ Loads all strings for the language from a specific files""" if not oFnFile.Exists(): Logger.debug (u'Language: String File does not exist:'+oFnFile.string) return if oFnFile.string in self.aLoadedFiles: Logger.debug (u'Language: Skip duplicate language file loading:'+oFnFile.string) return oDef = None try: sET_Data = CachedFile(oFnFile) if Globals.uDefinitionContext: oDef = Globals.oDefinitions.get(Globals.uDefinitionContext) oET_Root = Orca_FromString(sET_Data,oDef,oFnFile.string) self.__LoadXMLNode(oET_Root,self.dIDToString) except ParseError as e: uMsg=LogError(u'Language: Fatal Error:Load Language XmlFile (xml parse error):'+oFnFile.string,e) ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=True) except Exception as e: uMsg=LogError(u'Language: Fatal Error:Load Language XmlFile (2):'+oFnFile.string,e) ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=True)
def LoadActions(self) -> None: """ parses the definition specific actions """ Logger.info(u'Loading Actions for definition:' + self.uDefPublicTitle) uET_Data: str SetDefinitionContext(uDefinitionName=self.uName) if Globals.oFnAction.Exists(): uET_Data = CachedFile(oFileName=Globals.oFnAction) uET_Data = ReplaceDefVars(uET_Data, self.oDefinitionVars) oET_Root: Element = Orca_FromString( uET_Data=uET_Data, oDef=self, uFileName=Globals.oFnAction.string) Orca_include(oET_Root, orca_et_loader) SetDefinitionContext(uDefinitionName=self.uName) Globals.oActions.LoadActionsSub( oET_Root=oET_Root, uSegmentTag=u'pagestartactions', uListTag=u'pagestartaction', dTargetDic=Globals.oActions.dActionsPageStart, uFileName=Globals.oFnAction) Globals.oActions.LoadActionsSub( oET_Root=oET_Root, uSegmentTag=u'pagestartactions', uListTag=u'pagestopaction', dTargetDic=Globals.oActions.dActionsPageStop, uFileName=Globals.oFnAction) Globals.oActions.LoadActionsSub( oET_Root=oET_Root, uSegmentTag=u'actions', uListTag=u'action', dTargetDic=Globals.oActions.dActionsCommands, uFileName=Globals.oFnAction) SetVar(uVarName=u'ORCASTANDARDPAGESTARTACTIONSINCLUDED', oVarValue=u"1") SetVar(uVarName=u'ORCASTANDARDACTIONSINCLUDED', oVarValue=u"1") RestoreDefinitionContext() return None
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 ReadCodeset(self) -> None: """ reads the codeset file """ oTmpCodeSetAction: cAction aTmpCodeSetAction: List[cAction] oCodesetFileName: cFileName = self.oInterFace.FindCodesetFile( self.aIniSettings.uFNCodeset) if oCodesetFileName is None: self.ShowDebug(uMsg=u'Cannot Read Codeset (Not Found):' + self.aIniSettings.uFNCodeset) return self.ShowDebug(uMsg=u'Read Codeset:' + oCodesetFileName) if oCodesetFileName.Exists(): uET_Data: str = CachedFile(oFileName=oCodesetFileName) oET_Root: Element = Orca_FromString( uET_Data=uET_Data, oDef=None, uFileName=oCodesetFileName.string) Orca_include(oET_Root, orca_et_loader) dTmpCodeSetActions: Dict[str, List[cAction]] = {} Globals.oActions.LoadActionsSub(oET_Root=oET_Root, uSegmentTag=u'', uListTag=u'action', dTargetDic=dTmpCodeSetActions, uFileName=oCodesetFileName.string) # replacing alias bDoItAgain: bool = True uKey: str = u'' uAlias: str = u'' try: # replace all alias while bDoItAgain: bDoItAgain = False try: for uKey in dTmpCodeSetActions: iPos: int = -1 for oTmpCodeSetAction in dTmpCodeSetActions[uKey]: iPos += 1 if oTmpCodeSetAction.dActionPars.get( 'type', '') == "alias": uAlias: str = oTmpCodeSetAction.dActionPars[ 'cmd'] aAliasCodeSet: List[ cAction] = dTmpCodeSetActions[uAlias] if len(aAliasCodeSet) == 1: oTmpCodeSetAction = copy( aAliasCodeSet[0]) oTmpCodeSetAction.uActionName = uAlias else: oTmpCodeSetAction.uActionString = "call" oTmpCodeSetAction.dActionPars[ "actionname"] = uAlias oTmpCodeSetAction.iActionId = GetActionID( oTmpCodeSetAction.uActionString) oTmpCodeSetAction.dActionPars[ "type"] = "" dTmpCodeSetActions[uKey][ iPos] = oTmpCodeSetAction bDoItAgain = True except Exception as e: uMsg: str = self.ShowError( uMsg= u'Cannot read Codeset (wrong alias [%s=%s] CodesetFileName: %s):' % (uKey, uAlias, oCodesetFileName.string), oException=e) ShowErrorPopUp(uTitle='Error Reading Codeset', uMessage=uMsg) # Make calls local & Read the common attributes for uKey in dTmpCodeSetActions: for oTmpCodeSetAction in dTmpCodeSetActions[uKey]: if oTmpCodeSetAction.iActionId == Globals.oActions.oActionType.Call: uActionName: str = oTmpCodeSetAction.dActionPars.get( "actionname", "") if uActionName in dTmpCodeSetActions: oTmpCodeSetAction.dActionPars[ "actionname"] = self.MakeLocalActionName( uActionName) self.ReadAction(oTmpCodeSetAction) # add them to the global action list for uKey in dTmpCodeSetActions: Globals.oActions.SetActionList( self.MakeLocalActionName(uKey), dTmpCodeSetActions[uKey]) except Exception as e: uMsg: str = self.ShowError(uMsg=u'Cannot read Codeset :', oException=e) ShowErrorPopUp(uTitle='Error Reading Codeset', uMessage=uMsg) self.SetContextVar(uVarName="firstcall", uVarValue="1")