示例#1
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)
示例#2
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)
示例#3
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 _setCaretOffset(self, offset):
     rects = self._storyFieldsAndRects[1]
     if offset >= len(rects):
         raise RuntimeError("offset %d out of range")
     rect = rects[offset]
     # Place the cursor at the left coordinate of the character, vertically centered.
     point = Point(rect.left, rect.center.y)
     try:
         point = point.toPhysical(self.obj.windowHandle)
     except RuntimeError:
         raise RuntimeError(
             "Conversion to physical coordinates failed when setting caret offset"
         )
     oldX, oldY = winUser.getCursorPos()
     winUser.setCursorPos(*point)
     mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTDOWN, 0, 0)
     mouseHandler.executeMouseEvent(winUser.MOUSEEVENTF_LEFTUP, 0, 0)
     winUser.setCursorPos(oldX, oldY)
示例#5
0
	def kwargsFromSuper(cls,kwargs,relation=None):
		IAccessibleObject=kwargs['IAccessibleObject']
		#MSHTML should not be used for MSAA child elements.
		#However, objectFromPoint can hit an MSAA child element but we still should try MSHTML's own elementFromPoint even in this case.
		if kwargs.get('IAccessibleChildID') and not isinstance(relation,tuple):
			return False
		HTMLNode=None
		try:
			HTMLNode=HTMLNodeFromIAccessible(IAccessibleObject)
		except NotImplementedError:
			pass
		if not HTMLNode:
			return False

		if relation=="focus":
			# #4045: we must recurse into frames ourselves when fetching the active element of a document. 
			while True:
				try:
					HTMLNode=HTMLNode.document.activeElement
				except:
					log.exception("Error getting activeElement")
					break
				nodeName=HTMLNode.nodeName or ""
				if nodeName.lower() not in ("frame","iframe"):
					# The IAccessibleObject may be incorrect now, so let the constructor recalculate it.
					del kwargs['IAccessibleObject']
					break
				childElement=getChildHTMLNodeFromFrame(HTMLNode)
				if not childElement:
					break
				HTMLNode=childElement
			
		elif isinstance(relation,tuple):
			windowHandle=kwargs.get('windowHandle')
			if not windowHandle:
				log.debugWarning("Error converting point to client coordinates, no window handle")
				return False
			try:
				point = Point(*relation).toClient(windowHandle)
			except WindowsError:
				log.debugWarning("Error converting point to client coordinates", exc_info=True)
				return False
			# #3494: MSHTML's internal coordinates are always at a hardcoded DPI (usually 96) no matter the system DPI or zoom level.
			xFactor,yFactor=getZoomFactorsFromHTMLDocument(HTMLNode.document)
			try:
				HTMLNode = HTMLNode.document.elementFromPoint(point.x // xFactor, point.y // yFactor)
			except:
				HTMLNode = None
			if not HTMLNode:
				log.debugWarning("Error getting HTMLNode with elementFromPoint")
				return False
			del kwargs['IAccessibleObject']
			del kwargs['IAccessibleChildID']
		kwargs['HTMLNode']=HTMLNode
		return True
示例#6
0
	def test_ctypesPOINT(self):
		# Add
		self.assertEqual(Point(x=2, y=4)+POINT(x=2, y=4),Point(x=4, y=8))
		self.assertEqual(POINT(x=2, y=4)+Point(x=2, y=4),Point(x=4, y=8))
		# Sum
		self.assertEqual(sum((Point(x=2, y=4), POINT(x=2, y=4), Point(x=2, y=4))), Point(x=6, y=12))
		# Subtract
		self.assertEqual(Point(x=2, y=4)-POINT(x=4, y=8),Point(x=-2, y=-4))
		self.assertEqual(POINT(x=2, y=4)-Point(x=4, y=8),Point(x=-2, y=-4))
		# Greater than
		self.assertTrue(Point(x=3, y=4).yWiseGreaterThan(POINT(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).xWiseGreaterThan(POINT(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).xWiseGreaterThan(POINT(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).yWiseGreaterThan(POINT(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).yWiseGreaterOrEq(POINT(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).xWiseGreaterOrEq(POINT(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).xWiseGreaterOrEq(POINT(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).yWiseGreaterOrEq(POINT(x=3, y=4)))
		# Less than
		self.assertTrue(Point(x=4, y=3).yWiseLessThan(POINT(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).xWiseLessThan(POINT(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).xWiseLessThan(POINT(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).yWiseLessThan(POINT(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).yWiseLessOrEq(POINT(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).xWiseLessOrEq(POINT(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).xWiseLessOrEq(POINT(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).yWiseLessOrEq(POINT(x=4, y=3)))
		# Equality
		self.assertEqual(POINT(x=4, y=3), Point(x=4, y=3))
		self.assertNotEqual(POINT(x=3, y=4), Point(x=4, y=3))
示例#7
0
	def test_equal(self):
		self.assertEqual(Point(x=4, y=3), Point(x=4, y=3))
		self.assertNotEqual(Point(x=3, y=4), Point(x=4, y=3))
示例#8
0
	def test_lessThan(self):
		self.assertTrue(Point(x=4, y=3).yWiseLessThan(Point(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).xWiseLessThan(Point(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).xWiseLessThan(Point(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).yWiseLessThan(Point(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).yWiseLessOrEq(Point(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).xWiseLessOrEq(Point(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).xWiseLessOrEq(Point(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).yWiseLessOrEq(Point(x=4, y=3)))
示例#9
0
	def test_greaterThan(self):
		self.assertTrue(Point(x=3, y=4).yWiseGreaterThan(Point(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).xWiseGreaterThan(Point(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).xWiseGreaterThan(Point(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).yWiseGreaterThan(Point(x=3, y=4)))
		self.assertTrue(Point(x=3, y=4).yWiseGreaterOrEq(Point(x=4, y=3)))
		self.assertFalse(Point(x=3, y=4).xWiseGreaterOrEq(Point(x=4, y=3)))
		self.assertTrue(Point(x=4, y=3).xWiseGreaterOrEq(Point(x=3, y=4)))
		self.assertFalse(Point(x=4, y=3).yWiseGreaterOrEq(Point(x=3, y=4)))
示例#10
0
	def test_sub(self):
		self.assertEqual(Point(x=2, y=4)-Point(x=4, y=8),Point(x=-2, y=-4))
示例#11
0
	def test_sum(self):
		point=Point(x=2, y=4)
		self.assertEqual(sum((point, point, point)), Point(x=6, y=12))
示例#12
0
	def test_add(self):
		self.assertEqual(Point(x=2, y=4)+Point(x=2, y=4),Point(x=4, y=8))