Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. class Application(Gtk.Application):
  2.     def __init__(self, *args, **kwargs):
  3.         super().__init__(*args, application_id="org.android.toolkit",
  4.                          flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
  5.                          **kwargs)
  6.         self.window = None
  7.  
  8.         self.add_main_option("test", ord("t"), GLib.OptionFlags.NONE,
  9.                              GLib.OptionArg.NONE, "Command line test", None)
  10.  
  11.     def do_startup(self):
  12.         Gtk.Application.do_startup(self)
  13.  
  14.         action = Gio.SimpleAction.new("about", None)
  15.         action.connect("activate", self.on_about)
  16.         self.add_action(action)
  17.  
  18.         action = Gio.SimpleAction.new("quit", None)
  19.         action.connect("activate", self.on_quit)
  20.         self.add_action(action)
  21.  
  22.         builder = Gtk.Builder.new_from_string(MENU_XML, -1)
  23.         self.set_app_menu(builder.get_object("app-menu"))
  24.  
  25.     def do_activate(self):
  26.         if not self.window:
  27.             self.window = MainWindow(application=self, title="Android Toolkit")
  28.  
  29.         self.window.present()
  30.  
  31.     def do_command_line(self, command_line):
  32.         options = command_line.get_options_dict()
  33.  
  34.         if options.contains("test"):
  35.             print("Test argument recieved.")
  36.  
  37.             self.activate()
  38.             return 0
  39.  
  40.     def on_about(self, action, param):
  41.         about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True)
  42.         about_dialog.present()
  43.  
  44.     def on_quit(self, action, param):
  45.         self.quit()
  46.  
  47. if __name__ == "__main__":
  48.     app = Application()
  49.     app.run(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement