def getWindowTextInRect(bindingHandle, windowHandle, left, top, right, bottom, minHorizontalWhitespace, minVerticalWhitespace, stripOuterWhitespace=True, includeDescendantWindows=True): text, cpBuf = watchdog.cancellableExecute( _getWindowTextInRect, bindingHandle, windowHandle, includeDescendantWindows, left, top, right, bottom, minHorizontalWhitespace, minVerticalWhitespace, stripOuterWhitespace) if not text or not cpBuf: return u"", [] characterLocations = [] cpBufIt = iter(cpBuf) for cp in cpBufIt: left, top, right, bottom = (wcharToInt(cp), wcharToInt(next(cpBufIt)), wcharToInt(next(cpBufIt)), wcharToInt(next(cpBufIt))) if right < left: left, right = right, left characterLocations.append(RectLTRB(left, top, right, bottom)) return text, characterLocations
def _get_location(self): pointLeft=self.ppObject.left pointTop=self.ppObject.top pointWidth=self.ppObject.width pointHeight=self.ppObject.height left=self.documentWindow.ppObjectModel.pointsToScreenPixelsX(pointLeft) top=self.documentWindow.ppObjectModel.pointsToScreenPixelsY(pointTop) right=self.documentWindow.ppObjectModel.pointsToScreenPixelsX(pointLeft+pointWidth) bottom=self.documentWindow.ppObjectModel.pointsToScreenPixelsY(pointTop+pointHeight) return RectLTRB(left,top,right,bottom).toLTWH()
def getCaretRect(obj): left = ctypes.c_long() top = ctypes.c_long() right = ctypes.c_long() bottom = ctypes.c_long() res = watchdog.cancellableExecute( NVDAHelper.localLib.displayModel_getCaretRect, obj.appModule.helperLocalBindingHandle, obj.windowThreadID, ctypes.byref(left), ctypes.byref(top), ctypes.byref(right), ctypes.byref(bottom)) if res != 0: raise RuntimeError(f"displayModel_getCaretRect failed with res {res}") return RectLTRB(left.value, top.value, right.value, bottom.value)
def _get_location(self): if self.HTMLNodeName and not self.HTMLNodeName.startswith('#'): try: r=self.HTMLNode.getBoundingClientRect() except COMError: return None # #3494: MSHTML's internal coordinates are always at a hardcoded DPI (usually 96) no matter the system DPI or zoom level. xFactor,yFactor=self.zoomFactors left=int(r.left*xFactor) top=int(r.top*yFactor) right=int(r.right*xFactor) bottom=int(r.bottom*yFactor) return RectLTRB(left,top,right,bottom).toScreen(self.windowHandle).toLTWH() return None
def getImageFromSource(self, current_source): if current_source == "clipboardImage": recognizeImage = self.getImageFromClipboard() imageInfo = RecogImageInfo(0, 0, recognizeImage.width, recognizeImage.height, 1) return imageInfo, recognizeImage elif current_source == "clipboardURL": return None elif current_source == "foreGroundWindow": foregroundWindow = winUser.getForegroundWindow() desktopWindow = winUser.getDesktopWindow() foregroundRect = RECT() desktopRect = RECT() winUser.user32.GetWindowRect(foregroundWindow, byref(foregroundRect)) winUser.user32.GetWindowRect(desktopWindow, byref(desktopRect)) left = max(foregroundRect.left, desktopRect.left) right = min(foregroundRect.right, desktopRect.right) top = max(foregroundRect.top, desktopRect.top) bottom = min(foregroundRect.bottom, desktopRect.bottom) if right <= left or bottom <= top: ui.message(_("Current window position is invalid.")) return from locationHelper import RectLTRB windowRectLTRB = RectLTRB( left=left, right=right, top=top, bottom=bottom ) imageInfo = RecogImageInfo( windowRectLTRB.left, windowRectLTRB.top, windowRectLTRB.width, windowRectLTRB.height, 1 ) recognizeImage = ImageGrab.grab(( windowRectLTRB.top, windowRectLTRB.left, windowRectLTRB.width, windowRectLTRB.height )) return imageInfo, recognizeImage elif current_source == "wholeDesktop": recognizeImage = ImageGrab.grab() imageInfo = RecogImageInfo(0, 0, recognizeImage.width, recognizeImage.height, 1) return imageInfo, recognizeImage else: # Translators: Reported when source is not correct. ui.message(_("Unknown source: %s" % current_source)) return None
def test_ctypesRECT(self): # Intersection self.assertEqual(RectLTRB(left=2, top=2, right=4, bottom=4).intersection(RECT(left=3, top=3, right=5, bottom=5)), RectLTRB(left=3, top=3, right=4, bottom=4)) # Superset self.assertTrue(RectLTRB(left=2, top=2, right=6, bottom=6).isSuperset(RECT(left=2, top=2, right=4, bottom=4))) # Subset self.assertTrue(RectLTRB(left=2, top=2, right=4, bottom=4).isSubset(RECT(left=2, top=2, right=6, bottom=6))) # in self.assertIn(RECT(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=6, bottom=6)) self.assertNotIn(RECT(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=4, bottom=4)) # Equality self.assertEqual(RECT(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=4, bottom=4)) self.assertNotEqual(RECT(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=6, bottom=6))
def _getColumnLocationRaw(self, index): processHandle = self.processHandle # LVM_GETSUBITEMRECT requires a pointer to a RECT structure that will receive the subitem bounding rectangle information. localRect = RECT( # Returns the bounding rectangle of the entire item, including the icon and label. left=LVIR_LABEL, # According to Microsoft, top should be the one-based index of the subitem. # However, indexes coming from LVM_GETCOLUMNORDERARRAY are zero based. top=index) internalRect = winKernel.virtualAllocEx(processHandle, None, sizeof(localRect), winKernel.MEM_COMMIT, winKernel.PAGE_READWRITE) try: winKernel.writeProcessMemory(processHandle, internalRect, byref(localRect), sizeof(localRect), None) res = watchdog.cancellableSendMessage(self.windowHandle, LVM_GETSUBITEMRECT, self.IAccessibleChildID - 1, internalRect) if res: winKernel.readProcessMemory(processHandle, internalRect, ctypes.byref(localRect), ctypes.sizeof(localRect), None) finally: winKernel.virtualFreeEx(processHandle, internalRect, 0, winKernel.MEM_RELEASE) if res == 0: log.debugWarning( f"LVM_GETSUBITEMRECT failed for index {index} in list") return None # #8268: this might be a malformed rectangle # (i.e. with a left coordinate that is greater than the right coordinate). # This happens in Becky! Internet Mail, # as well in applications that expose zero width columns. left = localRect.left top = localRect.top right = localRect.right bottom = localRect.bottom if left > right: left = right if top > bottom: top = bottom return RectLTRB(left, top, right, bottom).toScreen(self.windowHandle).toLTWH()
def _getColumnLocationRaw(self, index: int) -> Optional[RectLTRB]: if not self.appModule.helperLocalBindingHandle: rect = self._getColumnLocationRawOutProc(index) else: rect = self._getColumnLocationRawInProc(index) if rect is None: return None # #8268: this might be a malformed rectangle # (i.e. with a left coordinate that is greater than the right coordinate). # This happens in Becky! Internet Mail, # as well in applications that expose zero width columns. left = rect.left top = rect.top right = rect.right bottom = rect.bottom if left > right: left = right if top > bottom: top = bottom return RectLTRB(left, top, right, bottom).toScreen(self.windowHandle).toLTWH()
def test_equal(self): self.assertEqual(RectLTRB(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=4, bottom=4)) self.assertNotEqual(RectLTRB(left=2, top=2, right=4, bottom=4), RectLTRB(left=2, top=2, right=6, bottom=6)) self.assertEqual(RectLTRB(left=2, top=2, right=4, bottom=4), RectLTWH(left=2, top=2, width=2, height=2)) self.assertNotEqual(RectLTRB(left=2, top=2, right=4, bottom=4), RectLTWH(left=2, top=2, width=4, height=4))
def test_subset(self): self.assertTrue(RectLTRB(left=2, top=2, right=4, bottom=4).isSubset(RectLTRB(left=2, top=2, right=6, bottom=6))) self.assertFalse(RectLTRB(left=2, top=2, right=6, bottom=6).isSubset(RectLTRB(left=2, top=2, right=4, bottom=4))) self.assertTrue(RectLTRB(left=2, top=2, right=6, bottom=6).isSubset(RectLTRB(left=2, top=2, right=6, bottom=6)))
def test_intersection(self): self.assertEqual(RectLTRB(left=2, top=2, right=4, bottom=4).intersection(RectLTRB(left=3, top=3, right=5, bottom=5)), RectLTRB(left=3, top=3, right=4, bottom=4)) self.assertEqual(RectLTRB(left=2, top=2, right=4, bottom=4).intersection(RectLTRB(left=5, top=5, right=7, bottom=7)), RectLTRB(left=0, top=0, right=0, bottom=0))
def test_fromFloatCollection(self): self.assertEqual(RectLTRB(left=10, top=10, right=20, bottom=20), RectLTRB.fromFloatCollection(10.0, 10.0, 20.0, 20.0)) self.assertEqual(RectLTWH(left=10, top=10, width=20, height=20), RectLTWH.fromFloatCollection(10.0, 10.0, 20.0, 20.0))