Skip to content

Commit 590a4bc

Browse files
authored
Add about dialog
1 parent 41d6630 commit 590a4bc

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/main.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
gi.require_version("Gtk", "4.0")
88
gi.require_version("Adw", "1")
9-
from gi.repository import Gtk, GLib, Adw
9+
from gi.repository import Gtk, GLib, Adw, Gio
1010

1111
print(timer_running)
1212
class TimerWindow(Gtk.ApplicationWindow):
@@ -19,7 +19,12 @@ def __init__(self, *args, **kwargs):
1919
self.set_titlebar(titlebar=headerbar)
2020
self.mainBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)
2121
self.set_child(self.mainBox)
22-
22+
menu_button_model = Gio.Menu()
23+
menu_button_model.append(about_app, 'app.about')
24+
menu_button = Gtk.MenuButton.new()
25+
menu_button.set_icon_name(icon_name='open-menu-symbolic')
26+
menu_button.set_menu_model(menu_model=menu_button_model)
27+
headerbar.pack_end(child=menu_button)
2328
self.spinner = Gtk.Spinner()
2429
self.mainBox.append(self.spinner)
2530

@@ -97,8 +102,31 @@ def stop_timer(self, alabeltext):
97102

98103
class MyApp(Adw.Application):
99104
def __init__(self, **kwargs):
100-
super().__init__(**kwargs)
105+
super().__init__(**kwargs, flags=Gio.ApplicationFlags.FLAGS_NONE)
101106
self.connect('activate', self.on_activate)
107+
self.create_action('about', self.on_about_action)
108+
109+
def on_about_action(self, action, param):
110+
dialog = Gtk.AboutDialog()
111+
dialog.set_title(about)
112+
dialog.set_name(timer_title)
113+
dialog.set_version("1.9")
114+
dialog.set_license_type(Gtk.License(Gtk.License.GPL_3_0))
115+
dialog.set_comments(simple_timer)
116+
dialog.set_website("https://github.com/vikdevelop/timer")
117+
dialog.set_website_label(source_code)
118+
dialog.set_authors(["vikdevelop <https://github.com/vikdevelop>"])
119+
dialog.set_translator_credits(translator_credits)
120+
dialog.set_copyright("© 2022 vikdevelop")
121+
dialog.set_logo_icon_name("com.github.vikdevelop.timer")
122+
dialog.show()
123+
124+
def create_action(self, name, callback, shortcuts=None):
125+
action = Gio.SimpleAction.new(name, None)
126+
action.connect('activate', callback)
127+
self.add_action(action)
128+
if shortcuts:
129+
self.set_accels_for_action(f'app.{name}', shortcuts)
102130

103131
def on_activate(self, app):
104132
self.win = TimerWindow(application=app)

0 commit comments

Comments
 (0)