xfstestsdb/xfstestsdb/gtk/window.py

54 lines
2.3 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""The main Adw.Window implementation for our application."""
import typing
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Adw
class Window(Adw.Window):
"""Our customized Window displayed to the user."""
child = GObject.Property(type=Gtk.Widget)
sidebar = GObject.Property(type=Gtk.Widget)
headerbar = GObject.Property(type=Adw.HeaderBar)
title = GObject.Property(type=Adw.WindowTitle)
runid = GObject.Property(type=int)
show_sidebar = GObject.Property(type=bool, default=False)
def __init__(self, **kwargs):
"""Set up our Window."""
super().__init__(default_height=1000, default_width=1600,
content=Gtk.Box(orientation=Gtk.Orientation.VERTICAL),
title=Adw.WindowTitle(title="xfstestsdb gtk"),
headerbar=Adw.HeaderBar(), **kwargs)
self._splitview = Adw.OverlaySplitView(content=self.child,
sidebar=self.sidebar,
collapsed=True,
show_sidebar=self.show_sidebar)
self._show_sidebar = Gtk.ToggleButton(icon_name="sidebar-show",
active=self.show_sidebar)
self.headerbar.pack_start(self._show_sidebar)
self.headerbar.props.title_widget = self.title
self.headerbar.add_css_class("flat")
self.props.content.append(self.headerbar)
self.props.content.append(self._splitview)
self._show_sidebar.bind_property("active", self, "show-sidebar",
GObject.BindingFlags.BIDIRECTIONAL)
self.bind_property("show-sidebar", self._splitview, "show-sidebar")
self.bind_property("sidebar", self._splitview, "sidebar")
self.bind_property("child", self._splitview, "content")
self.connect("notify::runid", self.__notify_runid)
if __debug__:
self.add_css_class("devel")
def __notify_runid(self, window: typing.Self,
param: GObject.ParamSpec) -> None:
text = f"runid #{self.runid}" if self.runid > 0 else ""
self.title.props.subtitle = text