#!/usr/bin/env python3
"""A tiny, deterministic GTK3 app used as the AT-SPI target for the Phase-0 spike.

It exposes exactly the controls the semantic-control agent must be able to observe and drive:
a labelled push button, an editable text entry, and a label whose text the button mutates. Titles
are fixed so the spike can look elements up by identity. See docs/LINUX_VM_AX_AGENT.md §8.
"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib  # noqa: E402

# The AT-SPI *application* node is named after the program; set it so the spike can look the app up by
# identity ("Nucleic AX Probe") rather than the argv[0] basename.
GLib.set_prgname("Nucleic AX Probe")
GLib.set_application_name("Nucleic AX Probe")


class ProbeWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Nucleic AX Probe")
        self.set_default_size(320, 160)

        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
        box.set_border_width(12)
        self.add(box)

        self.entry = Gtk.Entry()
        self.entry.set_placeholder_text("type here")
        self.entry.get_accessible().set_name("probe-entry")
        box.pack_start(self.entry, False, False, 0)

        self.button = Gtk.Button(label="Click Me")
        self.button.get_accessible().set_name("probe-button")
        self.button.connect("clicked", self.on_click)
        box.pack_start(self.button, False, False, 0)

        self.label = Gtk.Label(label="unclicked")
        self.label.get_accessible().set_name("probe-status")
        box.pack_start(self.label, False, False, 0)

        self.connect("destroy", Gtk.main_quit)

    def on_click(self, _btn):
        self.label.set_text("clicked")


if __name__ == "__main__":
    win = ProbeWindow()
    win.show_all()
    Gtk.main()
