def writeUserPreferences(self): """Write out the user's application-specific Orca preferences. """ moduleName = settings.getScriptModuleName(self.app) app_prefs.writePreferences(self.prefsDict, moduleName, self.appScript, self.keyBindingsModel, self.pronunciationModel) ftp = focus_tracking_presenter.FocusTrackingPresenter() ftp.loadAppSettings(self.appScript)
def loadAppSettings(self, script): """Load the users application specific settings for an app. Arguments: - script: the current active script. """ app = script.app settingsPackages = settings.settingsPackages moduleName = settings.getScriptModuleName(app) module = None if moduleName and len(moduleName): for package in settingsPackages: if len(package): name = package + "." + moduleName else: name = moduleName try: debug.println(debug.LEVEL_FINEST, "Looking for settings at %s.py..." % name) if not self._knownAppSettings.has_key(name): self._knownAppSettings[name] = \ __import__(name, globals(), locals(), ['']) reload(self._knownAppSettings[name]) debug.println(debug.LEVEL_FINEST, "...found %s.py" % name) # Setup the user's application specific key bindings. # (if any). # if hasattr(self._knownAppSettings[name], "overrideAppKeyBindings"): script.overrideAppKeyBindings = \ self._knownAppSettings[name].overrideAppKeyBindings script.keyBindings = \ self._knownAppSettings[name].overrideAppKeyBindings( \ script, script.keyBindings) # Setup the user's application specific pronunciations # (if any). # if hasattr(self._knownAppSettings[name], "overridePronunciations"): script.overridePronunciations = \ self._knownAppSettings[name].overridePronunciations script.app_pronunciation_dict = \ self._knownAppSettings[name].overridePronunciations( \ script, script.app_pronunciation_dict) break except ImportError: debug.println(debug.LEVEL_FINEST, "...could not find %s.py" % name)
def _createScript(self, app): """For the given application name, create a new script instance. We'll first see if a mapping from appName to module name exists. If it does, we use that. If it doesn't, we try the app name. If all else fails, we fall back to the default script. """ script = None if settings.enableCustomScripts: # Look for custom scripts first. # # We'll use the LEVEL_FINEST level for debug output here as # it really isn't an error if the script cannot be found. # But, sometimes a script cannot be "found" because it has # a syntax error in it, so we want to give script writers # a vehicle for debugging these types of things. # scriptPackages = settings.scriptPackages moduleName = settings.getScriptModuleName(app) module = None if moduleName and len(moduleName): for package in scriptPackages: if len(package): name = package + "." + moduleName else: name = moduleName try: debug.println(debug.LEVEL_FINEST, "Looking for script at %s.py..." % name) module = __import__(name, globals(), locals(), ['']) debug.println(debug.LEVEL_FINEST, "...found %s.py" % name) break except ImportError: debug.println(debug.LEVEL_FINEST, "...could not find %s.py" % name) except: debug.printException(debug.LEVEL_SEVERE) debug.println(debug.LEVEL_SEVERE, "While attempting to import %s" % name) if module: try: script = module.Script(app) except: # We do not want the getScript method to fail. If it does, # we want to let the script developer know what went wrong, # but we also want to move along without crashing Orca. # debug.printException(debug.LEVEL_SEVERE) # If there is no custom script for an application, try seeing if # there is a script for the toolkit of the application. If there # is, then try to use it. If there isn't, then fall back to the # default script. Note that this search is restricted to the "orca" # package for now. # if (not script) \ and app \ and app.__dict__.has_key("toolkitName") \ and app.toolkitName: try: debug.println( debug.LEVEL_FINE, "Looking for toolkit script %s.py..." % app.toolkitName) module = __import__(app.toolkitName, globals(), locals(), ['']) script = module.Script(app) debug.println(debug.LEVEL_FINE, "...found %s.py" % name) except ImportError: debug.println( debug.LEVEL_FINE, "...could not find %s.py" % app.toolkitName) except: debug.printException(debug.LEVEL_SEVERE) debug.println( debug.LEVEL_SEVERE, "While attempting to import %s" % app.toolkitName) if not script: script = default.Script(app) return script
def _createScript(self, app): """For the given application name, create a new script instance. We'll first see if a mapping from appName to module name exists. If it does, we use that. If it doesn't, we try the app name. If all else fails, we fall back to the default script. """ script = None if settings.enableCustomScripts: # Look for custom scripts first. # # We'll use the LEVEL_FINEST level for debug output here as # it really isn't an error if the script cannot be found. # But, sometimes a script cannot be "found" because it has # a syntax error in it, so we want to give script writers # a vehicle for debugging these types of things. # scriptPackages = settings.scriptPackages moduleName = settings.getScriptModuleName(app) module = None if moduleName and len(moduleName): for package in scriptPackages: if len(package): name = package + "." + moduleName else: name = moduleName try: debug.println(debug.LEVEL_FINEST, "Looking for script at %s.py..." % name) module = __import__(name, globals(), locals(), ['']) debug.println(debug.LEVEL_FINEST, "...found %s.py" % name) break except ImportError: debug.println(debug.LEVEL_FINEST, "...could not find %s.py" % name) except: debug.printException(debug.LEVEL_SEVERE) debug.println(debug.LEVEL_SEVERE, "While attempting to import %s" % name) if module: try: script = module.Script(app) except: # We do not want the getScript method to fail. If it does, # we want to let the script developer know what went wrong, # but we also want to move along without crashing Orca. # debug.printException(debug.LEVEL_SEVERE) # If there is no custom script for an application, try seeing if # there is a script for the toolkit of the application. If there # is, then try to use it. If there isn't, then fall back to the # default script. Note that this search is restricted to the "orca" # package for now. # if (not script) \ and app \ and app.__dict__.has_key("toolkitName") \ and app.toolkitName: try: debug.println( debug.LEVEL_FINE, "Looking for toolkit script %s.py..." % app.toolkitName) module = __import__(app.toolkitName, globals(), locals(), ['']) script = module.Script(app) debug.println(debug.LEVEL_FINE, "...found %s.py" % name) except ImportError: debug.println(debug.LEVEL_FINE, "...could not find %s.py" % app.toolkitName) except: debug.printException(debug.LEVEL_SEVERE) debug.println( debug.LEVEL_SEVERE, "While attempting to import %s" % app.toolkitName) if not script: script = default.Script(app) return script