| 1 |
import gi |
| 2 |
|
| 3 |
gi.require_version("Gtk", "4.0") |
| 4 |
from gi.repository import Gtk, GObject |
| 5 |
|
| 6 |
|
| 7 |
class StackWindow(Gtk.ApplicationWindow): |
| 8 |
def __init__(self, **kargs): |
| 9 |
super().__init__(**kargs, title="Stack Demo") |
| 10 |
|
| 11 |
self.set_default_size(300, 250) |
| 12 |
|
| 13 |
header = Gtk.HeaderBar() |
| 14 |
self.set_titlebar(header) |
| 15 |
|
| 16 |
stack = Gtk.Stack() |
| 17 |
stack.props.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT |
| 18 |
stack.props.transition_duration = 1000 |
| 19 |
self.set_child(stack) |
| 20 |
|
| 21 |
checkbutton = Gtk.CheckButton(label="Click me!") |
| 22 |
checkbutton.props.hexpand = True |
| 23 |
checkbutton.props.halign = Gtk.Align.CENTER |
| 24 |
page1 = stack.add_titled(checkbutton, "check", "Check Button") |
| 25 |
checkbutton.bind_property( |
| 26 |
"active", page1, "needs-attention", GObject.BindingFlags.DEFAULT |
| 27 |
) |
| 28 |
|
| 29 |
label = Gtk.Label() |
| 30 |
label.set_markup("<big>A fancy label</big>") |
| 31 |
stack.add_titled(label, "label", "A label") |
| 32 |
|
| 33 |
stack_switcher = Gtk.StackSwitcher() |
| 34 |
stack_switcher.set_stack(stack) |
| 35 |
header.set_title_widget(stack_switcher) |
| 36 |
|
| 37 |
# Let's start in the second page |
| 38 |
stack.set_visible_child_name("label") |
| 39 |
|
| 40 |
|
| 41 |
def on_activate(app): |
| 42 |
# Create window |
| 43 |
win = StackWindow(application=app) |
| 44 |
win.present() |
| 45 |
|
| 46 |
|
| 47 |
app = Gtk.Application(application_id="com.example.App") |
| 48 |
app.connect("activate", on_activate) |
| 49 |
|
| 50 |
app.run(None) |