Publish showcase_scenes/ from marimo
Browse files
showcase_scenes/gtk_dialog.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A real GTK3 window, which - unlike Tk - publishes an accessibility tree.
|
| 2 |
+
|
| 3 |
+
This is the app the accessibility-tree detector is demonstrated against: GTK3
|
| 4 |
+
exports every widget through ATK/AT-SPI, so a detector can read button names and
|
| 5 |
+
their real screen extents without OCR reading a single pixel.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
import gi
|
| 11 |
+
|
| 12 |
+
gi.require_version("Gtk", "3.0")
|
| 13 |
+
from gi.repository import GLib, Gtk # noqa: E402
|
| 14 |
+
|
| 15 |
+
WINDOW = (160, 160)
|
| 16 |
+
BUTTONS = ["Files", "Terminal", "Save", "Cancel"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def on_clicked(button, marker):
|
| 20 |
+
marker.write_text(button.get_label() or "")
|
| 21 |
+
label = getattr(button, "status_label", None)
|
| 22 |
+
if label is not None:
|
| 23 |
+
label.set_text("last action: " + (button.get_label() or ""))
|
| 24 |
+
return False
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def on_activate(app):
|
| 28 |
+
window = Gtk.ApplicationWindow(application=app, title="Accessible desktop")
|
| 29 |
+
window.set_default_size(460, 220)
|
| 30 |
+
window.move(*WINDOW)
|
| 31 |
+
|
| 32 |
+
grid = Gtk.Grid(column_spacing=8, row_spacing=8, margin=14)
|
| 33 |
+
window.add(grid)
|
| 34 |
+
|
| 35 |
+
marker = None
|
| 36 |
+
if len(sys.argv) > 1:
|
| 37 |
+
from pathlib import Path
|
| 38 |
+
marker = Path(sys.argv[1])
|
| 39 |
+
|
| 40 |
+
status = Gtk.Label(label="last action: (none)")
|
| 41 |
+
status.set_xalign(0)
|
| 42 |
+
grid.attach(status, 0, 0, 4, 1)
|
| 43 |
+
|
| 44 |
+
for column, name in enumerate(BUTTONS):
|
| 45 |
+
button = Gtk.Button(label=name)
|
| 46 |
+
button.status_label = status
|
| 47 |
+
button.set_size_request(100, 36)
|
| 48 |
+
if marker is not None:
|
| 49 |
+
button.connect("clicked", on_clicked, marker)
|
| 50 |
+
grid.attach(button, column, 1, 1, 1)
|
| 51 |
+
|
| 52 |
+
grid.attach(Gtk.Label(label="Choose an action"), 0, 2, 4, 1)
|
| 53 |
+
window.show_all()
|
| 54 |
+
|
| 55 |
+
if len(sys.argv) > 2:
|
| 56 |
+
from pathlib import Path
|
| 57 |
+
Path(sys.argv[2]).write_text("mapped")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
app = Gtk.Application(application_id="dev.tinycomputeragent.Demo")
|
| 61 |
+
app.connect("activate", on_activate)
|
| 62 |
+
sys.exit(app.run([]))
|