def nvdaControllerInternal_logMessage(pid,tid,level,fileName,funcName,lineNo,message): if not log.isEnabledFor(level): return 0 from appModuleHandler import getAppNameFromProcessID codepath="RPC: %s, %s, %s, line %d"%(getAppNameFromProcessID(pid,includeExt=True),fileName,funcName, lineNo) log._log(level,message,[],codepath=codepath) return 0
def script_saveBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark bookmarks = getSavedBookmarks() noteTitle = obj.makeTextInfo(textInfos.POSITION_SELECTION).text[:100].encode("utf-8") if bookmark.startOffset in bookmarks: noteBody = bookmarks[bookmark.startOffset].body else: noteBody = "" bookmarks[bookmark.startOffset] = Note(noteTitle, noteBody) fileName = getFileBookmarks() try: pickle.dump(bookmarks, file(fileName, "wb")) ui.message( # Translators: message presented when a position is saved as a bookmark. _("Saved position at character %d") % bookmark.startOffset) except Exception as e: log.debugWarning("Error saving bookmark", exc_info=True) ui.message( # Translators: message presented when a bookmark cannot be saved. _("Cannot save bookmark")) raise e
def script_saveTempBookmark(self, gesture): obj = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(obj.processID, True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor else: gesture.send() return bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark fileName = getFileTempBookmark() try: with open(fileName, "w", encoding="utf-8") as f: f.write(str(bookmark.startOffset)) # Translators: Message presented when a temporary bookmark is saved. ui.message( _("Saved temporary bookmark at position %d" % bookmark.startOffset)) except Exception as e: log.debugWarning("Error saving temporary bookmark", exc_info=True) raise e
def script_saveBookmark(self, gesture): obj = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(obj.processID, True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor else: gesture.send() return bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark bookmarks = getSavedBookmarks() noteTitle = obj.makeTextInfo(textInfos.POSITION_SELECTION).text[:100] if bookmark.startOffset in bookmarks: noteBody = bookmarks[bookmark.startOffset].body else: noteBody = "" bookmarks[bookmark.startOffset] = Note(noteTitle, noteBody) fileName = getFileBookmarks() try: with open(fileName, "wb") as f: pickle.dump(bookmarks, f, protocol=0) ui.message( # Translators: message presented when a position is saved as a bookmark. _("Saved position at character %d") % bookmark.startOffset) except Exception as e: log.debugWarning("Error saving bookmark", exc_info=True) ui.message( # Translators: message presented when a bookmark cannot be saved. _("Cannot save bookmark")) raise e
def setFocusedAppVolumeToPreviousLevel(): focus = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(focus.processID, True) level = _previousAppVolumeLevel.get(appName.lower()) if level is None: return level = int(level * 100) changeFocusedAppVolume(appName=appName, action="set", value=level)
def event_documentLoadComplete(self, obj, nextHandler): if appModuleHandler.getAppNameFromProcessID( obj.processID) in self.allowedApps: location = obj.location obj.location = None self.playObject(obj) obj.location = location nextHandler()
def script_reportAppModuleInfo(self,gesture): focus=api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(focus.processID,True) message = _("Currently running application is %s") % appName mod=focus.appModule if isinstance(mod,appModuleHandler.AppModule) and type(mod)!=appModuleHandler.AppModule: message += _(" and currently loaded module is %s") % mod.appModuleName.split(".")[0] ui.message(message)
def nvdaControllerInternal_logMessage(level,pid,message): if not log.isEnabledFor(level): return 0 if pid: from appModuleHandler import getAppNameFromProcessID codepath="RPC process %s (%s)"%(pid,getAppNameFromProcessID(pid,includeExt=True)) else: codepath="NVDAHelperLocal" log._log(level,message,[],codepath=codepath) return 0
def script_toggleCurrentAppVolumeMute(self, gesture): focus = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(focus.processID, True) if appName == "nvda.exe": ui.message(_("Unavailable for NVDA")) return try: volumeControl.toggleProcessVolume(appName) except: # noqa:E722 ui.message(_("Not available on this operating's system"))
def populateAttrs(pid): if (len(configBE.confAttribra) == 0): return global ATTRS # We are changing the global variable appname = appModuleHandler.getAppNameFromProcessID(pid) if (appname in configBE.confAttribra): ATTRS = configBE.confAttribra[appname] elif ("global" in configBE.confAttribra): ATTRS = configBE.confAttribra["global"] else: ATTRS = {}
def script_activateNotesDialog(self, gesture): obj=api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if not (hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough): gesture.send() return wx.CallAfter(self.popupNotesDialog)
def changeFocusedAppVolume(appName=None, action="increase", value=None): global _previousAppVolumeLevel if appName is None: focus = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID( focus.processID, True) if appName == "nvda.exe": ui.message(_("Unavailable for NVDA")) return from ..settings import _addonConfigManager try: sessions = AudioUtilities.GetAllSessions() except: # noqa:E722 # no supported log.warning( "AudioUtilities getAllCessions not supported on this system") return for session in sessions: try: name = session.Process.name() except: # noqa:E722 continue if name.lower() == appName.lower(): volume = session.SimpleAudioVolume mute = volume.GetMute() if mute: volume.SetMute(not mute, None) offset = 0.01 * _addonConfigManager.getVolumeChangeStepLevel() curLevel = volume.GetMasterVolume() if action == "increase": level = min(1, curLevel + offset) elif action == "decrease": level = max(0, curLevel - offset) elif action == "max": level = 1.0 elif action == "min": level = 0.0 elif action == "set": level = float(value) / 100 else: # no action log.warning("changeFocusedAppVolume: %s action is not known" % action) return _previousAppVolumeLevel[appName.lower()] = curLevel volume.SetMasterVolume(level, None) level = volume.GetMasterVolume() announceAppVolumeLevel(level) log.warning("%s volume is set to %s" % (appName, level)) return
def __init__(self, handle=None, windowTitle=None, appName=None): if handle: if winUser.isWindow(handle) == 0: raise ValueError( "Cannot create object for non existing window") else: self.handle = handle self.windowTitle = windowTitle self.appName = appName else: self.handle = api.getForegroundObject().windowHandle self.windowTitle = api.getForegroundObject().name self.appName = appModuleHandler.getAppNameFromProcessID( api.getForegroundObject().processID, True)
def __init__(self, parent): if NVDAAndAudioApplicationsManagerDialog._instance is not None: return NVDAAndAudioApplicationsManagerDialog._instance = self focus = api.getFocusObject() from appModuleHandler import getAppNameFromProcessID self.focusedAppName = getAppNameFromProcessID(focus.processID, True).split(".")[0] # Translators: this is the title of NVDA and Applications audio Channels manager dialog dialogTitle = _("NVDA and running Applications audio manager") title = NVDAAndAudioApplicationsManagerDialog.title = makeAddonWindowTitle( dialogTitle) super(NVDAAndAudioApplicationsManagerDialog, self).__init__(parent, wx.ID_ANY, title) self.doGui()
def getAppNameFromHost(processId): # Some apps have launcher executables which launch javaw.exe to run the app. # In this case, the parent process will usually be the launcher. proc = appModuleHandler.getWmiProcessInfo(processId) parent = proc.parentProcessId if parent: name = appModuleHandler.getAppNameFromProcessID(parent) if name and name not in ("explorer", "cmd"): # The parent isn't a shell, so it's probably a launcher. return name # Try getting the class/jar from the command line. cmd = proc.CommandLine if not cmd: raise LookupError try: return "javaw_" + _getEntryPoint(cmd).replace(".", "_") except: raise LookupError
def script_moveToTempBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return fileName = getFileTempBookmark() try: with codecs.open(fileName, "r", "utf-8") as f: tempBookmark = int(f.read()) moveToBookmark(tempBookmark) except: # Translators: Message presented when a temporary bookmark can't be found. ui.message("Temporary bookmark not found")
def script_saveTempBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark fileName = getFileTempBookmark() try: with codecs.open(fileName, "w", "utf-8") as f: f.write(str(bookmark.startOffset)) # Translators: Message presented when a temporary bookmark is saved. ui.message(_("Saved temporary bookmark at position %d" % bookmark.startOffset)) except Exception as e: log.debugWarning("Error saving temporary bookmark", exc_info=True) raise e
def changeAppVolume(appName=None, action="increase", value=100, report=True, reportValue=None): log.debug("changeFocusedAppVolume: %s, action= %s, level: %s" % (appName, action, value)) from ..settings import _addonConfigManager global _previousAppVolumeLevel if appName is None: focus = api.getFocusObject() from appModuleHandler import getAppNameFromProcessID appName = getAppNameFromProcessID(focus.processID, True) volumeObj = getAppVolumeObj(appName) if not volumeObj: return mute = volumeObj.GetMute() if mute: volumeObj.SetMute(not mute, None) speakersVolume = getVolumeObj().GetMasterVolumeLevelScalar() offset = _addonConfigManager.getVolumeChangeStepLevel() curLevel = getAbsoluteLevel(volumeObj.GetMasterVolume()) if action == "increase": level = min(100, curLevel + offset) elif action == "decrease": level = max(0, curLevel - offset) elif action == "max": level = 100 elif action == "min": level = 0 elif action == "set": # value = percent of speakers volume level = int(round(100 * speakersVolume) * value / 100) else: # unknown action log.warning("changeFocusedAppVolume: %s action is not known" % action) return (relativeLevel, absoluteLevel) = validateVolumeLevel(level, appName) setAppVolume(appName, relativeLevel, True, absoluteLevel)
def script_selectPreviousBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() if bookmarks == {}: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset prevPos = None for pos in sorted(bookmarks, reverse=True): if pos < curPos: prevPos = pos break if prevPos is not None: info = obj.makeTextInfo(Offsets(prevPos, prevPos)) info.updateSelection() review.handleCaretMove(info) if willSayAllResume(gesture): info.move(textInfos.UNIT_LINE,1,endPoint="end") #speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % prevPos) return ui.message( # Translators: message presented when the previous bookmark is not found. _("Previous bookmark not found"))
def script_selectNextBookmark(self, gesture): obj = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(obj.processID, True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() if bookmarks == {}: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return curPos = obj.makeTextInfo( textInfos.POSITION_CARET).bookmark.startOffset nextPos = None for pos in sorted(bookmarks): if pos > curPos: nextPos = pos break if nextPos is not None: moveToBookmark(nextPos) if not willSayAllResume(gesture): ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % nextPos) return ui.message( # Translators: message presented when the next bookmark is not found. _("Next bookmark not found"))
def centerFocusedApplication(): focus = api.getFocusObject() from appModuleHandler import getAppNameFromProcessID appName = getAppNameFromProcessID(focus.processID, True) toggleChannels(application=appName, balance="center")
def event_documentLoadComplete(self, obj, nextHandler): if appModuleHandler.getAppNameFromProcessID(obj.processID) in self.browser_apps: self.playObject(obj) nextHandler()
def script_centerNVDAAndFocusedApplication(self, gesture): from ..computerTools.volumeControl import splitChannels focus = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID( focus.processID, True) splitChannels(NVDAChannel="None", application=appName)