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)
| 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': |
no test coverage detected