Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new interface #586

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions poco/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


9 changes: 9 additions & 0 deletions poco/proxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
...