# Copyright (c) 2026 Storm Dragon # Authors: Storm Dragon, Angus Kola # SPDX-License-Identifier: GPL-3.0-or-later """Native label relationships for private Xvfb/AT-SPI tests.""" import subprocess import sys import gi gi.require_version("Gtk", "3.0") gi.require_version("Atk", "1.0") gi.require_version("GdkX11", "3.0") gi.require_version("Gdk", "3.0") from gi.repository import Atk, Gdk, GdkX11, GLib, Gtk def main(): window = Gtk.Window(title="Text label probe") box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) window.add(box) entries = [] for text, value, explicitName, protected in ( ("_Destination:", "", "", False), ("Display _name:", "Example document", "", False), ("Visible _label:", "Example value", "Preferred name", False), ("_Secret:", "private fixture value", "", True), (None, "Unlabeled value", "", False), ): entry = Gtk.Entry() entry.set_text(value) entry.set_visibility(not protected) if explicitName: entry.get_accessible().set_name(explicitName) if text: label = Gtk.Label.new_with_mnemonic(text) label.set_mnemonic_widget(entry) box.pack_start(label, False, False, 0) box.pack_start(entry, False, False, 0) entries.append(entry) # Explicit multi-label relations also preserve their provider order. combined = Gtk.Entry() for text in ("Account", "identifier"): label = Gtk.Label(label=text) box.pack_start(label, False, False, 0) combined.get_accessible().add_relationship(Atk.RelationType.LABELLED_BY, label.get_accessible()) box.pack_start(combined, False, False, 0) entries.append(combined) summary = Gtk.Entry() summary.set_text("Example summary") summary.set_editable(False) label = Gtk.Label(label="Read-only summary:") label.set_mnemonic_widget(summary) box.pack_start(label, False, False, 0) box.pack_start(summary, False, False, 0) entries.append(summary) window.show_all() Gdk.Display.get_default().sync() subprocess.run(["xdotool", "windowfocus", str(GdkX11.X11Window.get_xid(window.get_window()))], check=True) def command_ready(_source, condition): if condition & GLib.IO_HUP: Gtk.main_quit() return False line = sys.stdin.readline() if not line: Gtk.main_quit() return False entries[int(line)].grab_focus() return True GLib.io_add_watch(sys.stdin, GLib.IO_IN | GLib.IO_HUP, command_ready) GLib.idle_add(lambda: (print("ready", flush=True), False)[1]) Gtk.main() if __name__ == "__main__": main()