Beispiel #1
0
    def GetSettingParFromIni(self, uSectionName, uVarName):
        """
        Returns a setting for the configuration ini file
        If the entry does not exist, it tries to puls the value from the  aInterFaceIniSettings dict of already predifined settings
        If not exist there as well, an error will be logged

        :rtype: string|None
        :param string uSectionName: The name of the section
        :param uVarName: The name of the parameter/setting in the section
        :return: The value of the setting, empty string if not found
         """

        oSetting = self.oScript.GetSettingObjectForConfigName(uSectionName)
        uResult = Config_GetDefault_Str(self.oConfigParser, uSectionName,
                                        uVarName, None)
        if uResult is None:
            uResult = str(oSetting.aScriptIniSettings.queryget(uVarName))
        if uResult is None:
            uResult = ''
            self.oScript.ShowError(u'can\'t find script setting: %s:%s' %
                                   (uSectionName, uVarName))
        else:
            self.oScript.ShowDebug(u'Returning script setting: %s from %s:%s' %
                                   (uResult, uSectionName, uVarName))
        return uResult
Beispiel #2
0
    def GetSettingParFromIni(self, *, uSectionName: str, uVarName: str) -> str:
        """
        Returns a setting for the configuration ini file
        If the entry does not exist, it tries to puls the value from the  aIniSettings dict of already predifined settings
        If not exist there as well, an error will be logged

        :param str uSectionName: The name of the section
        :param uVarName: The name of the parameter/setting in the section
        :return: The value of the setting, empty string if not found
         """

        oSetting = self.oObject.GetSettingObjectForConfigName(
            uConfigName=uSectionName)
        uResult = Config_GetDefault_Str(oConfig=self.oConfigParser,
                                        uSection=uSectionName,
                                        uOption=uVarName,
                                        vDefaultValue="***notfound***")
        if uResult == "***notfound***":
            uResult = str(oSetting.aIniSettings.queryget(uVarName))
        if uResult is None:
            uResult = ''
            self.oObject.ShowError(uMsg=u'can\'t find setting: %s:%s' %
                                   (uSectionName, uVarName))
        else:
            self.oObject.ShowDebug(uMsg=u'Returning setting: %s from %s:%s' %
                                   (uResult, uSectionName, uVarName))
        return uResult
Beispiel #3
0
    def CreateSettingsJSONString(self) -> None:
        """ Creates the json string for the settings dialog AND reads/writes the defaults to the config file """

        uSection: str = Globals.uDefinitionName
        uSection = uSection.replace(u' ', u'_')
        uVisSection: str
        oConfig: Config = Globals.oDefinitionConfigParser

        for uDefinitionKey in self:
            oDef = self[uDefinitionKey]
            uVisSection = oDef.uName
            if len(oDef.aDefinitionsSettings) > 0:
                uTitle: str = oDef.uDefPublicTitle
                for aSetting in oDef.aDefinitionsSettings:
                    uType: str = aSetting['type']

                    if uType == "section":
                        uVisSection = aSetting['title']
                        continue
                    if oDef.dDefinitionSettingsJSON.get(uVisSection) is None:
                        oDef.dDefinitionSettingsJSON[
                            uVisSection] = u'[{ "type": "title","title": "' + uTitle + '" }\n'
                        #oDef.dDefinitionSettingsJSON[uVisSection]=u'['

                    aSetting['section'] = uSection
                    uFormatString: str = self.dSettingFormatStrings.get(uType)
                    if uFormatString is None:
                        uFormatString = self.dSettingFormatStrings['default']
                    oDef.dDefinitionSettingsJSON[
                        uVisSection] += uFormatString.format(**aSetting)
                    uVar: str = aSetting['var']
                    uDefault: str = self.dSettingsDefaults[uVar]
                    #uDefault=ReplaceVars(uDefault)
                    #todo temporary hack to bypass configparser unicode bug
                    uDefault = EscapeUnicode(uDefault)
                    #check for cookies
                    uCookie: str = aSetting["cookie"]
                    if uCookie != u"" and uDefault == "":
                        uDefault = Var_Load(uVarName=uCookie,
                                            uDefault="",
                                            uPrefix="")

                    # parse definition settings into vars
                    uValue: str = ReplaceVars(
                        Config_GetDefault_Str(oConfig=oConfig,
                                              uSection=uSection,
                                              uOption=uVar,
                                              vDefaultValue=uDefault))
                    #todo temporary hack to bypass configparser unicode bug
                    uValue = UnEscapeUnicode(uValue)
                    # Logger.debug("Loading Definition Config Setting into var: [%s]=[%s]" %(uVar,uValue))
                    SetVar(uVarName=uVar, oVarValue=uValue)
                    self.aDefinitionSettingVars.append(uVar)
            for uVisSection in oDef.dDefinitionSettingsJSON:
                if len(oDef.dDefinitionSettingsJSON[uVisSection]) > 0:
                    oDef.dDefinitionSettingsJSON[uVisSection] += u']'
        oConfig.write()
        return None
Beispiel #4
0
    def ReadConfigFromIniFile(self, uConfigName):
        """ Reads the script config file """
        if self.aScriptIniSettings.bInitCompleted:
            return
        self.aScriptIniSettings.bInitCompleted = True

        if uConfigName != u'':
            self.uConfigName = uConfigName
            self.uContext = self.oScript.uScriptName + u'/' + self.uConfigName
        self.uSection = self.uConfigName

        try:
            self.oScript.oScriptConfig.LoadConfig()
            SetVar(uVarName=u'ScriptConfigSection', oVarValue=uConfigName)
            dIniDef = self.oScript.oScriptConfig.CreateSettingJsonCombined(
                self)

            for uKey2 in dIniDef:
                oLine = dIniDef[uKey2]
                uType = oLine.get("type")
                uKey = oLine.get("key")
                uDefault = oLine.get("default")

                if uKey is None or uDefault is None:
                    continue

                # we replace JSON defaults by script-settings defaults, if exists
                if self.aScriptIniSettings.queryget(uKey) is not None:
                    uDefault = self.aScriptIniSettings.queryget(uKey)

                uResult = Config_GetDefault_Str(
                    self.oScript.oScriptConfig.oConfigParser, self.uSection,
                    uKey, uDefault)

                if uType == "scrolloptions" or uType == "string":
                    self.aScriptIniSettings[uKey] = ReplaceVars(uResult)
                elif uType == "numeric" or uType == "numericslider":
                    self.aScriptIniSettings[uKey] = ToInt(uResult)
                elif uType == "numericfloat":
                    self.aScriptIniSettings[uKey] = ToFloat(uResult)
                elif uType == "bool":
                    self.aScriptIniSettings[uKey] = ToBool(uResult)
                elif uType == "title" or uType == "buttons" or uType == "path" or uType == "varstring":
                    pass
                else:
                    self.ShowError(
                        u'Cannot read config name (base), wrong attribute:' +
                        self.oScript.oScriptConfig.oFnConfig.string +
                        u' Section:' + self.uSection + " " + oLine["type"])

            self.oScript.oScriptConfig.oConfigParser.write()
        except Exception as e:
            self.ShowError(uMsg=u'Cannot read config name (base):' +
                           self.oScript.oScriptConfig.oFnConfig.string +
                           u' Section:' + self.uSection,
                           oException=e)
            return
Beispiel #5
0
 def LoadRepositoryDirectory(self, bDoNotExecute):
     """ Loads the directory of a repository """
     aActions = []
     if len(oRepository.aRepEntries) == 0:
         for i in range(Globals.iCntRepositories):
             uRepKey = u'repository_state' + str(i)
             uRepUrl = Globals.aRepositories[i]
             if not uRepUrl == '':
                 if Config_GetDefault_Str(Globals.oOrcaConfigParser,
                                          u'ORCA', uRepKey, '0') != '0':
                     oRepository.Init()
                     aActions += oRepository.LoadAllSubReps(
                         ReplaceVars(uRepUrl), self.aSubReps, bDoNotExecute)
     return aActions
Beispiel #6
0
 def LoadRepositoryDirectory(self, *, bDoNotExecute: bool) -> List[cAction]:
     """ Loads the directory of a repository """
     aActions: List[cAction] = []
     if len(oRepository.aRepEntries) == 0:
         for i in range(Globals.iCntRepositories):
             uRepKey = u'repository_state' + str(i)
             uRepUrl = Globals.aRepositories[i]
             if not uRepUrl == '':
                 if Config_GetDefault_Str(oConfig=Globals.oOrcaConfigParser,
                                          uSection=u'ORCA',
                                          uOption=uRepKey,
                                          vDefaultValue='0') != '0':
                     oRepository.Init()
                     aActions += oRepository.LoadAllSubReps(
                         uPath=ReplaceVars(uRepUrl),
                         aSubReps=self.aSubReps,
                         bDoNotExecute=bDoNotExecute)
     return aActions
Beispiel #7
0
    def InitAndReadSettingsPanel(self):
        """
        Reads the complete settings from the orca.ini file
        it will set setting defaults, if we do not have an ini file by now
        """
        try:
            '''
            if Globals.oParameter.oPathLog is not None:
                oPathLogfile = Globals.oParameter.oPathLog
            else:
                oPathLogfile = cPath(Globals.oPathRoot) + "logs"
            oPathLogfile.Create()
            kivyConfig.set('kivy', 'log_dir', oPathLogfile.string)
            kivyConfig.write()
            uOrgLogFn=Logger.manager.loggerDict["kivy"].handlers[1].filename
            Logger.debug(u"Init: Original Startup Logile at :"+uOrgLogFn)
            '''

            Logger.level = Logger.level

            Globals.fDoubleTapTime = ToFloat(
                kivyConfig.getint('postproc', 'double_tap_time')) / 1000.0
            self.oFnConfig = cFileName(Globals.oPathRoot) + u'orca.ini'

            oConfig = Globals.oOrcaConfigParser
            oConfig.filename = self.oFnConfig.string
            if self.oFnConfig.Exists():
                oConfig.read(self.oFnConfig.string)

            if not oConfig.has_section(u'ORCA'):
                oConfig.add_section(u'ORCA')

            Globals.uDefinitionName = Config_GetDefault_Str(
                oConfig, u'ORCA', u'definition', u'setup')
            if "[" in Globals.uDefinitionName:
                Globals.uDefinitionName = Globals.uDefinitionName[
                    Globals.uDefinitionName.find("[") +
                    1:Globals.uDefinitionName.find("]")]

            if Globals.uDefinitionName == u'setup':
                Logger.setLevel(logging.DEBUG)

            oRootPath = Config_GetDefault_Path(oConfig, u'ORCA', u'rootpath',
                                               Globals.oPathRoot.string)
            if oRootPath.string:
                Globals.oPathRoot = oRootPath
            oFnCheck = cFileName(Globals.oPathRoot +
                                 'actions') + 'actionsfallback.xml'
            if not oFnCheck.Exists():
                Globals.oPathRoot = OS_GetUserDataPath()

            Logger.debug(u'Init: Override Path:' + Globals.oPathRoot)

            self.InitRootDirs()
            Globals.iLastInstalledVersion = Config_GetDefault_Int(
                oConfig, u'ORCA', 'lastinstalledversion',
                ToIntVersion(Globals.uVersion))

            Globals.bProtected = (Globals.oPathRoot + u'protected').Exists()
            if Globals.bProtected:
                SetVar(uVarName="PROTECTED", oVarValue="1")
            else:
                SetVar(uVarName="PROTECTED", oVarValue="0")

            # get the installed interfaces , etc
            i = 0
            while True:
                oInstalledRep = cInstalledReps()
                uKey = u'installedrep%i_type' % i
                oInstalledRep.uType = Config_GetDefault_Str(
                    oConfig, u'ORCA', uKey, '')
                uKey = u'installedrep%i_name' % i
                oInstalledRep.uName = Config_GetDefault_Str(
                    oConfig, u'ORCA', uKey, '')
                uKey = u'installedrep%i_version' % i
                oInstalledRep.iVersion = Config_GetDefault_Int(
                    oConfig, u'ORCA', uKey, 0)

                if not oInstalledRep.uName == '':
                    uKey = '%s:%s' % (oInstalledRep.uType, oInstalledRep.uName)
                    Globals.dInstalledReps[uKey] = oInstalledRep
                    i += 1
                else:
                    break

            del Globals.aRepositories[:]

            # get the configured repos
            for i in range(Globals.iCntRepositories):
                if i == 0:
                    uDefault = 'https://www.orca-remote.org/repositories/ORCA_$var(REPVERSION)/repositories'
                else:
                    uDefault = ''
                uKey = u'repository' + str(i)
                uRep = ReplaceVars(
                    Config_GetDefault_Str(oConfig, u'ORCA', uKey, uDefault))
                Globals.aRepositories.append(uRep)

                # we add some values for state, which helps for the Download Settings
                uKey = u'repository_state' + str(i)
                Config_GetDefault_Str(oConfig, u'ORCA', uKey, '1')

            # Getting the lists for skins, definitions and languages
            Globals.aSkinList = self.oPathSkinRoot.GetFolderList()
            Globals.aLanguageList = Globals.oPathLanguageRoot.GetFolderList()
            Globals.aDefinitionList = Globals.oPathDefinitionRoot.GetFolderList(
            )
            Globals.uSkinName = Config_GetDefault_Str(oConfig, u'ORCA',
                                                      u'skin',
                                                      u'ORCA_silver_hires')
            self.uSoundsName = Config_GetDefault_Str(oConfig, u'ORCA',
                                                     u'sounds',
                                                     u'ORCA_default')
            Globals.uLanguage = Config_GetDefault_Str(oConfig, u'ORCA',
                                                      u'language',
                                                      OS_GetLocale())
            Globals.uDefinitionContext = Globals.uDefinitionName

            if Globals.uDefinitionName == 'setup':
                Logger.setLevel(logging.DEBUG)

            if not Globals.uLanguage in Globals.aLanguageList:
                if len(Globals.aLanguageList) > 0:
                    Globals.uLanguage = Globals.aLanguageList[0]
            oConfig.set(u'ORCA', u'language', Globals.uLanguage)

            Globals.uLocalesName = Config_GetDefault_Str(
                oConfig, u'ORCA', u'locales', u'UK (12h)')

            if 'shared_documents' in Globals.aDefinitionList:
                Globals.aDefinitionList.remove('shared_documents')

            if not Globals.uDefinitionName in Globals.aDefinitionList:
                if len(Globals.aDefinitionList) > 0:
                    Globals.uDefinitionName = Globals.aDefinitionList[0]
                    oConfig.set(u'ORCA', u'definition',
                                Globals.uDefinitionName)

            if not Globals.uSkinName in Globals.aSkinList:
                if len(Globals.aSkinList) > 0:
                    Globals.uSkinName = Globals.aSkinList[0]

            oConfig.set(u'ORCA', u'skin', Globals.uSkinName)
            oConfig.set(u'ORCA', u'interface', ReplaceVars("select"))
            oConfig.set(u'ORCA', u'script', ReplaceVars("select"))
            oConfig.set(u'ORCA', u'definitionmanage', ReplaceVars("select"))

            Globals.bInitPagesAtStart = Config_GetDefault_Bool(
                oConfig, u'ORCA', u'initpagesatstartup', u'0')
            Globals.fDelayedPageInitInterval = Config_GetDefault_Float(
                oConfig, u'ORCA', u'delayedpageinitinterval', u'60')
            Globals.fStartRepeatDelay = Config_GetDefault_Float(
                oConfig, u'ORCA', u'startrepeatdelay', u'0.8')
            Globals.fContRepeatDelay = Config_GetDefault_Float(
                oConfig, u'ORCA', u'contrepeatdelay', u'0.2')
            Globals.fLongPressTime = Config_GetDefault_Float(
                oConfig, u'ORCA', u'longpresstime', u'1')
            Globals.bConfigCheckForNetwork = Config_GetDefault_Bool(
                oConfig, u'ORCA', u'checkfornetwork', u'1')
            Globals.uNetworkCheckType = Config_GetDefault_Str(
                oConfig, u'ORCA', u'checknetworktype',
                OS_GetDefaultNetworkCheckMode())
            Globals.uConfigCheckNetWorkAddress = Config_GetDefault_Str(
                oConfig, u'ORCA', u'checknetworkaddress', 'auto')
            Globals.bClockWithSeconds = Config_GetDefault_Bool(
                oConfig, u'ORCA', u'clockwithseconds', u'1')
            Globals.bLongDate = Config_GetDefault_Bool(oConfig, u'ORCA',
                                                       u'longdate', u'0')
            Globals.bLongDay = Config_GetDefault_Bool(oConfig, u'ORCA',
                                                      u'longday', u'0')
            Globals.bLongMonth = Config_GetDefault_Bool(
                oConfig, u'ORCA', u'longmonth', u'0')
            Globals.bVibrate = Config_GetDefault_Bool(oConfig, u'ORCA',
                                                      u'vibrate', u'0')
            Globals.bIgnoreAtlas = Config_GetDefault_Bool(
                oConfig, u'ORCA', u'ignoreatlas', u'0')
            Globals.fScreenSize = Config_GetDefault_Float(
                oConfig, u'ORCA', u'screensize', u'0')

            if Globals.fScreenSize == 0:
                Globals.fScreenSize = math.sqrt(
                    Globals.iAppWidth**2 + Globals.iAppHeight**2) / Metrics.dpi

            self.InitOrientationVars()
            Globals.uStretchMode = Config_GetDefault_Str(
                oConfig, u'ORCA', u'stretchmode', OS_GetDefaultStretchMode())
            Globals.oSound.ReadSoundVolumesFromConfig(oConfig)
            oConfig.write()

            self.InitPathes()  # init all used pathes

            # clear cache in case of an update
            if self.bClearCaches:
                ClearAtlas()

            # Create and read the definition ini file
            Globals.oDefinitionConfigParser = oConfig = OrcaConfigParser()

            oConfig.filename = Globals.oDefinitionPathes.oFnDefinitionIni.string
            if Globals.oDefinitionPathes.oFnDefinitionIni.Exists():
                oConfig.read(Globals.oDefinitionPathes.oFnDefinitionIni.string)
            uSection = Globals.uDefinitionName
            uSection = uSection.replace(u' ', u'_')
            if not oConfig.has_section(uSection):
                oConfig.add_section(uSection)
            return True

        except Exception as e:
            uMsg = u'Global Init:Unexpected error reading settings:' + ToUnicode(
                e)
            Logger.critical(uMsg)
            ShowErrorPopUp(uTitle='Fatal Error',
                           uMessage=uMsg,
                           bAbort=True,
                           uTextContinue='',
                           uTextQuit=u'Quit')
            return 0
Beispiel #8
0
    def ReadConfigFromIniFile(self, *, uConfigName: str) -> None:
        """
        Reads the object config file

        :param string uConfigName: The configuration name to read
        :return: None
        """

        if self.aIniSettings.bInitCompleted:
            return
        self.aIniSettings.bInitCompleted = True

        if uConfigName != u'':
            self.uConfigName = uConfigName
            self.uContext = self.oObject.uObjectName + u'/' + self.uConfigName
            self.SetContextVar(uVarName="context", uVarValue=self.uContext)

        self.uSection = self.uConfigName

        try:
            self.oObject.oObjectConfig.LoadConfig()

            if self.oObject.uObjectType == "interface":
                SetVar(uVarName=u'InterfaceCodesetList',
                       oVarValue=self.oObject.CreateCodesetListJSONString())
            SetVar(uVarName=u'ObjectConfigSection', oVarValue=uConfigName)
            dIniDef: Dict[
                str,
                Dict] = self.oObject.oObjectConfig.CreateSettingJsonCombined(
                    oSetting=self)

            for uKey2 in dIniDef:
                dLine: Dict = dIniDef[uKey2]
                uType: str = dLine.get("type")
                uKey: str = dLine.get("key")
                uDefault: str = dLine.get("default")

                if uKey is None or uDefault is None:
                    continue

                # we replace JSON defaults by interface-settings defaults, if exists
                if self.aIniSettings.queryget(uKey) is not None:
                    uDefault = self.aIniSettings.queryget(uKey)

                uResult: str = Config_GetDefault_Str(
                    oConfig=self.oObject.oObjectConfig.oConfigParser,
                    uSection=self.uSection,
                    uOption=uKey,
                    vDefaultValue=uDefault)

                if uType == "scrolloptions" or uType == "string":
                    self.aIniSettings[uKey] = ReplaceVars(uResult)
                elif uType == "numeric" or uType == "numericslider":
                    self.aIniSettings[uKey] = ToInt(uResult)
                elif uType == "numericfloat":
                    self.aIniSettings[uKey] = ToFloat(uResult)
                elif uType == "bool":
                    self.aIniSettings[uKey] = ToBool(uResult)
                elif uType == "varstring":
                    self.aIniSettings[uKey] = ReplaceVars(uResult)
                elif uType == "path":
                    if isinstance(uResult, str):
                        self.aIniSettings[uKey] = cPath(uResult)
                    else:
                        self.aIniSettings[uKey] = uResult
                elif uType == "title" or uType == "buttons":
                    pass
                else:
                    self.ShowError(
                        uMsg=u'Cannot read config name (base), wrong attribute:'
                        + self.oObject.oObjectConfig.oFnConfig.string +
                        u' Section:' + self.uSection + " " + dLine["type"])

                if uKey == 'FNCodeset':
                    self.ReadCodeset()

            self.oObject.oObjectConfig.oConfigParser.write()
        except Exception as e:
            self.ShowError(uMsg=u'Cannot read config name (base):' +
                           self.oObject.oObjectConfig.oFnConfig.string +
                           u' Section:' + self.uSection,
                           oException=e)
            return