"""A real GTK3 window, which - unlike Tk - publishes an accessibility tree. This is the app the accessibility-tree detector is demonstrated against: GTK3 exports every widget through ATK/AT-SPI, so a detector can read button names and their real screen extents without OCR reading a single pixel. """ import sys import gi gi.require_version("Gtk", "3.0") from gi.repository import GLib, Gtk # noqa: E402 WINDOW = (160, 160) BUTTONS = ["Files", "Terminal", "Save", "Cancel"] def on_clicked(button, marker): marker.write_text(button.get_label() or "") label = getattr(button, "status_label", None) if label is not None: label.set_text("last action: " + (button.get_label() or "")) return False def on_activate(app): window = Gtk.ApplicationWindow(application=app, title="Accessible desktop") window.set_default_size(460, 220) window.move(*WINDOW) grid = Gtk.Grid(column_spacing=8, row_spacing=8, margin=14) window.add(grid) marker = None if len(sys.argv) > 1: from pathlib import Path marker = Path(sys.argv[1]) status = Gtk.Label(label="last action: (none)") status.set_xalign(0) grid.attach(status, 0, 0, 4, 1) for column, name in enumerate(BUTTONS): button = Gtk.Button(label=name) button.status_label = status button.set_size_request(100, 36) if marker is not None: button.connect("clicked", on_clicked, marker) grid.attach(button, column, 1, 1, 1) grid.attach(Gtk.Label(label="Choose an action"), 0, 2, 4, 1) window.show_all() if len(sys.argv) > 2: from pathlib import Path Path(sys.argv[2]).write_text("mapped") app = Gtk.Application(application_id="dev.tinycomputeragent.Demo") app.connect("activate", on_activate) sys.exit(app.run([]))