Merge pull request #2 from dnarvaez/sbtree
Resync with the sugar-build implementation of tree.py
This commit is contained in:
commit
7fef364494
@ -18,9 +18,11 @@
|
|||||||
UNSTABLE.
|
UNSTABLE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from gi.repository import Atspi
|
from gi.repository import Atspi
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
Atspi.set_timeout(-1, -1)
|
Atspi.set_timeout(-1, -1)
|
||||||
|
|
||||||
@ -34,23 +36,30 @@ def _retry_find(func):
|
|||||||
result = None
|
result = None
|
||||||
n_retries = 1
|
n_retries = 1
|
||||||
|
|
||||||
while n_retries <= 10:
|
while n_retries <= 50:
|
||||||
print "Try %d, name=%s role_name=%s" % \
|
logging.info("Try %d, name=%s role_name=%s" %
|
||||||
(n_retries,
|
(n_retries,
|
||||||
kwargs.get("name", None),
|
kwargs.get("name", None),
|
||||||
kwargs.get("role_name", None))
|
kwargs.get("role_name", None)))
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = func(*args, **kwargs)
|
||||||
|
except GLib.GError, e:
|
||||||
|
# The application is not responding, try again
|
||||||
|
if e.code == Atspi.Error.IPC:
|
||||||
|
continue
|
||||||
|
|
||||||
|
logging.error("GError code %d", e.code)
|
||||||
|
raise
|
||||||
|
|
||||||
result = func(*args, **kwargs)
|
|
||||||
expect_none = kwargs.get("expect_none", False)
|
expect_none = kwargs.get("expect_none", False)
|
||||||
if (not expect_none and result) or \
|
if (not expect_none and result) or \
|
||||||
(expect_none and not result):
|
(expect_none and not result):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
n_retries = n_retries + 1
|
n_retries = n_retries + 1
|
||||||
|
|
||||||
get_root().dump()
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
@ -61,11 +70,19 @@ class Node:
|
|||||||
self._accessible = accessible
|
self._accessible = accessible
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
self._crawl_accessible(self, 0)
|
lines = []
|
||||||
|
self._crawl_accessible(self, 0, lines)
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
def do_action(self, name):
|
def do_action(self, name):
|
||||||
for i in range(self._accessible.get_n_actions()):
|
for i in range(self._accessible.get_n_actions()):
|
||||||
if Atspi.Action.get_name(self._accessible, i) == name:
|
# New, incompatible API
|
||||||
|
if hasattr(self._accessible, "get_action_name"):
|
||||||
|
action_name = self._accessible.get_action_name(i)
|
||||||
|
else:
|
||||||
|
action_name = Atspi.Action.get_name(self._accessible, i)
|
||||||
|
|
||||||
|
if action_name == name:
|
||||||
self._accessible.do_action(i)
|
self._accessible.do_action(i)
|
||||||
|
|
||||||
def click(self, button=1):
|
def click(self, button=1):
|
||||||
@ -149,8 +166,8 @@ class Node:
|
|||||||
for child in node.get_children():
|
for child in node.get_children():
|
||||||
self._find_all_descendants(child, predicate, matches)
|
self._find_all_descendants(child, predicate, matches)
|
||||||
|
|
||||||
def _crawl_accessible(self, node, depth):
|
def _crawl_accessible(self, node, depth, lines):
|
||||||
print " " * depth + str(node)
|
lines.append(" " * depth + str(node))
|
||||||
|
|
||||||
for child in node.get_children():
|
for child in node.get_children():
|
||||||
self._crawl_accessible(child, depth + 1)
|
self._crawl_accessible(child, depth + 1, lines)
|
||||||
|
Loading…
Reference in New Issue
Block a user