From 55e8b65aed3a0004284151cf8976c1fd4d63f472 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 18 Oct 2012 13:58:38 -0700 Subject: [PATCH] Add support for fetching the current tab title via DBus. Closes LP#1067910 --- remotinator | 4 +++- terminatorlib/ipc.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/remotinator b/remotinator index f720851d..d464ee54 100755 --- a/remotinator +++ b/remotinator @@ -24,7 +24,7 @@ import sys from terminatorlib.util import dbg, err try: from terminatorlib import ipc -except ImportErrror: +except ImportError: err('Unable to initialise Terminator remote library. This probably means dbus is not available') sys.exit(1) @@ -35,6 +35,8 @@ COMMANDS={ 'hsplit': ['terminal_hsplit', 'Split the current terminal horizontally'], 'vsplit': ['terminal_vsplit', 'Split the current terminal vertically'], 'terminals': ['get_terminals', 'Get a list of all terminals'], + 'terminal_tab': ['get_terminal_tab', 'Get the UUID of a parent tab'], + 'terminal_tab_title': ['get_terminal_tab_title', 'Get the title of a parent tab'], } if __name__ == '__main__': diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index d413be84..47888a62 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -10,6 +10,7 @@ import dbus.glib from borg import Borg from terminator import Terminator from config import Config +from factory import Factory from util import dbg CONFIG = Config() @@ -93,6 +94,26 @@ class DBusService(Borg, dbus.service.Object): """Return a list of all the terminals""" return [x.uuid.urn for x in self.terminator.terminals] + @dbus.service.method(BUS_NAME) + def get_terminal_tab(self, uuid): + """Return the UUID of the parent tab of a given terminal""" + maker = Factory() + terminal = self.terminator.find_terminal_by_uuid(uuid) + window = terminal.get_toplevel() + root_widget = window.get_children()[0] + if maker.isinstance(root_widget, 'Notebook'): + return root_widget.uuid.urn + + @dbus.service.method(BUS_NAME) + def get_terminal_tab_title(self, uuid): + """Return the title of a parent tab of a given terminal""" + maker = Factory() + terminal = self.terminator.find_terminal_by_uuid(uuid) + window = terminal.get_toplevel() + root_widget = window.get_children()[0] + if maker.isinstance(root_widget, "Notebook"): + return root_widget.get_tab_label(terminal).get_label() + def with_proxy(func): """Decorator function to connect to the session dbus bus""" dbg('dbus client call: %s' % func.func_name) @@ -122,3 +143,13 @@ def get_terminals(session, uuid): """Call the dbus method to return a list of all terminals""" print '\n'.join(session.get_terminals(uuid)) +@with_proxy +def get_terminal_tab(session, uuid): + """Call the dbus method to return the toplevel tab for a terminal""" + print session.get_terminal_tab(uuid) + +@with_proxy +def get_terminal_tab_title(session, uuid): + """Call the dbus method to return the title of a tab""" + print session.get_terminal_tab_title(uuid) +