Now saving the window properties to GSettings; added some comments

This commit is contained in:
BlueFox 2024-02-04 20:45:46 +01:00
parent a896a9ba27
commit 2b9afb08af
3 changed files with 63 additions and 5 deletions

View File

@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="colorcodes">
<schema id="de.privacynerd.colorcodes" path="/de/privacynerd/colorcodes/">
<schema id="de.privacynerd.colorcodes.state" path="/de/privacynerd/colorcodes/state/">
<key name="width" type="i">
<default>600</default>
</key>
<key name="height" type="i">
<default>300</default>
</key>
<key name="is-maximized" type="b">
<default>false</default>
</key>
<key name="is-fullscreen" type="b">
<default>false</default>
</key>
</schema>
</schemalist>

View File

@ -17,14 +17,25 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
from gi.repository import Adw
from gi.repository import Gtk
from gi.repository import Adw, Gtk, Gio
@Gtk.Template(resource_path='/de/privacynerd/colorcodes/window.ui')
class ColorcodesWindow(Adw.ApplicationWindow):
__gtype_name__ = 'ColorcodesWindow'
__gtype_name__ = 'ColorCodesWindow'
label = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Restore state via GSettings
self.settings = Gio.Settings(schema_id="de.privacynerd.colorcodes.state")
self.settings.bind("width", self, "default-width",
Gio.SettingsBindFlags.DEFAULT)
self.settings.bind("height", self, "default-height",
Gio.SettingsBindFlags.DEFAULT)
self.settings.bind("is-maximized", self, "maximized",
Gio.SettingsBindFlags.DEFAULT)
self.settings.bind("is-fullscreen", self, "fullscreened",
Gio.SettingsBindFlags.DEFAULT)

View File

@ -2,13 +2,40 @@
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="ColorcodesWindow" parent="AdwApplicationWindow">
<template class="ColorCodesWindow" parent="AdwApplicationWindow">
<property name="default-width">600</property>
<property name="default-height">300</property>
<property name="width-request">400</property>
<property name="height-request">250</property>
<property name="title">Color Codes</property>
<!-- A breakpoint to switch from top view switcher to a bottom switcher bar on small sizes (e.g. mobile) -->
<child>
<object class="AdwBreakpoint">
<condition>max-width: 450sp</condition>
<setter object="switcher_bar" property="reveal">True</setter>
<setter object="header_bar" property="title-widget"/>
</object>
</child>
<!-- Now the contents in a AdwToolbarView (pretty much standard) -->
<property name="content">
<object class="AdwToolbarView">
<!-- At the top, the AdwHeaderBar containing a AdwViewSwitcher shown at big sizes -->
<child type="top">
<object class="AdwHeaderBar" id="header_bar">
<!--<property name="title-widget">
<object class="AdwViewSwitcher">
<property name="stack">stack</property>
<property name="policy">wide</property>
<child>
<object class="GtkButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Menu</property>
<property name="label">Test</property>
</object>
</child>
</object>
</property>-->
<!-- ...and the menu button for settings, info etc. -->
<child type="end">
<object class="GtkMenuButton">
<property name="primary">True</property>
@ -19,6 +46,7 @@
</child>
</object>
</child>
<!-- Now the content (previously the top bar was defined) -->
<property name="content">
<object class="GtkLabel" id="label">
<property name="label">This is under massive development!</property>
@ -27,6 +55,13 @@
</style>
</object>
</property>
<!-- Now the bottom bar (previously the content property was defined) -->
<!-- This one's just displayed if the width of the window is too low -->
<!--<child type="bottom">
<object class="AdwViewSwitcherBar" id="switcher_bar">
<property name="stack">stack</property>
</object>
</child>-->
</object>
</property>
</template>