Files

162 lines
5.5 KiB
Python

#!/usr/bin/env python3
"""Mutable GTK tree fixture for the isolated native AT-SPI test."""
import os
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, GLib, Gtk, Pango
window = Gtk.Window(title="Cthulhu Tree Probe")
window.connect("destroy", Gtk.main_quit)
window.set_default_size(320, 180)
resize_pending = False
activation_window = None
container = (
Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
if os.environ.get("CTHULHU_TREE_CONTAINER") == "box"
else Gtk.ListBox()
)
container.get_accessible().set_name("Dynamic controls")
window.add(container)
def make_row(name):
row = Gtk.ListBoxRow()
row.add(Gtk.Label(label=name))
return row
persistent = make_row("Persistent control")
removable = make_row("Removable control")
container.add(persistent)
container.add(removable)
review_label = Gtk.Label(label="Café 猫\nSecond line")
review_label.get_accessible().set_name("Review text probe")
container.add(review_label)
protected = Gtk.Entry()
protected.set_visibility(False)
protected.set_text("fixture secret")
protected.get_accessible().set_name("Protected text probe")
container.add(protected)
caret_entry = Gtk.Entry()
caret_entry.set_text("Caret 猫 text")
caret_entry.set_position(6)
caret_entry.get_accessible().set_name("Caret review probe")
container.add(caret_entry)
scroller = Gtk.ScrolledWindow()
scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
scroller.set_size_request(100, 35)
clipped_label = Gtk.Label(label="Clipped " + "猫" * 60 + " OFFSCREEN")
clipped_label.set_xalign(0)
clipped_label.get_accessible().set_name("Clipped review probe")
scroller.add(clipped_label)
container.add(scroller)
numeric = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, -10, 10, 0.01)
numeric.set_digits(2)
numeric.set_value(1.25)
numeric.get_accessible().set_name("Numeric value probe")
container.add(numeric)
if os.environ.get("CTHULHU_SPEECH_METADATA") == "1":
mnemonic_button = Gtk.Button.new_with_mnemonic("_Activate")
mnemonic_button.get_accessible().set_name("Mnemonic probe")
container.add(mnemonic_button)
indentation_entry = Gtk.Entry()
indentation_entry.set_text("\t Indented É")
indentation_entry.set_position(5)
indentation_entry.get_accessible().set_name("Indentation probe")
container.add(indentation_entry)
color_view = Gtk.TextView()
color_view.get_accessible().set_name("Color attribute probe")
color_view.set_wrap_mode(Gtk.WrapMode.NONE)
color_buffer = color_view.get_buffer()
color_buffer.set_text("Red example")
red_tag = color_buffer.create_tag("red", foreground="#ff0000", underline=Pango.Underline.ERROR)
color_buffer.apply_tag(red_tag, color_buffer.get_start_iter(), color_buffer.get_iter_at_offset(3))
color_buffer.place_cursor(color_buffer.get_iter_at_offset(1))
container.add(color_view)
def on_key_press(_window, event):
global activation_window, removable, resize_pending
if os.environ.get("CTHULHU_SPEECH_METADATA") == "1":
if event.keyval == Gdk.KEY_F9:
mnemonic_button.grab_focus()
return True
if event.keyval == Gdk.KEY_F10:
indentation_entry.grab_focus()
return True
if event.keyval == Gdk.KEY_F11:
color_view.grab_focus()
return True
if event.keyval == Gdk.KEY_F6:
caret_entry.grab_focus()
return True
if event.keyval == Gdk.KEY_F7:
protected.grab_focus()
return True
if event.keyval == Gdk.KEY_F8:
numeric.grab_focus()
return True
if event.keyval == Gdk.KEY_Escape:
window.destroy()
return True
if event.keyval == Gdk.KEY_r and removable is not None:
container.remove(removable)
removable = None
window.set_title("Cthulhu Tree Probe Removed")
return True
if event.keyval == Gdk.KEY_v:
review_label.hide()
window.set_title("Cthulhu Tree Probe Text Hidden")
return True
if event.keyval == Gdk.KEY_t:
review_label.set_text("Changed 猫\nNew line")
window.set_title("Cthulhu Tree Probe Text Changed")
return True
if event.keyval == Gdk.KEY_m:
resize_pending = True
window.resize(500, 300)
return True
if event.keyval == Gdk.KEY_h:
persistent.hide()
window.set_title("Cthulhu Tree Probe Hidden")
return True
if event.keyval == Gdk.KEY_a:
container.add(make_row("Added control"))
container.show_all()
window.set_title("Cthulhu Tree Probe Added")
return True
if event.keyval == Gdk.KEY_w:
activation_window = Gtk.Window(title="Cthulhu Activation Probe")
activation_window.set_transient_for(window)
activation_window.set_default_size(240, 100)
activation_button = Gtk.Button(label="Activated control")
activation_window.add(activation_button)
activation_window.show_all()
activation_button.grab_focus()
activation_window.present()
GLib.timeout_add(1000, activation_window.destroy)
return True
return False
def on_size_allocate(_window, allocation):
global resize_pending
if resize_pending and allocation.width == 500 and allocation.height == 300:
resize_pending = False
window.set_title("Cthulhu Tree Probe Resized")
window.connect("size-allocate", on_size_allocate)
window.connect("key-press-event", on_key_press)
window.show_all()
window.present()
if os.environ.get("CTHULHU_TREE_MANUAL") != "1":
GLib.timeout_add_seconds(20, Gtk.main_quit)
Gtk.main()