4545import gi
4646
4747gi .require_version ("Gtk" , "3.0" )
48- from gi .repository import Gtk , GObject
48+ from gi .repository import Gtk , GObject , GLib , Gio
4949
5050import gettext
5151
@@ -66,13 +66,27 @@ def __init__(self, qapp):
6666 """
6767 :param qapp: qubesadmin.Qubes object
6868 """
69- super ().__init__ (application_id = "org.qubesos.newqube" )
69+ super ().__init__ (
70+ application_id = "org.qubesos.newqube" ,
71+ flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE ,
72+ )
7073 self .qapp : qubesadmin .Qubes = qapp
74+ self .open_at : str | None = None
7175
7276 self .builder : Optional [Gtk .Builder ] = None
7377 self .main_window : Optional [Gtk .Window ] = None
7478 self .template_selector : Optional [TemplateSelector ] = None
7579
80+ self .add_main_option (
81+ "open-at" ,
82+ ord ("o" ),
83+ GLib .OptionFlags .NONE ,
84+ GLib .OptionArg .STRING ,
85+ "Open new qube tool at provided qube type (application, template, "
86+ "standalone, named-disposable, disposable-template)" ,
87+ "qube-type" ,
88+ )
89+
7690 self .progress_bar_dialog = ProgressBarDialog (
7791 self , _ ("Loading available applications..." )
7892 )
@@ -104,6 +118,20 @@ def do_activate(self, *args, **kwargs):
104118 height = self .main_window .get_allocated_height ()
105119 self .main_window .resize (width , height )
106120
121+ match self .open_at :
122+ case "application" :
123+ self .qube_type_app .set_active (True )
124+ case "template" :
125+ self .qube_type_template .set_active (True )
126+ case "standalone" :
127+ self .qube_type_standalone .set_active (True )
128+ case "named-disposable" :
129+ self .qube_type_disposable .set_active (True )
130+ case "disposable-template" :
131+ self .qube_type_dvm_template .set_active (True )
132+ case _:
133+ self .qube_type_app .set_active (True )
134+
107135 self .hold ()
108136
109137 def perform_setup (self ):
@@ -372,6 +400,23 @@ def _create_qube(
372400
373401 return vm
374402
403+ def do_command_line (self , command_line ):
404+ """
405+ Handle CLI arguments. This method overrides default do_command_line
406+ from Gtk.Application (and due to pygtk being dynamically generated
407+ pylint is confused about its arguments).
408+ """
409+ # pylint: disable=arguments-differ
410+ Gtk .Application .do_command_line (self , command_line )
411+ options = command_line .get_options_dict ()
412+ options = options .end ().unpack ()
413+ if "open-at" in options :
414+ self .open_at = options ["open-at" ]
415+ else :
416+ self .open_at = None
417+ self .activate ()
418+ return 0
419+
375420
376421def main ():
377422 """
0 commit comments