Skip to content

Commit 74db826

Browse files
committed
about dialog: migrate from Gtk.Builder to Gtk.Template
1 parent dd473be commit 74db826

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

safeeyes/glade/about_dialog.glade

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ GNU General Public License for more details.
3535
You should have received a copy of the GNU General Public License
3636
along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</property>
3737
</object>
38-
<object class="GtkWindow" id="window_about">
38+
<template parent="GtkApplicationWindow" class="AboutDialog">
3939
<property name="title">Safe Eyes</property>
4040
<property name="resizable">0</property>
4141
<property name="icon-name">io.github.slgobinath.SafeEyes</property>
42+
<signal name="close-request" handler="on_window_delete" swapped="no" />
4243
<child>
4344
<object class="GtkBox" id="layout_box">
4445
<property name="visible">1</property>
@@ -144,6 +145,7 @@ along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</pr
144145
</child>
145146
<child>
146147
<object class="GtkButton" id="btn_close">
148+
<signal name="clicked" handler="on_close_clicked" swapped="no" />
147149
<property name="label" translatable="yes">Close</property>
148150
<property name="visible">1</property>
149151
<property name="can-focus">1</property>
@@ -168,5 +170,5 @@ along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</pr
168170
</child>
169171
</object>
170172
</child>
171-
</object>
173+
</template>
172174
</interface>

safeeyes/ui/about_dialog.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,56 @@
1919
"""This module creates the AboutDialog which shows the version and license."""
2020

2121
import os
22+
import gi
23+
24+
gi.require_version("Gtk", "4.0")
25+
from gi.repository import Gtk
2226

2327
from safeeyes import utility
2428
from safeeyes.translations import translate as _
2529

2630
ABOUT_DIALOG_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/about_dialog.glade")
2731

2832

29-
class AboutDialog:
33+
@Gtk.Template(filename=ABOUT_DIALOG_GLADE)
34+
class AboutDialog(Gtk.ApplicationWindow):
3035
"""AboutDialog reads the about_dialog.glade and build the user interface
3136
using that file.
3237
3338
It shows the application name with version, a small description,
3439
license and the GitHub url.
3540
"""
3641

37-
def __init__(self, application, version):
38-
builder = utility.create_gtk_builder(ABOUT_DIALOG_GLADE)
39-
self.window = builder.get_object("window_about")
40-
self.window.set_application(application)
42+
__gtype_name__ = "AboutDialog"
4143

42-
self.window.connect("close-request", self.on_window_delete)
43-
builder.get_object("btn_close").connect("clicked", self.on_close_clicked)
44+
lbl_decription = Gtk.Template.Child()
45+
lbl_license = Gtk.Template.Child()
46+
lbl_app_name = Gtk.Template.Child()
47+
48+
def __init__(self, application, version):
49+
super().__init__(application=application)
4450

45-
builder.get_object("lbl_decription").set_label(
51+
self.lbl_decription.set_label(
4652
_(
4753
"Safe Eyes protects your eyes from eye strain (asthenopia) by reminding"
4854
" you to take breaks while you're working long hours at the computer"
4955
)
5056
)
51-
builder.get_object("lbl_license").set_label(_("License") + ":")
57+
self.lbl_license.set_label(_("License") + ":")
5258

5359
# Set the version at the runtime
54-
builder.get_object("lbl_app_name").set_label("Safe Eyes " + version)
60+
self.lbl_app_name.set_label("Safe Eyes " + version)
5561

5662
def show(self):
5763
"""Show the About dialog."""
58-
self.window.present()
64+
self.present()
5965

66+
@Gtk.Template.Callback()
6067
def on_window_delete(self, *args):
6168
"""Window close event handler."""
62-
self.window.destroy()
69+
self.destroy()
6370

71+
@Gtk.Template.Callback()
6472
def on_close_clicked(self, *args):
6573
"""Close button click event handler."""
66-
self.window.destroy()
74+
self.destroy()

0 commit comments

Comments
 (0)