-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMainWindow.py
More file actions
72 lines (50 loc) · 1.8 KB
/
Copy pathMainWindow.py
File metadata and controls
72 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""Python - PyGObject - GTK."""
import pathlib
import sys
import gi
gi.require_version(namespace="Gtk", version="4.0")
gi.require_version(namespace="Adw", version="1")
from gi.repository import Adw, Gio, Gtk
BASE_DIR = pathlib.Path(__file__).resolve().parent
sys.path.append(str(BASE_DIR.parent.parent.parent / "scripts"))
from blp import blp_to_ui
UI_FILE = BASE_DIR / "MainWindow.ui"
BLP_FILE = BASE_DIR / "MainWindow.blp"
blp_to_ui(file=BLP_FILE)
Adw.init()
@Gtk.Template(filename=UI_FILE)
class ExampleWindow(Adw.ApplicationWindow):
__gtype_name__ = "ExampleWindow"
def __init__(self, **kwargs):
super().__init__(**kwargs)
class ExampleApplication(Adw.Application):
def __init__(self):
super().__init__(
application_id="br.com.justcode.Gtk",
flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
)
self.create_action("quit", self.exit_app, ["<primary>q"])
def do_activate(self):
win = self.props.active_window
if not win:
win = ExampleWindow(application=self)
win.present()
def do_startup(self):
Gtk.Application.do_startup(self)
def do_shutdown(self):
Gtk.Application.do_shutdown(self)
def exit_app(self, action, param):
self.quit()
def create_action(self, name, callback, shortcuts=None):
action = Gio.SimpleAction.new(name=name, parameter_type=None)
action.connect("activate", callback)
self.add_action(action=action)
if shortcuts:
self.set_accels_for_action(
detailed_action_name=f"app.{name}",
accels=shortcuts,
)
if __name__ == "__main__":
app = ExampleApplication()
app.run(sys.argv)