Skip to content

Commit bd40ffc

Browse files
committed
Add API to get library locators from context tree
1 parent ce647fb commit bd40ffc

3 files changed

Lines changed: 43 additions & 35 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "java-access-bridge-wrapper"
3-
version = "0.12.0"
3+
version = "0.13.0"
44
description = "Python wrapper for the Windows Java Access Bridge"
55
license = "Apache-2.0"
66
readme = "README.md"

src/JABWrapper/context_tree.py

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,20 @@ def __repr__(self) -> str:
9090
Returns:
9191
A string that represents the object tree with detailed Node values.
9292
"""
93-
string = "{}Role={}, Name={}, VAN={}, Desc={}, Ancestry={}, St={}, Sts={}, at x={}:y={} w={} h={}; indexInParent={}; cc={}; vcc={}".format(
94-
' ' * self.ancestry,
95-
repr(self.context_info.role),
96-
repr(self.context_info.name),
97-
repr(self.virtual_accessible_name),
98-
repr(self.ancestry),
99-
repr(self.context_info.description),
100-
repr(self.state),
101-
repr(self.context_info.states),
102-
self.context_info.x,
103-
self.context_info.y,
104-
self.context_info.width,
105-
self.context_info.height,
106-
self.context_info.indexInParent,
107-
self.context_info.childrenCount,
108-
self.visible_children_count
109-
)
93+
string = (f"{'| ' * self.ancestry}"
94+
f"role:{self.context_info.role}; "
95+
f"name:{self.context_info.name}; "
96+
f"virtual_accessible_name:{self.virtual_accessible_name}; "
97+
f"description:{self.context_info.description}; "
98+
f"ancestry:{self.ancestry}; "
99+
f"state:{self.state}; "
100+
f"states={self.context_info.states}; "
101+
f"at x:{self.context_info.x} y:{self.context_info.y}; "
102+
f"width:{self.context_info.width}; "
103+
f"height:{self.context_info.height}; "
104+
f"indexInParent:{self.context_info.indexInParent}; "
105+
f"childrenCount:{self.context_info.childrenCount}; "
106+
f"visible_children_count:{self.visible_children_count}")
110107
for parser in self._parsers:
111108
string += f"{parser}"
112109
for child in self.children:
@@ -118,26 +115,33 @@ def __str__(self) -> str:
118115
Returns:
119116
A string of Node values.
120117
"""
121-
string = "Role={}, Name={}, VAN={}, ancestry={}, Desc={}, St={}, Sts={}, at x={}:y={} w={} h={}; indexInParent={}; cc={}; vcc={}".format(
122-
repr(self.context_info.role),
123-
repr(self.context_info.name),
124-
repr(self.virtual_accessible_name),
125-
repr(self.ancestry),
126-
repr(self.context_info.description),
127-
repr(self.state),
128-
repr(self.context_info.states),
129-
self.context_info.x,
130-
self.context_info.y,
131-
self.context_info.width,
132-
self.context_info.height,
133-
self.context_info.indexInParent,
134-
self.context_info.childrenCount,
135-
self.visible_children_count
136-
)
118+
string = (f"role:{self.context_info.role}, "
119+
f"name:{self.context_info.name}, "
120+
f"virtual_accessible_name:{self.virtual_accessible_name}; "
121+
f"description:{self.context_info.description}; "
122+
f"ancestry:{self.ancestry}; "
123+
f"state:{self.state}; "
124+
f"states={self.context_info.states}; "
125+
f"at x:{self.context_info.x} y:{self.context_info.y}; "
126+
f"width:{self.context_info.width}; "
127+
f"height:{self.context_info.height}; "
128+
f"indexInParent:{self.context_info.indexInParent}; "
129+
f"childrenCount:{self.context_info.childrenCount}; "
130+
f"visible_children_count:{self.visible_children_count}")
137131
for parser in self._parsers:
138132
string += "{}".format(parser)
139133
return string
140134

135+
def get_library_locator_tree_as_text(self):
136+
"""
137+
Returns node info in library locator format.
138+
"""
139+
string = (f"{'| ' * self.ancestry}role:{self.context_info.role} and name:{self.context_info.name} and "
140+
f"description:{self.context_info.description} and indexInParent:{self.context_info.indexInParent}")
141+
for child in self.children:
142+
string += f"\n{child.get_library_locator_tree_as_text()}"
143+
return string
144+
141145
def traverse(self):
142146
yield self
143147
for child in self.children:
@@ -269,6 +273,9 @@ def __repr__(self) -> str:
269273
def __str__(self):
270274
return f"{self.root}"
271275

276+
def get_library_locator_tree_as_text(self):
277+
return self.root.get_library_locator_tree_as_text()
278+
272279
@retry_callback
273280
def _property_change_cp(self, source: JavaObject, property: str, old_value: str, new_value: str) -> None:
274281
with self._lock:

src/JABWrapper/context_tree_reader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def main():
214214
locator = ' '.join(sys.argv[2:])
215215
simulator = LocatorSimulator(output_file)
216216
simulator.parse_element_tree()
217-
print([str(item).strip() for item in simulator.find_element(locator)])
217+
for element in simulator.find_element(locator):
218+
print(str(element))
218219

219220

220221
if __name__ == '__main__':

0 commit comments

Comments
 (0)