def isRecordingReady(): fg = api.getForegroundObject() hTime = readOrRecord() hRecord = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) text = getNVDAObjectFromEvent(hTime, OBJID_CLIENT, CHILDID_SELF).value text1 = getNVDAObjectFromEvent(hRecord, OBJID_CLIENT, CHILDID_SELF).value if not text1 and (text and not text.isspace()): return True return False
def getAttachmentInfos2013(self): fg = api.getForegroundObject() cidAttachments = 4623 bFoundWindow = False bResult = False try: handle = findDescendantWindow(fg.windowHandle, className=None, controlID=cidAttachments) bFoundWindow = True obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) if not (obj.location.width == 0 and obj.location.height == 0): attachmentsList = [ c for c in obj.children[1:] if c.role == controlTypes.Role.LISTITEM ] namesGen = (a.name for a in attachmentsList) bResult = True except LookupError: pass if not bResult: cidAttachments = 4104 try: handle = findDescendantWindow(fg.windowHandle, className=None, controlID=cidAttachments) obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) if obj.firstChild is None: raise LookupError bFoundWindow = True def makeGenChildren( o ): #Define a generator to get children since the .children roperty does not work o = o.firstChild while o is not None: if o.role == controlTypes.Role.BUTTON: yield o o = o.next attachmentsList = [o for o in makeGenChildren(obj)] namesGen = (a.name for a in attachmentsList) bResult = True except LookupError: pass if not bFoundWindow: raise LookupError if bResult: return attachmentsList, handle, namesGen, obj.name else: return [], handle, [], obj.name
def getHeaderFieldObject(self, nField): try: cid, name = self.getHeaderFieldsFun()[nField] except KeyError: raise HeaderFieldNotFoundeError() try: handle = findDescendantWindow(self.rootDialog.windowHandle, controlID=cid) if handle: obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) except LookupError: raise HeaderFieldNotFoundeError() except AttributeError: # Exception raised when performing tests calling self.rootDialog.windowHandle on FakeRootDialog obj = [ o for o in self.rootDialog.children if o.windowControlID == cid ] if len(obj) != 1: infos = { 'obj': obj, 'cid': cid, 'name': name, } log.debug(f'Header field not found. Infos: {infos}') raise HeaderFieldNotFoundeError() obj = obj[0] if controlTypes.STATE_INVISIBLE in obj.states: raise HeaderFieldNotFoundeError() return obj, name
def getHeaderParent(self): # faster than previous self.simpleParent.children[-1] headerHandle = watchdog.cancellableSendMessage( self.simpleParent.windowHandle, LVM_GETHEADER, 0, 0) headerParent = getNVDAObjectFromEvent(headerHandle, winUser.OBJID_CLIENT, 0) return headerParent
def timeRemaining(): hwnd = readOrRecord() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sActual = o.value if sActual != '' and not sActual.isspace() and ' ' in sActual: sActual = sActual.split(': ') sActual = sActual[2].split() sActual = sActual[0] sTotal = o.value sTotal = sTotal.split(': ') sTotal = sTotal[1] sTotal = sTotal.split(' ')[0] if sTotal == sActual: # Translators: Message to inform the user that there is no remaining time. return _('No time remaining !') hORm = len(sTotal.split('.')[1]) fmt = "%H:%M'%S.%f" if not ':' in sActual: sActual = u'0:{0}'.format(sActual) if not ':' in sTotal: sTotal = u'0:{0}'.format(sTotal) result = datetime.strptime(sTotal, fmt) - datetime.strptime(sActual, fmt) result = str(result).decode('utf-8') result = result.replace(':', "'") result = result.replace("'", ':', 1) result = result[:-4] if hORm == 2 else result[:-3] return timeSplitter(result)
def getHeaderFieldObject(self, nField): dicHeaderFields = self.getHeaderFieldsFun() try: cid, name = dicHeaderFields[nField] except KeyError: msg = f'The key {nField} is not present in the dictionary {dicHeaderFields}' raise HeaderFieldNotFoundeError(msg) if isinstance(cid, tuple): cids = cid else: cids = (cid, ) if self.rootDialog.name != 'Fake root': msgList = [] for cid in cids: try: handle = findDescendantWindow(self.rootDialog.windowHandle, controlID=cid) if handle: obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) if controlTypes.State.INVISIBLE in obj.states: msgList.append( f'Object (cid={obj.windowControlID}) is invisible' ) else: break else: msgList.append(f'Handle={handle} found for cid={cid}') except LookupError: msgList.append(f'LookupError for cid={cid}') else: msg = f'No window found for cids={cids}. Details below:\n' + '\n'.join( msgList) raise HeaderFieldNotFoundeError(msg) else: log.debug('FakeRootDialog') obj = [ o for o in self.rootDialog.children if o.windowControlID in cids ] nObj = len(obj) if nObj != 1: infoDic = { 'obj': obj, 'children': str([o.windowControlID for o in self.rootDialog.children]), 'cids': cids, 'name': name, } info = '\n'.join(f'{k}: {v}' for (k, v) in infoDic.items()) msg = f'Fake root window: {nObj} objects found, 1 expected. Info =\n{info}' raise HeaderFieldNotFoundeError(msg) obj = obj[0] if controlTypes.State.INVISIBLE in obj.states: msg = f'Object (cid={obj.windowControlID}) is invisible' raise HeaderFieldNotFoundeError(msg) return obj, name
def getForegroundObject(): hdMain = ctypes.windll.user32.GetForegroundWindow() if not getString( vlc_strings.ID_VLCAppTitle) in winUser.getWindowText(hdMain): hdMain = winUser.getWindow(winUser.getWindow(hdMain, 2), 2) o = getNVDAObjectFromEvent(hdMain, -4, 0) return o
def script_reportCurrentSelection(self, gesture): parentHandle = self.parent.windowHandle # index of first selected item # use -1 to query first list item too # with index 0L selItemIndex = watchdog.cancellableSendMessage(parentHandle, LVM_GETNEXTITEM, -1, LParam(LVNI_SELECTED)) listLen = watchdog.cancellableSendMessage(parentHandle, LVM_GETITEMCOUNT, 0, 0) items = [] while (0 <= selItemIndex < listLen): item = getNVDAObjectFromEvent(parentHandle, winUser.OBJID_CLIENT, selItemIndex + 1) itemChild = item.getChild(0) itemName = itemChild.name if itemChild else item.name if itemName: items.append(itemName) # index of next selected item selItemIndex = watchdog.cancellableSendMessage( parentHandle, LVM_GETNEXTITEM, selItemIndex, LParam(LVNI_SELECTED)) spokenItems = ', '.join(items) ui.message("%d %s: %s" % ( len(items), # translators: message presented when get selected item count and names _("selected items"), spokenItems))
def _get_word(self): wordWindowHandle = windll.user32.GetDlgItem(self.windowHandle, IDC_SPELLING_WORD) wordObject = getNVDAObjectFromEvent(wordWindowHandle, winUser.OBJID_CLIENT, 0) if controlTypes.STATE_INVISIBLE in wordObject.states: return "" return wordObject.name
def getHeader(self): try: return self.header except AttributeError: #handle = findDescendantWindow(api.getForegroundObject().windowHandle, controlID=138, className='SysHeader32') handle = findDescendantWindow(self.parent.windowHandle, controlID=138, className='SysHeader32') self.header = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) self.allowIAccessibleChildIDAndChildCountForPositionInfo = True return self.header
def getInfoBarObj(self): try: cid = self.getInfoBarControlId() obj = getNVDAObjectFromEvent( findDescendantWindow(api.getForegroundObject().windowHandle, visible=True, className=None, controlID=cid), winUser.OBJID_CLIENT, 0) except LookupError: obj = None return obj
def isStarting(): focus = api.getFocusObject() if focus.role == ROLE_PANE and focus.name == u'mp3DirectCut': hwnd = readOrRecord() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sStarting = o.value if not sStarting: return True return False
def totalTime(): if checkPart() or checkSelection(): hwnd = readOrRecord() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sTime = o.value sTime = sTime.split(': ') sTime = sTime[1].split(' ')[0] sTotal = timeSplitter(sTime) return sTotal
def actualDurationPercentage(): hwnd = readOrRecord() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sActual = o.value if '(' in sActual: sActual = sActual.split('(') sActual = sActual[1] sActual = sActual[:-1] return sActual
def actualDuration(): hwnd = readOrRecord() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sActual = o.value if sActual and not sActual.isspace() and ' ' in sActual: sActual = sActual.split(': ') sActual = sActual[2].split() sActual = sActual[0] sActual = timeSplitter(sActual) return sActual
def beginSelection(): if checkSelection(): fg = api.getForegroundObject() hwnd = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) text = o.value beginSelection = text.split(' - ') beginSelection = beginSelection[0] beginSelection = beginSelection.split()[1] return timeSplitter(beginSelection)
def selectionDuration(): if checkSelection(): fg = api.getForegroundObject() hwnd = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) text = o.value selectionDuration = text.split('(') selectionDuration = selectionDuration[1] selectionDuration = selectionDuration[:-1] return timeSplitter(selectionDuration)
def checkSelection(): fg = api.getForegroundObject() hwnd = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) text = o.value if text and not text.isspace(): text = text.split() if text[0].endswith(':'): return True return False
def isRecording(): fg = api.getForegroundObject() hwnd = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) text = o.value if text and not text.isspace(): text = text.split() if text[1].startswith("'"): return True return False
def isReading(): fg = api.getForegroundObject() o = fg.firstChild.firstChild.lastChild.firstChild hwnd = o.windowHandle childID = o.childCount - 1 readingBtn = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, childID) if all(x in readingBtn.states for x in [STATE_SYSTEM_INDETERMINATE, STATE_SYSTEM_MIXED]): return True return False
def script_focusToMessageBody(self, gesture): try: obj = getNVDAObjectFromEvent( findDescendantWindow(api.getForegroundObject().windowHandle, visible=True, className=None, controlID=4159), winUser.OBJID_CLIENT, 0) except LookupError: # Translators: Error when trying to move focus in message body ui.message(_("Not in a message window")) return obj.setFocus()
def script_touchKeyboardEnable(self, gesture): # Locate the touch keyboard button and activate it, simulating JAWS 17 gesture. keyboardButtonHwnd = windowUtils.findDescendantWindow( api.getDesktopObject().windowHandle, className="TIPBand") touchKeyboardButton = getNVDAObjectFromEvent(keyboardButtonHwnd, winUser.OBJID_CLIENT, 0) try: touchKeyboardButton.doAction() tones.beep(1000, 150) except NotImplementedError: # Translators: message shown when touch keyboard button is not found. ui.message(_("Cannot activate touch keyboard"))
def part(flag=None): if checkPart(): fg = api.getForegroundObject() hwnd = windowUtils.findDescendantWindow(fg.windowHandle, controlID=160) o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) text = o.value text = text.split('(') text = text[1] text = text.split(')') text = text[0] text = text.replace(u'/', ' {0} '.format(_('of'))) return u'{0} {1}'.format(announce[10], text) if not flag else '{0} {1}'.format( _('Part'), text)
def getHeaderFieldObject(self, nField): try: cid,name = self.getHeaderFieldsFun()[nField] except KeyError: raise HeaderFieldNotFoundeError() try: handle = findDescendantWindow(self.rootDialog.windowHandle, controlID=cid) if handle: obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) except: raise HeaderFieldNotFoundeError() if controlTypes.STATE_INVISIBLE in obj.states: raise HeaderFieldNotFoundeError() return obj,name
def getAttachmentInfos2016(self): fg = api.getForegroundObject() cidAttachments=4306 handle = findDescendantWindow(fg.windowHandle, className=None, controlID=cidAttachments) obj = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) try: o = obj while o.role != controlTypes.ROLE_BUTTON: o = o.firstChild attachmentsList = [a for a in o.parent.children if a.role == controlTypes.ROLE_BUTTON] except AttributeError: attachmentsList = [] namesGen = (child.firstChild.getChild(1).name for child in attachmentsList) return attachmentsList,handle,namesGen,obj.name
def findInList(self, text, reverse, caseSensitive, stopCheck=lambda: False): """performs search in item list, via object handles.""" # specific implementation fg = api.getForegroundObject() listHandles = findAllDescendantWindows(fg.windowHandle, controlID=self.windowControlID) thisList = None # there may be different lists with same controlID (see eMule) for handle in listHandles: tempList = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) if tempList == self.simpleParent: thisList = tempList break # if handle approach fails, use generic method if not thisList: res = super(ColumnsReview32, self).findInList(text, reverse, caseSensitive) return res listLen = self.positionInfo["similarItemsInGroup"] # 1-based index curIndex = self.positionInfo["indexInGroup"] if reverse: indexes = rangeFunc(curIndex - 1, 0, -1) else: indexes = rangeFunc(curIndex + 1, listLen + 1) for index in indexes: item = getNVDAObjectFromEvent(thisList.windowHandle, winUser.OBJID_CLIENT, index) if ((not caseSensitive and text.lower() in item.name.lower()) or (caseSensitive and text in item.name)): return item if stopCheck(): break
def expressSearch(self): """search toolbars using windows handles.""" barHandles = findAllDescendantWindows( api.getForegroundObject().windowHandle, visible=True) debugLog("Found %d handles" % len(barHandles)) for handle in barHandles: bar = getNVDAObjectFromEvent(handle, winUser.OBJID_CLIENT, 0) if not bar: continue if bar.role == roles.TOOLBAR: self.bars.append(bar) # some handles carry to invisible simpleParent # i.e. in Windows explorer elif not bar.isFocusable and (bar.role in self.promisingRoles or bar.role in self.lessPromisingRoles): # indeed, here child may be a toolbar, and bar its parent for child in bar.children: if child.role == roles.TOOLBAR: self.bars.append(child)
def script_vuMeter(self, gesture): gesture.send() if isStarting(): sayMessage(announce[3]) return h = self.windowHandle hwnd = vuMeterHandle() repeat = getLastScriptRepeatCount() o = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) sLevel = o.value if sLevel: if repeat == 0: sayMessage(announce[7] + ' : ' + sLevel) elif repeat == 1: setFocus(hwnd) mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, None, None) mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, None, None) sayMessage(announce[19]) setFocus(h) else: sayMessage(announce[18])
def script_SPLControllerPrefix(self, gesture): global SPLWin # Error checks: # 1. If SPL Studio is not running, print an error message. # 2. If we're already in SPL, ask the app module if SPL Assistant can be invoked with this command. if "splstudio" in api.getForegroundObject().appModule.appModuleName: if not api.getForegroundObject().appModule.SPLConPassthrough(): # Translators: Presented when NVDA cannot enter SPL Controller layer since SPL Studio is focused. ui.message(_("You are already in SPL Studio window. For status commands, use SPL Assistant commands.")) self.finish() return else: api.getForegroundObject().appModule.script_SPLAssistantToggle(gesture) return SPLWin = user32.FindWindowW(u"SPLStudio", None) if SPLWin == 0: # Translators: Presented when Station Playlist Studio is not running. ui.message(_("SPL Studio is not running.")) self.finish() return # No errors, so continue. if not self.SPLController: self.bindGestures(self.__SPLControllerGestures) # 17.12: also bind cart keys. # Exclude number row if Studio Standard is running. cartKeys = self.fnCartKeys if not getNVDAObjectFromEvent(user32.FindWindowW(u"TStudioForm", None), OBJID_CLIENT, 0).name.startswith("StationPlaylist Studio Standard"): cartKeys+=self.numCartKeys for cart in cartKeys: self.bindGesture("kb:%s"%cart, "cartsWithoutBorders") self.bindGesture("kb:shift+%s"%cart, "cartsWithoutBorders") self.bindGesture("kb:control+%s"%cart, "cartsWithoutBorders") self.bindGesture("kb:alt+%s"%cart, "cartsWithoutBorders") self.SPLController = True # Translators: The name of a layer command set for Station Playlist Studio. # Hint: it is better to translate it as "SPL Control Panel." ui.message(_("SPL Controller")) else: self.script_error(gesture) self.finish()
def getTextFromWindow(hwnd): obj = getNVDAObjectFromEvent(hwnd, OBJID_CLIENT, CHILDID_SELF) return obj.value
def script_cancel(self, gesture): buttonWindowHandle = windll.user32.GetDlgItem(self.windowHandle, IDCANCEL) button = getNVDAObjectFromEvent(buttonWindowHandle, winUser.OBJID_CLIENT, 0) button.doAction()
def script_touchKeyboardEnable(self, gesture): # Locate the touch keyboard button and activate it, simulating JAWS 17 gesture. keyboardButtonHwnd = windowUtils.findDescendantWindow(api.getDesktopObject().windowHandle, className="TIPBand") touchKeyboardButton = getNVDAObjectFromEvent(keyboardButtonHwnd, winUser.OBJID_CLIENT, 0) touchKeyboardButton.doAction() tones.beep(1000, 150)
def script_nextTrackTitle(self, gesture): studioAppMod = getNVDAObjectFromEvent(user32.FindWindowW(u"TStudioForm", None), OBJID_CLIENT, 0).appModule studioAppMod.script_sayNextTrackTitle(None) self.finish()