File size: 1,866 Bytes
d0f63e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""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([]))