Skip to content
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
4 changes: 4 additions & 0 deletions src/pyax/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def inspect(
depth: Annotated[
int, typer.Option(help="Depth of subtree to show")
] = 0,
show_parents: Annotated[
bool, typer.Option(help="Show parent chain from selected element to app root")
] = False,
json: Annotated[bool, typer.Option(help="Output in JSON format")] = False,
):
cli_inspect(
Expand All @@ -144,6 +147,7 @@ def inspect(
list_attributes,
list_actions,
-1 if show_subtree and depth == 0 else depth,
show_parents,
json,
)

Expand Down
22 changes: 22 additions & 0 deletions src/pyax/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def inspect(
list_attributes,
list_actions,
depth,
show_parents,
json,
):
app = _get_target_application(app_name)
Expand Down Expand Up @@ -266,6 +267,25 @@ def _show(element):
depth=depth,
)

def _show_parent_chain(element):
_CONSOLE.print("[bold]Parent chain (selected -> root)[/bold]")
idx = 0
current = element
while current:
obj = _element_to_dict(
current, attributes, all_attributes, list_attributes, list_actions
)
if "AXChildren" in obj:
obj.pop("AXChildren")
_CONSOLE.print(
f"{idx:>2}: " + _obj_to_pretty_string(current, obj, role_markup="cyan")
)
parent = current.parent
if not parent or parent == current:
break
current = parent
idx += 1

if dom_id:
_show(_get_target_uielement(app_name, None, dom_id))
return
Expand All @@ -279,3 +299,5 @@ def _show(element):

print()
_show(element)
if show_parents:
_show_parent_chain(element)
5 changes: 4 additions & 1 deletion src/pyax/_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def draw_rect(
if not flip_y
else QtGui.QGuiApplication.primaryScreen().size().height() - rect["y"]
)
painter.drawRect(rect["x"] - self.x(), y, rect["w"], rect["h"])
# Qt drawRect(x, y, w, h) expects ints; AX frame values can be floats.
painter.drawRect(
int(rect["x"] - self.x()), int(y), int(rect["w"]), int(rect["h"])
)
painter.end()
self.label.setPixmap(canvas)