MCPcopy
hub / github.com/AirtestProject/Poco / get_position

Method get_position

poco/proxy.py:596–627  ·  view source on GitHub ↗

Get the position of the UI elements. Args: focus: focus point of UI proxy, see :py:meth:`.focus() ` for more details Returns: 2-list/2-tuple: coordinates (x, y) in NormalizedCoordinate system Raises:

(self, focus=None)

Source from the content-addressed store, hash-verified

594
595 @volatile_attribute
596 def get_position(self, focus=None):
597 """
598 Get the position of the UI elements.
599
600 Args:
601 focus: focus point of UI proxy, see :py:meth:`.focus() <poco.proxy.UIObjectProxy.focus>` for more details
602
603 Returns:
604 2-list/2-tuple: coordinates (x, y) in NormalizedCoordinate system
605
606 Raises:
607 TypeError: raised when unsupported focus type is specified
608 """
609 focus = focus or self._focus or 'center'
610 if focus == 'anchor':
611 pos = list(map(float, self.attr('pos')))
612 elif focus == 'center':
613 x, y = map(float, self.attr('pos'))
614 w, h = self.get_size()
615 ap_x, ap_y = map(float, self.attr("anchorPoint"))
616 fx, fy = 0.5, 0.5
617 pos = [x + w * (fx - ap_x), y + h * (fy - ap_y)]
618 elif type(focus) in (list, tuple):
619 x, y = map(float, self.attr('pos'))
620 w, h = self.get_size()
621 ap_x, ap_y = map(float, self.attr("anchorPoint"))
622 fx, fy = focus
623 pos = [x + w * (fx - ap_x), y + h * (fy - ap_y)]
624 else:
625 raise TypeError('Unsupported focus type {}. '
626 'Only "anchor/center" or 2-list/2-tuple available.'.format(type(focus)))
627 return pos
628
629 def _direction_vector_of(self, dir_):
630 if dir_ == 'up':

Callers 14

__getitem__Method · 0.95
__iter__Method · 0.95
clickMethod · 0.95
rclickMethod · 0.95
double_clickMethod · 0.95
long_clickMethod · 0.95
swipeMethod · 0.95
drag_toMethod · 0.95
pinchMethod · 0.95
get_boundsMethod · 0.95
__init__Method · 0.80
toMethod · 0.80

Calls 2

attrMethod · 0.95
get_sizeMethod · 0.95

Tested by

no test coverage detected