|
19 | 19 | """This module creates the AboutDialog which shows the version and license.""" |
20 | 20 |
|
21 | 21 | import os |
| 22 | +import gi |
| 23 | + |
| 24 | +gi.require_version("Gtk", "4.0") |
| 25 | +from gi.repository import Gtk |
22 | 26 |
|
23 | 27 | from safeeyes import utility |
24 | 28 | from safeeyes.translations import translate as _ |
25 | 29 |
|
26 | 30 | ABOUT_DIALOG_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/about_dialog.glade") |
27 | 31 |
|
28 | 32 |
|
29 | | -class AboutDialog: |
| 33 | +@Gtk.Template(filename=ABOUT_DIALOG_GLADE) |
| 34 | +class AboutDialog(Gtk.ApplicationWindow): |
30 | 35 | """AboutDialog reads the about_dialog.glade and build the user interface |
31 | 36 | using that file. |
32 | 37 |
|
33 | 38 | It shows the application name with version, a small description, |
34 | 39 | license and the GitHub url. |
35 | 40 | """ |
36 | 41 |
|
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" |
41 | 43 |
|
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) |
44 | 50 |
|
45 | | - builder.get_object("lbl_decription").set_label( |
| 51 | + self.lbl_decription.set_label( |
46 | 52 | _( |
47 | 53 | "Safe Eyes protects your eyes from eye strain (asthenopia) by reminding" |
48 | 54 | " you to take breaks while you're working long hours at the computer" |
49 | 55 | ) |
50 | 56 | ) |
51 | | - builder.get_object("lbl_license").set_label(_("License") + ":") |
| 57 | + self.lbl_license.set_label(_("License") + ":") |
52 | 58 |
|
53 | 59 | # 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) |
55 | 61 |
|
56 | 62 | def show(self): |
57 | 63 | """Show the About dialog.""" |
58 | | - self.window.present() |
| 64 | + self.present() |
59 | 65 |
|
| 66 | + @Gtk.Template.Callback() |
60 | 67 | def on_window_delete(self, *args): |
61 | 68 | """Window close event handler.""" |
62 | | - self.window.destroy() |
| 69 | + self.destroy() |
63 | 70 |
|
| 71 | + @Gtk.Template.Callback() |
64 | 72 | def on_close_clicked(self, *args): |
65 | 73 | """Close button click event handler.""" |
66 | | - self.window.destroy() |
| 74 | + self.destroy() |
0 commit comments