83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2026 Storm Dragon
|
|
# Authors: Storm Dragon, Angus Kola
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Controlled selection flood and same-process sibling window fixture."""
|
|
import os
|
|
import sys
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
gi.require_version("Atk", "1.0")
|
|
gi.require_version("GdkX11", "3.0")
|
|
from gi.repository import Atk, GdkX11, GLib, Gtk
|
|
|
|
|
|
fixtureName = sys.argv[1]
|
|
windows = []
|
|
pendingInput = ""
|
|
|
|
|
|
def make_window(title):
|
|
window = Gtk.Window(title=title)
|
|
window.set_default_size(350, 260)
|
|
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
window.add(box)
|
|
entry = Gtk.Entry()
|
|
entry.get_accessible().set_name(title + " entry")
|
|
box.add(entry)
|
|
store = Gtk.ListStore(str)
|
|
for index in range(40):
|
|
store.append(["Result " + str(index)])
|
|
table = Gtk.TreeView(model=store)
|
|
table.get_accessible().set_name(title + " results")
|
|
table.append_column(Gtk.TreeViewColumn("Result", Gtk.CellRendererText(), text=0))
|
|
box.add(table)
|
|
marker = Gtk.Label(label="Marker")
|
|
marker.get_accessible().set_role(Atk.Role.ALERT)
|
|
box.add(marker)
|
|
window.show_all()
|
|
entry.grab_focus()
|
|
windows.append(window)
|
|
return window, entry, table, marker
|
|
|
|
|
|
window, entry, table, marker = make_window(fixtureName)
|
|
sibling = None
|
|
|
|
|
|
def receive_command(_source, _condition):
|
|
global pendingInput, sibling
|
|
content = os.read(sys.stdin.fileno(), 4096)
|
|
if not content:
|
|
Gtk.main_quit()
|
|
return False
|
|
pendingInput += content.decode()
|
|
while "\n" in pendingInput:
|
|
command, pendingInput = pendingInput.split("\n", 1)
|
|
if command.startswith("flood "):
|
|
generation = command.split()[1]
|
|
selection = table.get_selection()
|
|
for index in range(300):
|
|
selection.select_path(Gtk.TreePath.new_from_indices([index % 40]))
|
|
marker.set_text("Flood complete " + generation)
|
|
elif command == "sibling":
|
|
sibling, _, _, _ = make_window(fixtureName + " sibling")
|
|
print("sibling", GdkX11.X11Window.get_xid(sibling.get_window()), flush=True)
|
|
elif command == "edit":
|
|
entry.set_text("Updated text")
|
|
entry.set_position(-1)
|
|
elif command == "focus-table":
|
|
table.grab_focus()
|
|
table.set_cursor(Gtk.TreePath.new_from_indices([1]))
|
|
elif command == "quit":
|
|
Gtk.main_quit()
|
|
return False
|
|
return True
|
|
|
|
|
|
GLib.io_add_watch(sys.stdin, GLib.IO_IN | GLib.IO_HUP, receive_command)
|
|
GLib.idle_add(lambda: print("ready", GdkX11.X11Window.get_xid(window.get_window()), flush=True) or False)
|
|
Gtk.main()
|