mirror of
https://github.com/Apress/foundations-of-pygtk-development.git
synced 2026-01-04 23:20:06 +01:00
Initial commit
This commit is contained in:
31
App_and_AppWindow/Application1.py
Normal file
31
App_and_AppWindow/Application1.py
Normal file
@@ -0,0 +1,31 @@
|
||||
class Application(Gtk.Application):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, application_id="org.example.myapp",
|
||||
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
||||
**kwargs)
|
||||
self.window = None
|
||||
self.add_main_option("test", ord("t"), GLib.OptionFlags.NONE,
|
||||
GLib.OptionArg.NONE, "Command line test", None)
|
||||
|
||||
def do_startup(self):
|
||||
Gtk.Application.do_startup(self)
|
||||
action = Gio.SimpleAction.new("quit", None)
|
||||
action.connect("activate", self.on_quit)
|
||||
self.add_action(action)
|
||||
|
||||
def do_activate(self):
|
||||
# We only allow a single window and raise any existing ones
|
||||
if not self.window:
|
||||
# Windows are associated with the application
|
||||
# when the last one is closed the application shuts down
|
||||
self.window = AppWindow(application=self, title="Main Window")
|
||||
self.window.present()
|
||||
|
||||
def do_command_line(self, command_line):
|
||||
options = command_line.get_options_dict()
|
||||
if options.contains("test"):
|
||||
# This is printed on the main instance
|
||||
print("Test argument recieved")
|
||||
self.activate()
|
||||
return 0
|
||||
Reference in New Issue
Block a user