This is somewhat more reliable (maybe just due to the delay....)

This commit is contained in:
Isaiah Odhner 2023-09-10 00:33:50 -04:00
parent 2a7b4412e1
commit b9503e44f4

View File

@ -162,9 +162,20 @@ class PilotRecorder():
if index is None: if index is None:
steps_code += f"await pilot.click({selector!r}, offset=Offset({offset.x}, {offset.y}))\n" steps_code += f"await pilot.click({selector!r}, offset=Offset({offset.x}, {offset.y}))\n"
else: else:
steps_code += f"widget = pilot.app.query({selector!r})[{index!r}]\n" # Strategy: click on the screen, offset by the widget's position.
# can't pass a widget to pilot.click, only a selector, or None # steps_code += f"widget = pilot.app.query({selector!r})[{index!r}]\n"
steps_code += f"await pilot.click(offset=Offset({offset.x}, {offset.y}) + widget.region.offset)\n" # # can't pass a widget to pilot.click, only a selector, or None
# steps_code += f"await pilot.click(offset=Offset({offset.x}, {offset.y}) + widget.region.offset)\n"
# Strategy: add a class to the widget, and click on that.
steps_code += f"""
# Click on widget disambiguated by index (selector {selector!r} matched multiple nodes)
await pilot.pause(0.5)
widget = pilot.app.query({selector!r})[{index!r}]
widget.add_class('pilot-click-target')
await pilot.click('.pilot-click-target')
widget.remove_class('pilot-click-target')
"""
elif isinstance(event, MouseMove): elif isinstance(event, MouseMove):
# TODO: generate code for drags (but not extraneous mouse movement) # TODO: generate code for drags (but not extraneous mouse movement)
pass pass