11#!/usr/bin/env python
22import os
33import gi
4+ import sys
45gi .require_version ('Gtk' , '3.0' )
56gi .require_version ('Handy' , '1' )
67gi .require_version ('Vte' , '2.91' )
7- from gi .repository import Gtk , Gdk , GLib , Vte , Handy , Pango
8+ from gi .repository import Gtk , Gdk , Gio , GLib , Vte , Handy , Pango
89
910CONF_NAME = "EasyTerm"
1011CONF_DEF_CWD = os .getcwd ()
@@ -107,11 +108,72 @@ def __init__(self, cwd:str="", command:list=[], env:list=[], actions:list=[], *a
107108
108109class EasyTerm (Gtk .Application ):
109110 def __init__ (self , cwd :str = "" , command :list = [], env :list = [], actions :list = [], * args , ** kwds ):
110- super ().__init__ (* args , ** kwds )
111+ super ().__init__ (
112+ application_id = 'com.usebottles.easyterm' ,
113+ flags = Gio .ApplicationFlags .HANDLES_COMMAND_LINE ,
114+ * args , ** kwds
115+ )
111116 self .cwd = cwd
112117 self .command = command
113118 self .env = env
114119 self .actions = actions
120+
121+ self .__register_arguments ()
122+
123+ def __register_arguments (self ):
124+ self .add_main_option (
125+ "cwd" ,
126+ ord ("c" ),
127+ GLib .OptionFlags .NONE ,
128+ GLib .OptionArg .STRING ,
129+ "Set the initial working directory" ,
130+ None
131+ )
132+ self .add_main_option (
133+ "command" ,
134+ ord ("c" ),
135+ GLib .OptionFlags .NONE ,
136+ GLib .OptionArg .STRING ,
137+ "Set the command to execute" ,
138+ None
139+ )
140+ self .add_main_option (
141+ "env" ,
142+ ord ("e" ),
143+ GLib .OptionFlags .NONE ,
144+ GLib .OptionArg .STRING ,
145+ "Set the environment variables" ,
146+ None
147+ )
148+ self .add_main_option (
149+ "actions" ,
150+ ord ("a" ),
151+ GLib .OptionFlags .NONE ,
152+ GLib .OptionArg .STRING ,
153+ "Set the actions" ,
154+ None
155+ )
156+
157+
158+ def do_command_line (self , command_line ):
159+ cwd = ""
160+ command = []
161+ env = []
162+ actions = []
163+
164+ options = command_line .get_options_dict ()
165+
166+ if options .contains ("cwd" ):
167+ cwd = options .lookup_value ("cwd" ).get_string ()
168+ if options .contains ("command" ):
169+ command = options .lookup_value ("command" ).get_string ().split (" " )
170+ if options .contains ("env" ):
171+ env = options .lookup_value ("env" ).get_string ().split (" " )
172+ if options .contains ("actions" ):
173+ actions = options .lookup_value ("actions" ).get_string ().split (" " )
174+
175+ EasyTermLib (cwd , command , env , actions )
176+ return 0
115177
116178 def do_activate (self ):
117179 win = MainWindow (
@@ -121,13 +183,12 @@ def do_activate(self):
121183 actions = self .actions
122184 )
123185 win .connect ('delete-event' , Gtk .main_quit )
124- win .show_all ()
125- Gtk .main ()
186+ win .present ()
126187
127188 def do_startup (self ):
128189 Gtk .Application .do_startup (self )
129190
130191
131192if __name__ == "__main__" :
132193 app = EasyTerm ()
133- app .run (None )
194+ app .run (sys . argv )
0 commit comments