From 5d35c196c71fc06590d2e353d463435c00db8276 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 30 Oct 2012 00:11:24 +0000 Subject: [PATCH] Add a command line option to spawn new tabs via DBus --- ChangeLog | 1 + doc/terminator.1 | 4 ++++ terminator | 9 +++++++-- terminatorlib/ipc.py | 14 ++++++++++++++ terminatorlib/optionparse.py | 2 ++ terminatorlib/terminator.py | 4 ++++ terminatorlib/window.py | 2 +- 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02dd90ee..51107831 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ terminator 1.0: John Feuerstein * Support reading configuration from alternate files, via a patch from Pavel Khlebovich + * Allow creation of new tabs in existing Terminators, via DBus * Bug fixes terminator 0.96: diff --git a/doc/terminator.1 b/doc/terminator.1 index 1a7294d2..c63edc16 100644 --- a/doc/terminator.1 +++ b/doc/terminator.1 @@ -86,6 +86,10 @@ only be printed from the specified functions. If this is specified in addition to \-\-debug-classes, only the intersection of the two lists will be displayed .TP +.B \-\-new-tab +If this is specified and Terminator is already running, DBus will be +used to spawn a new tab in the first Terminator window. +.TP .SH "KEYBINDINGS" The following keybindings can be used to control Terminator: .TP diff --git a/terminator b/terminator index f0f8a41a..8164c909 100755 --- a/terminator +++ b/terminator @@ -66,7 +66,7 @@ if __name__ == '__main__': try: dbus_service = ipc.DBusService() except ipc.DBusException: - dbg('Unable to become master process, requesting a new window') + dbg('Unable to become master process, operating via DBus') # 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) @@ -78,7 +78,12 @@ if __name__ == '__main__': val = 'True' optionslist[opt] = val and '%s'%val or '' optionslist = dbus.Dictionary(optionslist, signature='ss') - ipc.new_window(optionslist) + if OPTIONS.new_tab: + dbg('Requesting a new tab') + ipc.new_tab(optionslist) + else: + dbg('Requesting a new window') + ipc.new_window(optionslist) sys.exit() except ImportError: dbg('dbus not imported') diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index c7a3f0da..87e0344d 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -69,6 +69,15 @@ class DBusService(Borg, dbus.service.Object): self.terminator.create_layout(oldopts.layout) self.terminator.layout_done() + @dbus.service.method(BUS_NAME, in_signature='a{ss}') + def new_tab(self, options=dbus.Dictionary()): + """Create a new tab""" + dbg('dbus method called: new_tab with parameters %s'%(options)) + oldopts = self.terminator.config.options_get() + oldopts.__dict__ = options + self.terminator.config.options_set(oldopts) + window = self.terminator.get_windows()[0] + window.tab_new() @dbus.service.method(BUS_NAME) def terminal_hsplit(self, uuid=None): @@ -132,6 +141,11 @@ def new_window(session, options): """Call the dbus method to open a new window""" session.new_window(options) +@with_proxy +def new_tab(session, options): + """Call the dbus method to open a new tab in the first window""" + session.new_tab(options) + @with_proxy def terminal_hsplit(session, uuid): """Call the dbus method to horizontally split a terminal""" diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index 9cdabc23..e74997dd 100755 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -87,6 +87,8 @@ icon for the window (by file or name)')) help=_('Comma separated list of classes to limit debugging to')) parser.add_option('--debug-methods', action='store', dest='debug_methods', help=_('Comma separated list of methods to limit debugging to')) + parser.add_option('--new-tab', action='store_true', dest='new_tab', + help=_('If Terminator is already running, just open a new tab')) for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n', '--no-gconf' ]: parser.add_option(item, dest='dummy', action='store', diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 5bea899a..29eaa97c 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -104,6 +104,10 @@ class Terminator(Borg): dbg('session manager asked us to die') # FIXME: Implement this + def get_windows(self): + """Return a list of windows""" + return self.windows + def register_window(self, window): """Register a new window widget""" if window not in self.windows: diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 7031400a..e39fa714 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -262,7 +262,7 @@ class Window(Container, gtk.Window): if not self.is_child_notebook(): dbg('Making a new Notebook') notebook = maker.make('Notebook', window=self) - self.get_child().newtab(debugtab, cwd=cwd, profile=profile) + return self.get_child().newtab(debugtab, cwd=cwd, profile=profile) def on_delete_event(self, window, event, data=None): """Handle a window close request"""