From d76b0dee7f25a39e656f389ac4ea473c926e3f6f Mon Sep 17 00:00:00 2001 From: Date: Thu, 29 Dec 2011 20:02:11 +0100 Subject: [PATCH 1/3] Added a parameter to the dbus method new_window, to allow the passing of the command to execute. --- terminator | 2 +- terminatorlib/ipc.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/terminator b/terminator index 1fd95ccd..7c4b978c 100755 --- a/terminator +++ b/terminator @@ -66,7 +66,7 @@ if __name__ == '__main__': dbus_service = ipc.DBusService() except ipc.DBusException: dbg('Unable to become master process, requesting a new window') - ipc.new_window(OPTIONS.layout) + ipc.new_window(OPTIONS.layout, OPTIONS.command or '') sys.exit() except ImportError: dbg('dbus not imported') diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index d413be84..dbcbaaef 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -59,11 +59,16 @@ class DBusService(Borg, dbus.service.Object): self.terminator = Terminator() @dbus.service.method(BUS_NAME) - def new_window(self, layout='default'): + def new_window(self, layout, command=''): """Create a new Window""" - dbg('dbus method called: new_window') + dbg('dbus method called: new_window with parameters %s, %s'%(layout, command)) + if command: + options = self.terminator.config.options_get() + options.command = command + self.terminator.config.options_set(options) self.terminator.create_layout(layout) self.terminator.layout_done() + @dbus.service.method(BUS_NAME) def terminal_hsplit(self, uuid=None): @@ -103,9 +108,9 @@ def with_proxy(func): return _exec @with_proxy -def new_window(session, layout='default'): +def new_window(session, layout='default', command=''): """Call the dbus method to open a new window""" - session.new_window(layout) + session.new_window(layout, command) @with_proxy def terminal_hsplit(session, uuid): From abdcc0f201f9181531c645e907496dc955fc571d Mon Sep 17 00:00:00 2001 From: Date: Thu, 29 Dec 2011 21:39:09 +0100 Subject: [PATCH 2/3] Changed the dbus method new_window to use an array of options instead of only passing the layout, also formatted a little the help strings in the optionparse module (to fit in 80 chars without breaking the indent) --- terminator | 14 +++++++++++++- terminatorlib/ipc.py | 19 +++++++++---------- terminatorlib/optionparse.py | 31 +++++++++++++++++-------------- terminatorlib/window.py | 6 +++--- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/terminator b/terminator index 7c4b978c..575bc604 100755 --- a/terminator +++ b/terminator @@ -62,11 +62,23 @@ if __name__ == '__main__': dbg('dbus disabled by command line') raise ImportError from terminatorlib import ipc + import dbus try: dbus_service = ipc.DBusService() except ipc.DBusException: dbg('Unable to become master process, requesting a new window') - ipc.new_window(OPTIONS.layout, OPTIONS.command or '') + # get rid of the None and True types so dbus can handle them (empty + # and 'True' strings are used instead), also arrays are joined + # (the -x argument for example) + optionslist = {} + for opt, val in OPTIONS.__dict__.items(): + if type(val) == type([]): + val = ' '.join(val) + if val == True: + val = 'True' + optionslist[opt] = val or '' + optionslist = dbus.Dictionary(optionslist, signature='ss') + ipc.new_window(optionslist) sys.exit() except ImportError: dbg('dbus not imported') diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index dbcbaaef..b791a40b 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -58,15 +58,14 @@ class DBusService(Borg, dbus.service.Object): if not self.terminator: self.terminator = Terminator() - @dbus.service.method(BUS_NAME) - def new_window(self, layout, command=''): + @dbus.service.method(BUS_NAME, in_signature='a{ss}') + def new_window(self, options=dbus.Dictionary()): """Create a new Window""" - dbg('dbus method called: new_window with parameters %s, %s'%(layout, command)) - if command: - options = self.terminator.config.options_get() - options.command = command - self.terminator.config.options_set(options) - self.terminator.create_layout(layout) + dbg('dbus method called: new_window with parameters %s'%(options)) + oldopts = self.terminator.config.options_get() + oldopts.__dict__ = options + self.terminator.config.options_set(oldopts) + self.terminator.create_layout(oldopts.layout) self.terminator.layout_done() @@ -108,9 +107,9 @@ def with_proxy(func): return _exec @with_proxy -def new_window(session, layout='default', command=''): +def new_window(session, options): """Call the dbus method to open a new window""" - session.new_window(layout, command) + session.new_window(options) @with_proxy def terminal_hsplit(session, uuid): diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index 13a2a09d..70a29165 100755 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -53,22 +53,25 @@ def parse_options(): dest='borderless', help=_('Disable window borders')) parser.add_option('-H', '--hidden', action='store_true', dest='hidden', help=_('Hide the window at startup')) - parser.add_option('-T', '--title', dest='forcedtitle', help=_('Specify a \ -title for the window')) - parser.add_option('--geometry', dest='geometry', type='string', help=_('Set \ -the preferred size and position of the window (see X man page)')) - parser.add_option('-e', '--command', dest='command', help=_('Specify a \ -command to execute inside the terminal')) + parser.add_option('-T', '--title', dest='forcedtitle', + help=_('Specify a title for the window')) + parser.add_option('--geometry', dest='geometry', type='string', + help=_('Set the preferred size and position of the window' + '(see X man page)')) + parser.add_option('-e', '--command', dest='command', + help=_('Specify a command to execute inside the terminal')) parser.add_option('-x', '--execute', dest='execute', action='callback', - callback=execute_cb, help=_('Use the rest of the command line as a \ -command to execute inside the terminal, and its arguments')) + callback=execute_cb, + help=_('Use the rest of the command line as a command to execute' + 'nside the terminal, and its arguments')) parser.add_option('--working-directory', metavar='DIR', dest='working_directory', help=_('Set the working directory')) - parser.add_option('-r', '--role', dest='role', help=_('Set a custom \ -WM_WINDOW_ROLE property on the window')) - parser.add_option('-l', '--layout', dest='layout', help=_('Select a layout')) - parser.add_option('-p', '--profile', dest='profile', help=_('Use a \ -different profile as the default')) + parser.add_option('-r', '--role', dest='role', + help=_('Set a custom WM_WINDOW_ROLE property on the window')) + parser.add_option('-l', '--layout', dest='layout', + help=_('Select a layout')) + parser.add_option('-p', '--profile', dest='profile', + help=_('Use a different profile as the default')) parser.add_option('-u', '--no-dbus', action='store_true', dest='nodbus', help=_('Disable DBus')) parser.add_option('-d', '--debug', action='count', dest='debug', @@ -78,7 +81,7 @@ different profile as the default')) parser.add_option('--debug-methods', action='store', dest='debug_methods', help=_('Comma separated list of methods to limit debugging to')) for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n', - '--no-gconf' ]: + '--no-gconf' ]: parser.add_option(item, dest='dummy', action='store', help=SUPPRESS_HELP) diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 8fb4fbf7..1921bb7a 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -70,13 +70,13 @@ class Window(Container, gtk.Window): options = self.config.options_get() if options: - if options.forcedtitle is not None: + if options.forcedtitle: self.title.force_title(options.forcedtitle) - if options.role is not None: + if options.role: self.set_role(options.role) - if options.geometry is not None: + if options.geometry: if not self.parse_geometry(options.geometry): err('Window::__init__: Unable to parse geometry: %s' % options.geometry) From f12f7e7b47218dd2e51fba89c235a7f09fb154a0 Mon Sep 17 00:00:00 2001 From: Date: Thu, 29 Dec 2011 21:43:12 +0100 Subject: [PATCH 3/3] Added a little transformatios to make sure all the parameters of the config are passed to string before calling the dbus method (integers for example). --- terminator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminator b/terminator index 575bc604..f0f8a41a 100755 --- a/terminator +++ b/terminator @@ -76,7 +76,7 @@ if __name__ == '__main__': val = ' '.join(val) if val == True: val = 'True' - optionslist[opt] = val or '' + optionslist[opt] = val and '%s'%val or '' optionslist = dbus.Dictionary(optionslist, signature='ss') ipc.new_window(optionslist) sys.exit()