Files
cthulhu/tests/gtk_edit_labels.py

60 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Edit fields whose labels are exposed only through AT-SPI relations."""
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Atk", "1.0")
from gi.repository import Atk, Gtk
window = Gtk.Window(title="Edit label probe")
window.connect("destroy", Gtk.main_quit)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
window.add(box)
def field(identifier, labels, name="", password=False):
entry = Gtk.Entry()
entry.set_text("secret value" if password else "sample value")
entry.set_visibility(not password)
accessible = entry.get_accessible()
accessible.set_name(name)
accessible.set_description(identifier)
for text in labels:
label = Gtk.Label(label=text)
box.pack_start(label, False, False, 0)
accessible.add_relationship(Atk.RelationType.LABELLED_BY, label.get_accessible())
box.pack_start(entry, False, False, 0)
field("related", ["Nickname"])
field("multiple", ["Account", "identifier"])
field("named", ["Other label"], name="Explicit name")
field("unlabelled", [])
field("protected", ["Password"], password=True)
# Exercise the role-invalid Text fallback used by GTK 4, and ensure that a
# password relation target cannot contribute either its name or its contents.
invalid_label = Gtk.Label(label="Fallback label")
invalid_label.get_accessible().set_role(Atk.Role.INVALID)
invalid_label.get_accessible().set_name("")
box.pack_start(invalid_label, False, False, 0)
invalid_entry = Gtk.Entry()
invalid_entry.get_accessible().set_name("")
invalid_entry.get_accessible().set_description("invalid-label")
invalid_entry.get_accessible().add_relationship(Atk.RelationType.LABELLED_BY,
invalid_label.get_accessible())
box.pack_start(invalid_entry, False, False, 0)
password_label = Gtk.Entry()
password_label.set_visibility(False)
password_label.set_text("secret relation value")
password_label.get_accessible().set_name("secret relation name")
box.pack_start(password_label, False, False, 0)
safe_entry = Gtk.Entry()
safe_entry.get_accessible().set_name("")
safe_entry.get_accessible().set_description("password-target")
safe_entry.get_accessible().add_relationship(Atk.RelationType.LABELLED_BY,
password_label.get_accessible())
box.pack_start(safe_entry, False, False, 0)
window.show_all()
Gtk.main()