From c7d7298cdfc6a5a9c6997859511d55a48302bc28 Mon Sep 17 00:00:00 2001 From: "hank.huang" <44250052+letmeNo1@users.noreply.github.com> Date: Sun, 21 May 2023 20:21:15 +0800 Subject: [PATCH] add new interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在我们有一个场景是 1234567 | 连接 1234568 | 连接 1234569 | 连接 1234566 | 连接 而元素列表如下: "12345.." 和 "connect" 全部在同一个层级,没有对应的关系 我无法直通过左边的数字定位到右边的connect的按键,因此加了这三个接口,用于方便直接获取某个元素的上一个和下一个兄弟节点,以及自身所处在的子集中的索引值 --- poco/proxy.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ poco/proxy.pyi | 9 ++++++++ 2 files changed, 71 insertions(+) diff --git a/poco/proxy.py b/poco/proxy.py index 77886b92..88ec1666 100644 --- a/poco/proxy.py +++ b/poco/proxy.py @@ -889,3 +889,65 @@ def _do_query(self, multiple=True, refresh=False): self._evaluated = True self._query_multiple = multiple return self._nodes + + def index(self): + """ + Returns the index of this element in all the child nodes of the parent node + + """ + sibling = self.sibling() + if not sibling._query_multiple: + nodes = sibling._do_query(multiple=True, refresh=True) + else: + nodes = sibling._nodes + current_pos = self.get_position(focus="anchor") + for i, node in enumerate(nodes,start=1): + if node.getAttr('pos') == current_pos: + return i + + def last_sibling(self): + """ + Returns the sibling to the left of an element + + """ + sibling = self.sibling() + if not sibling._query_multiple: + nodes = sibling._do_query(multiple=True, refresh=True) + else: + nodes = sibling._nodes + current_pos = self.get_position(focus="anchor") + rst = None + for i, node in enumerate(nodes): + if node.getAttr('pos') == current_pos: + uiobj = UIObjectProxy(self.poco) + uiobj.query = ('index', (self.query, i - 1)) + uiobj._evaluated = True + uiobj._query_multiple = True + uiobj._nodes = nodes[i - 1] + uiobj._nodes_proxy_is_list = False + rst = uiobj + return rst + + def next_sibling(self): + """ + Returns the sibling to the left of an element + """ + sibling = self.sibling() + if not sibling._query_multiple: + nodes = sibling._do_query(multiple=True, refresh=True) + else: + nodes = sibling._nodes + current_pos = self.get_position(focus="anchor") + rst = None + for i, node in enumerate(nodes): + if node.getAttr('pos') == current_pos: + uiobj = UIObjectProxy(self.poco) + uiobj.query = ('index', (self.query, i + 1)) + uiobj._evaluated = True + uiobj._query_multiple = True + uiobj._nodes = nodes[i + 1] + uiobj._nodes_proxy_is_list = False + rst = uiobj + return rst + + diff --git a/poco/proxy.pyi b/poco/proxy.pyi index bdc60b08..a8d134a4 100644 --- a/poco/proxy.pyi +++ b/poco/proxy.pyi @@ -102,3 +102,12 @@ class UIObjectProxy(object): def _direction_vector_of(self, dir_: (float, float)) -> (float, float): ... + + def next_sibling(self) -> UIObjectProxy: + ... + + def last_sibling(self) -> UIObjectProxy: + ... + + def index(self) -> UIObjectProxy: + ...