1
1
import sys
2
2
3
3
import gi
4
- gi .require_version ('Gtk' , '3.0' )
4
+
5
+ gi .require_version ("Gtk" , "3.0" )
5
6
from gi .repository import GLib , Gio , Gtk
6
7
7
8
# This would typically be its own file
8
- MENU_XML = """
9
+ MENU_XML = """
9
10
<?xml version="1.0" encoding="UTF-8"?>
10
11
<interface>
11
12
<menu id="app-menu">
48
49
</interface>
49
50
"""
50
51
51
- class AppWindow (Gtk .ApplicationWindow ):
52
52
53
+ class AppWindow (Gtk .ApplicationWindow ):
53
54
def __init__ (self , * args , ** kwargs ):
54
55
super ().__init__ (* args , ** kwargs )
55
56
56
57
# This will be in the windows group and have the "win" prefix
57
- max_action = Gio .SimpleAction .new_stateful ("maximize" , None ,
58
- GLib .Variant .new_boolean (False ))
58
+ max_action = Gio .SimpleAction .new_stateful (
59
+ "maximize" , None , GLib .Variant .new_boolean (False )
60
+ )
59
61
max_action .connect ("change-state" , self .on_maximize_toggle )
60
62
self .add_action (max_action )
61
63
62
64
# Keep it in sync with the actual state
63
- self .connect ("notify::is-maximized" ,
64
- lambda obj , pspec : max_action .set_state (
65
- GLib .Variant .new_boolean (obj .props .is_maximized )))
65
+ self .connect (
66
+ "notify::is-maximized" ,
67
+ lambda obj , pspec : max_action .set_state (
68
+ GLib .Variant .new_boolean (obj .props .is_maximized )
69
+ ),
70
+ )
66
71
67
72
lbl_variant = GLib .Variant .new_string ("String 1" )
68
- lbl_action = Gio .SimpleAction .new_stateful ("change_label" , lbl_variant .get_type (),
69
- lbl_variant )
73
+ lbl_action = Gio .SimpleAction .new_stateful (
74
+ "change_label" , lbl_variant .get_type (), lbl_variant
75
+ )
70
76
lbl_action .connect ("change-state" , self .on_change_label_state )
71
77
self .add_action (lbl_action )
72
78
73
- self .label = Gtk .Label (label = lbl_variant .get_string (),
74
- margin = 30 )
79
+ self .label = Gtk .Label (label = lbl_variant .get_string (), margin = 30 )
75
80
self .add (self .label )
76
81
self .label .show ()
77
82
@@ -86,16 +91,25 @@ def on_maximize_toggle(self, action, value):
86
91
else :
87
92
self .unmaximize ()
88
93
89
- class Application (Gtk .Application ):
90
94
95
+ class Application (Gtk .Application ):
91
96
def __init__ (self , * args , ** kwargs ):
92
- super ().__init__ (* args , application_id = "org.example.myapp" ,
93
- flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE ,
94
- ** kwargs )
97
+ super ().__init__ (
98
+ * args ,
99
+ application_id = "org.example.myapp" ,
100
+ flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE ,
101
+ ** kwargs
102
+ )
95
103
self .window = None
96
104
97
- self .add_main_option ("test" , ord ("t" ), GLib .OptionFlags .NONE ,
98
- GLib .OptionArg .NONE , "Command line test" , None )
105
+ self .add_main_option (
106
+ "test" ,
107
+ ord ("t" ),
108
+ GLib .OptionFlags .NONE ,
109
+ GLib .OptionArg .NONE ,
110
+ "Command line test" ,
111
+ None ,
112
+ )
99
113
100
114
def do_startup (self ):
101
115
Gtk .Application .do_startup (self )
@@ -139,6 +153,7 @@ def on_about(self, action, param):
139
153
def on_quit (self , action , param ):
140
154
self .quit ()
141
155
156
+
142
157
if __name__ == "__main__" :
143
158
app = Application ()
144
159
app .run (sys .argv )
0 commit comments