|
| 1 | +import gi # type:ignore |
| 2 | + |
| 3 | +gi.require_version("GLib", "2.0") |
| 4 | +from gi.repository import GLib # type:ignore |
| 5 | +from gi.repository import Gio, GObject |
| 6 | + |
| 7 | +gi.require_version("Gdk", "4.0") |
| 8 | +from gi.repository import Gdk |
| 9 | + |
| 10 | +gi.require_version("Gtk", "4.0") |
| 11 | +from gi.repository import Gtk |
| 12 | + |
| 13 | + |
| 14 | +class MyThing(GObject.Object): |
| 15 | + def __init__(self, aValue: int) -> None: |
| 16 | + super().__init__() |
| 17 | + self.aValue = aValue |
| 18 | + |
| 19 | + |
| 20 | +def on_activate(app: Gtk.Application) -> None: |
| 21 | + print("creating application window") |
| 22 | + win = Gtk.ApplicationWindow(application=app) |
| 23 | + print("created") |
| 24 | + box = Gtk.Box() |
| 25 | + |
| 26 | + button = Gtk.Button() |
| 27 | + button.set_label("hello world?") |
| 28 | + |
| 29 | + button2 = Gtk.Button() |
| 30 | + button2.set_label("goodbye world?") |
| 31 | + lm = Gio.ListStore.new(MyThing) |
| 32 | + lm.append(MyThing(7)) |
| 33 | + lm.append(MyThing(8)) |
| 34 | + lm.append(MyThing(9)) |
| 35 | + signalFactory = Gtk.SignalListItemFactory() |
| 36 | + |
| 37 | + def onsetup( |
| 38 | + factory: Gtk.SignalListItemFactory, item: Gtk.ListItem |
| 39 | + ) -> None: |
| 40 | + value = item.get_item().aValue |
| 41 | + item.set_child(Gtk.Label.new(f"setup {value}")) |
| 42 | + |
| 43 | + def onbind(factory: Gtk.SignalListItemFactory, item: Gtk.ListItem) -> None: |
| 44 | + value = item.get_item().aValue |
| 45 | + item.set_child(Gtk.Label.new(f"bind {value}")) |
| 46 | + |
| 47 | + signalFactory.connect("setup", onsetup) |
| 48 | + signalFactory.connect("bind", onbind) |
| 49 | + lv = Gtk.ListView.new(Gtk.SingleSelection.new(lm), signalFactory) |
| 50 | + box.append(button) |
| 51 | + box.append(lv) |
| 52 | + box.append(button2) |
| 53 | + win.set_child(box) |
| 54 | + win.present() |
| 55 | + print("presented") |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + # Create a new application |
| 60 | + app = Gtk.Application(application_id="im.glyph.and.this.is.a.detail.view") |
| 61 | + app.connect("activate", on_activate) |
| 62 | + |
| 63 | + # Run the application |
| 64 | + print("running?") |
| 65 | + app.run() |
| 66 | + print("goodbye?") |
0 commit comments