def list(self): for ref in self.catalog(): item = self.get(ref) if item is None: log.warn("No item retrieved for ref: %s" % (ref,)) else: yield item
def initGestures(): global gesturesFileExists, iniGestures if profileFileExists and gesturesBDPath() != '?': log.debug('Main gestures map found') confGen = gesturesBDPath() confspec = ConfigObj(StringIO(""""""), encoding="UTF-8", list_values=False) iniGestures = ConfigObj(confGen, configspec=confspec, indent_type="\t", encoding="UTF-8") result = iniGestures.validate(Validator()) if result is not True: log.exception('Malformed configuration file') gesturesFileExists = False else: gesturesFileExists = True else: log.warn('No main gestures map (%s) found' % gesturesBDPath(1)) gesturesFileExists = False if gesturesFileExists: for g in iniGestures['globalCommands.GlobalCommands']: if isinstance( iniGestures['globalCommands.GlobalCommands'][g], list): for h in range( len(iniGestures['globalCommands.GlobalCommands'][g])): iniGestures[inputCore.normalizeGestureIdentifier( str(iniGestures['globalCommands.GlobalCommands'][g][h]))] = g elif ('kb:' in g and g not in ['kb:alt', 'kb:control', 'kb:windows', 'kb:control', 'kb:applications'] and 'br(' + curBD + '):' in str(iniGestures['globalCommands.GlobalCommands'][g])): iniGestures[inputCore.normalizeGestureIdentifier(str( iniGestures['globalCommands.GlobalCommands'][g])).replace('br(' + curBD + '):', '')] = g return gesturesFileExists, iniGestures
def _load(self): confspec = ConfigObj(StringIO("""#{0} add-on Configuration File {1} {2} {3} """.format(_curAddon.manifest["name"], self._generalConfSpec, self._optionsConfSpec, self._resumeFilesConfSpec)), list_values=False, encoding="UTF-8") confspec.newlines = "\r\n" configFile = os.path.join(globalVars.appArgs.configPath, "%sAddon.ini" % self.addon.manifest["name"]) try: self._conf = ConfigObj(configFile, configspec=confspec, indent_type="\t", encoding="UTF-8") except: # noqa:E722 self._conf = ConfigObj(None, configspec=confspec, indent_type="\t", encoding="UTF-8") self._configFileError = "Error parsing configuration file: %s" % e self._conf.newlines = "\r\n" result = self._conf.validate(self._val) if not result or self._configFileError: log.warn(configFileError) return if not os.path.exists(configFile): self.save()
def load(factoryDefaults=False): """Loads the configuration from the configFile. It also takes note of the file's modification time so that L{save} won't lose any changes made to the file while NVDA is running. """ global conf, synthSpec configFileName = os.path.join(globalVars.appArgs.configPath, "nvda.ini") if factoryDefaults: conf = ConfigObj(None, configspec=confspec, indent_type="\t", encoding="UTF-8") conf.filename = configFileName else: try: conf = ConfigObj(configFileName, configspec=confspec, indent_type="\t", encoding="UTF-8") except ConfigObjError as e: conf = ConfigObj(None, configspec=confspec, indent_type="\t", encoding="UTF-8") conf.filename = configFileName globalVars.configFileError = "Error parsing configuration file: %s" % e # Python converts \r\n to \n when reading files in Windows, so ConfigObj can't determine the true line ending. conf.newlines = "\r\n" errorList = validateConfig(conf, val) if synthSpec is None: synthSpec = deepcopy(conf["speech"].configspec["__many__"]) if errorList: globalVars.configFileError = "Errors in configuration file '%s':\n%s" % ( conf.filename, "\n".join(errorList)) if globalVars.configFileError: log.warn(globalVars.configFileError)
def load(factoryDefaults=False): """Loads the configuration from the configFile. It also takes note of the file's modification time so that L{save} won't lose any changes made to the file while NVDA is running. """ global conf,synthSpec configFileName=os.path.join(globalVars.appArgs.configPath,"nvda.ini") if factoryDefaults: conf = ConfigObj(None, configspec = confspec, indent_type = "\t", encoding="UTF-8") conf.filename=configFileName else: try: conf = ConfigObj(configFileName, configspec = confspec, indent_type = "\t", encoding="UTF-8") except ConfigObjError as e: conf = ConfigObj(None, configspec = confspec, indent_type = "\t", encoding="UTF-8") conf.filename=configFileName globalVars.configFileError="Error parsing configuration file: %s"%e # Python converts \r\n to \n when reading files in Windows, so ConfigObj can't determine the true line ending. conf.newlines = "\r\n" errorList=validateConfig(conf,val) if synthSpec is None: synthSpec=deepcopy(conf["speech"].configspec["__many__"]) if errorList: globalVars.configFileError="Errors in configuration file '%s':\n%s"%(conf.filename,"\n".join(errorList)) if globalVars.configFileError: log.warn(globalVars.configFileError)
def event_nodeManagerTerminated(self, nodeManager): if self.nodeManager != nodeManager: log.warn(u"nodeManager different than self.nodeManager") return self._ready = False if self.timerCheckAutoAction: self.timerCheckAutoAction.cancel() self.nodeManager = None del self.markerResults[:] self._mutatedControlsById.clear() self._mutatedControlsByOffset[:] = [] for q in self.markerQueries: q.resetResults()
def triggerNVDAExit(newNVDA: Optional[NewNVDAInstance] = None): """ Used to safely exit NVDA. If a new instance is required to start after exit, queue one by specifying instance information with `newNVDA`. """ import queueHandler global _hasShutdownBeenTriggered with _shuttingDownFlagLock: if not _hasShutdownBeenTriggered: # queue this so that the calling process can exit safely (eg a Popup menu) queueHandler.queueFunction(queueHandler.eventQueue, _doShutdown, newNVDA) _hasShutdownBeenTriggered = True else: log.warn("NVDA exit has already been triggered")
def loadConf(): global curBD, gesturesFileExists, profileFileExists, iniProfile curBD = braille.handler.display.name brlextConf = config.conf["brailleExtender"].copy() if "profile_%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["profile_%s" % curBD] = "default" if "tabSize_%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["tabSize_%s" % curBD] = 2 if "leftMarginCells__%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["leftMarginCells_%s" % curBD] = 0 if "rightMarginCells__%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["rightMarginCells_%s" % curBD] = 0 if "autoScrollDelay_%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["autoScrollDelay_%s" % curBD] = 3000 if "keyboardLayout_%s" % curBD not in brlextConf.keys(): config.conf["brailleExtender"]["keyboardLayout_%s" % curBD] = "?" confGen = (r"%s\%s\%s\profile.ini" % (profilesDir, curBD, config.conf["brailleExtender"]["profile_%s" % curBD])) if (curBD != "noBraille" and os.path.exists(confGen)): profileFileExists = True confspec = config.ConfigObj(StringIO(""""""), encoding="UTF-8", list_values=False) iniProfile = config.ConfigObj(confGen, configspec=confspec, indent_type="\t", encoding="UTF-8") result = iniProfile.validate(Validator()) if result is not True: log.exception("Malformed configuration file") return False else: if curBD != "noBraille": log.warn("%s inaccessible" % confGen) else: log.debug("No braille display present") if (backupDisplaySize - config.conf["brailleExtender"]["rightMarginCells_" + curBD] <= backupDisplaySize and config.conf["brailleExtender"]["rightMarginCells_%s" % curBD] > 0): braille.handler.displaySize = backupDisplaySize - config.conf[ "brailleExtender"]["rightMarginCells_%s" % curBD] if not noUnicodeTable: loadPreferedTables() if config.conf["brailleExtender"]["inputTableShortcuts"] not in tablesUFN: config.conf["brailleExtender"]["inputTableShortcuts"] = '?' if config.conf["brailleExtender"]["features"]["roleLabels"]: loadRoleLabels(config.conf["brailleExtender"]["roleLabels"].copy()) return True
def loadConf(): global conf, reviewModeApps, quickLaunches, gesturesFileExists, iTables, oTables, profileFileExists, iniProfile confspec = ConfigObj(StringIO(""" [general] autoCheckUpdate = boolean(default=True) channelUpdate = option("stable", "dev", default="stable") lastCheckUpdate = float(min=0, default=0) profile_{CUR_BD} = string(default="default") keyboardLayout_{CUR_BD} = string(default={KEYBOARDLAYOUT}) showConstructST = boolean(default=True) brailleDisplay1 = string(default="noBraille") brailleDisplay2 = string(default="noBraille") reportVolumeBraille = boolean(default=True) reportVolumeSpeech = boolean(default=False) reviewModeApps = string(default="cmd, putty, bash, powershell") hourDynamic = boolean(default=True) limitCells_{CUR_BD} = integer(min=0, default=0, max={MAX_CELLS}) delayScroll_{CUR_BD} = float(min=0, default=3, max={MAX_DELAYSCROLL}) smartDelayScroll = boolean(default=False) reverseScroll = boolean(default=False) ignoreBlankLineScroll = boolean(default=True) speakScroll = boolean(default=True) alwaysSpeakScroll = boolean(default=True) speakRoutingTo = boolean(default=True) iTableShortcuts = string(default="?") iTables = string(default="{ITABLE}") oTables = string(default="{OTABLE}") quickLaunchGestures_{CUR_BD} = string(default="{QLGESTURES}") quickLaunchLocations_{CUR_BD} = string(default="notepad; wordpad; calc; cmd") attribra = boolean(default=True) tabSpace = boolean(default=False) tabSize = integer(min=1, default=2, max=42) postTable = string(default="None") [patch] updateBraille = boolean(default=True) scrollBraille = boolean(default=True) """.format( CUR_BD=curBD, MAX_BD=42, ITABLE=config.conf["braille"]["inputTable"] + ', unicode-braille.utb', OTABLE=config.conf["braille"]["translationTable"], MAX_CELLS=420, MAX_DELAYSCROLL=999, MAX_TABLES=420, KEYBOARDLAYOUT=iniProfile['keyboardLayouts'].keys()[0] if 'keyboardLayouts' in iniProfile.keys() else None, QLGESTURES=iniProfile['miscs']['defaultQuickLaunches'] if 'miscs' in iniProfile.keys() else '' )), encoding="UTF-8", list_values=False) confspec.initial_comment = ['%s (%s)' % (_addonName, _addonVersion), _addonURL] confspec.final_comment = ['End Of File'] confspec.newlines = "\n" conf = ConfigObj(cfgFile, configspec=confspec, indent_type="\t", encoding="UTF-8") result = conf.validate(Validator()) if result is not True: log.error('Malformed configuration file') return False else: confspec = ConfigObj(StringIO(""""""), encoding="UTF-8", list_values=False) confGen = ('%s\%s\%s\profile.ini' % (profilesDir, curBD, conf["general"]["profile_%s" % curBD])) if (curBD != 'noBraille' and osp.exists(confGen)): profileFileExists = True iniProfile = ConfigObj(confGen, configspec=confspec, indent_type="\t", encoding="UTF-8") result = iniProfile.validate(Validator()) if result is not True: log.exception('Malformed configuration file') return False else: if curBD != 'noBraille': log.warn('%s inaccessible' % confGen) else: log.debug('No braille display present') if (conf['general']['limitCells_' + curBD] <= backupDisplaySize and conf['general']['limitCells_' + curBD] > 0): braille.handler.displaySize = conf['general']['limitCells_' + curBD] reviewModeApps = [k.strip() for k in conf["general"]["reviewModeApps"].split(',') if k.strip() != ''] tmp1 = [k.strip() for k in conf["general"]["quickLaunchGestures_%s" % curBD].split(';') if k.strip() != ''] tmp2 = [k.strip() for k in conf["general"]["quickLaunchLocations_%s" % curBD].split(';') if k.strip() != ''] for i, gesture in enumerate(tmp1): if i >= len(tmp2): break quickLaunches[gesture] = tmp2[i] if not noUnicodeTable: lITables = [table[0] for table in brailleTables.listTables() if table.input] lOTables = [table[0] for table in brailleTables.listTables() if table.output] iTables = conf['general']['iTables'] oTables = conf['general']['oTables'] if not isinstance(iTables, list): iTables = iTables.replace(', ', ',').split(',') if not isinstance(oTables, list): oTables = oTables.replace(', ', ',').split(',') iTables = [t for t in iTables if t in lITables] oTables = [t for t in oTables if t in lOTables] return True
def InitData(self, context): self.context = context if "data" not in context: context["data"] = {} if "WebModule" not in context["data"]: data = self.data = context["data"]["WebModule"] = {} else: data = self.data = context["data"]["WebModule"] webModule = context["webModule"] if "webModule" in context else None if webModule is None: # Translators: Web module creation dialog title title = _("New Web Module") else: # Translators: Web module edition dialog title title = _("Edit Web Module") self.Title = title if "name" in data: name = data["name"] elif webModule is not None: name = webModule.name else: name = "" self.webModuleName.Value = name urls = [] selectedUrl = None if "url" in data: url = ", ".join(data["url"]) selectedUrl = url urls.append(url) for url in itertools.chain([url], data["url"]): if url not in urls: urls.append(url) if webModule is not None: url = ", ".join(webModule.url) if not selectedUrl: selectedUrl = url for url_ in itertools.chain([url], webModule.url): if url_ not in urls: urls.append(url_) if "focusObject" in context: urlFromObject = getUrlFromObject(context["focusObject"]) log.info("urlFromObject: %s" % urlFromObject) if urlFromObject is None: if webModule is None: ui.message(_("URL not found")) elif urlFromObject not in urls: urls.append(urlFromObject) else: log.warn("focusObject not in context") urlsChoices = [] for url in urls: choice = url urlChoices = [choice] # Strip protocol if "://" in choice: choice = choice.split("://", 1)[-1] urlChoices.insert(0, choice) # Strip parameters if "?" in choice: choice = choice.rsplit('?', 1)[0] urlChoices.insert(0, choice) # Strip directories while "/" in choice[1:]: choice = choice.rsplit('/', 1)[0] urlChoices.insert(0, choice) # Reverse order for local resources (most specific first) if url.startswith("file:") or url.startswith("/"): urlChoices.reverse() urlsChoices.extend(urlChoices) urlsChoicesSet = set() urlsChoices = [ choice for choice in urlsChoices if not (choice in urlsChoicesSet or urlsChoicesSet.add(choice)) ] self.webModuleUrl.SetItems(urlsChoices) self.webModuleUrl.Selection = (urlsChoices.index(selectedUrl) if selectedUrl else 0) windowTitleChoices = [] windowTitleIsFilled = False if "windowTitle" in data: windowTitleIsFilled = True windowTitleChoices.append( data["windowTitle"] if data["windowTitle"] else "") if (webModule is not None and webModule.windowTitle not in windowTitleChoices): windowTitleIsFilled = True windowTitleChoices.append( webModule.windowTitle if webModule.windowTitle else "") windowTitleFilled = True if "focusObject" in context: obj = context["focusObject"] if obj.windowText not in windowTitleChoices: windowTitleChoices.append(obj.windowText) item = self.webModuleWindowTitle log.info("windowTitleChoices: %s" % windowTitleChoices) item.SetItems(windowTitleChoices) if windowTitleIsFilled: item.Selection = 0 else: item.Value = ""