예제 #1
0
	def test_collection(self):
		"""Tests whether a collection of several rectangle and point types convert to the expected L{RectLTRB}."""
		rect=RectLTRB(left=10, top=15, right=500, bottom=1000)
		self.assertEqual(RectLTRB.fromCollection(
			rect.topLeft,
			rect.bottomRight,
			rect.center,
			Point(15, 15),
			Point(20, 20),
			Point(50, 50),
			Point(400, 400),
			POINT(x=15, y=15),
			POINT(x=20, y=20),
			POINT(x=50, y=50),
			POINT(x=400, y=400),
			RectLTRB(left=450, top=450, right=490, bottom=990),
			RECT(450, 450, 490, 990)
		), rect)

		location=RectLTWH(left=10, top=15, width=500, height=1000)
		self.assertEqual(RectLTWH.fromCollection(
			location.topLeft,
			location.bottomRight,
			location.center,
			Point(15, 15),
			Point(20, 20),
			Point(50, 50),
			Point(400, 400),
			POINT(x=15, y=15),
			POINT(x=20, y=20),
			POINT(x=50, y=50),
			POINT(x=400, y=400),
			RectLTRB(left=450, top=450, right=505, bottom=1010),
			RECT(450, 450, 490, 990)
		), location)
예제 #2
0
	def test_in(self):
		rect = RectLTRB(left=2, top=2, right=6, bottom=6)
		self.assertIn(RectLTRB(left=2, top=2, right=4, bottom=4), rect)
		self.assertNotIn(rect, rect)
		self.assertIn(Point(x=2, y=2), rect)
		self.assertIn(Point(x=4, y=4), rect)
		self.assertNotIn(Point(x=2, y=6), rect)
		self.assertNotIn(Point(x=6, y=2), rect)
		self.assertNotIn(Point(x=6, y=6), rect)
예제 #3
0
	def test_expandOrShrink(self):
		"""Tests the expand or shrink functionality to resize a rectangle given a specified margin."""
		rect = RectLTRB(left=10, top=10, right=20, bottom=20)
		self.assertEqual(rect.expandOrShrink(10), RectLTRB(left=0, top=0, right=30, bottom=30))
		self.assertEqual(rect.expandOrShrink(-2), RectLTRB(left=12, top=12, right=18, bottom=18))
		self.assertRaises(RuntimeError, rect.expandOrShrink, -10)

		location = RectLTWH(left=10, top=10, width=10, height=10)
		self.assertEqual(location.expandOrShrink(10), RectLTWH(left=0, top=0, width=30, height=30))
		self.assertEqual(location.expandOrShrink(-2), RectLTWH(left=12, top=12, width=6, height=6))
		self.assertRaises(RuntimeError, location.expandOrShrink, -10)
예제 #4
0
	def test_points(self):
		rect = RectLTRB(left=-5, top=-5, right=5, bottom=5)
		self.assertEqual(rect.topLeft, Point(x=-5, y=-5))
		self.assertEqual(rect.topRight, Point(x=5, y=-5))
		self.assertEqual(rect.bottomLeft, Point(x=-5, y=5))
		self.assertEqual(rect.bottomRight, Point(x=5, y=5))
		self.assertEqual(rect.center, Point(x=0, y=0))
		# Specifically test some other edge cases for center
		self.assertEqual(RectLTRB(left=10, top=10, right=20, bottom=20).center, Point(x=15, y=15))
		self.assertEqual(RectLTRB(left=-20, top=-20, right=-10, bottom=-10).center, Point(x=-15, y=-15))
		self.assertEqual(RectLTRB(left=10, top=10, right=21, bottom=21).center, Point(x=16, y=16))
		self.assertEqual(RectLTRB(left=-21, top=-21, right=-10, bottom=-10).center, Point(x=-16, y=-16))
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
예제 #6
0
파일: powerpnt.py 프로젝트: tsengwoody/nvda
	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)
예제 #8
0
파일: MSHTML.py 프로젝트: shaleenp/nvda
	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
예제 #9
0
	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
예제 #10
0
	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))
예제 #11
0
 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()
예제 #12
0
 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()
예제 #13
0
	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))
예제 #14
0
	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)))
예제 #15
0
	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))
예제 #16
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))