Add dbus mechanism to obtain a list of terminals

This commit is contained in:
Chris Jones 2011-08-25 22:10:04 +01:00
parent fdebe10d9d
commit 007ca36723
5 changed files with 41 additions and 6 deletions

View File

@ -30,6 +30,7 @@ APP_VERSION='1.0'
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'],
}
if __name__ == '__main__':
@ -50,6 +51,10 @@ if __name__ == '__main__':
err("Unknown command: %s" % command)
sys.exit(1)
if not os.environ.has_key('TERMINATOR_UUID'):
err("$TERMINATOR_UUID is not set. Are you definitely running inside Terminator?")
sys.exit(1)
func = getattr(ipc, COMMANDS[command][0])
func(os.environ['TERMINATOR_UUID'])

View File

@ -46,6 +46,8 @@ from terminatorlib.version import APP_NAME, APP_VERSION
from terminatorlib.util import dbg, err
if __name__ == '__main__':
dbus_service = None
dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))
OPTIONS = terminatorlib.optionparse.parse_options()
@ -61,7 +63,7 @@ if __name__ == '__main__':
raise ImportError
from terminatorlib import ipc
try:
ipc.DBusService()
dbus_service = ipc.DBusService()
except ipc.DBusException:
dbg('Unable to become master process, requesting a new window')
ipc.new_window(OPTIONS.layout)
@ -73,6 +75,7 @@ if __name__ == '__main__':
MAKER = Factory()
TERMINATOR = Terminator()
TERMINATOR.set_origcwd(ORIGCWD)
TERMINATOR.set_dbus_data(dbus_service)
TERMINATOR.reconfigure()
try:
dbg('Creating a terminal with layout: %s' % OPTIONS.layout)

View File

@ -30,6 +30,7 @@ except:
class DBusService(Borg, dbus.service.Object):
"""DBus Server class. This is implemented as a Borg"""
bus_name = None
bus_path = None
terminator = None
def __init__(self):
@ -52,6 +53,8 @@ class DBusService(Borg, dbus.service.Object):
"Couldn't get DBus name %s: Name exists" % BUS_NAME)
self.bus_name = dbus.service.BusName(BUS_NAME,
bus=dbus.SessionBus())
if not self.bus_path:
self.bus_path = BUS_PATH
if not self.terminator:
self.terminator = Terminator()
@ -65,12 +68,12 @@ class DBusService(Borg, dbus.service.Object):
@dbus.service.method(BUS_NAME)
def terminal_hsplit(self, uuid=None):
"""Split a terminal horizontally, by UUID"""
self.terminal_split(uuid, True)
return self.terminal_split(uuid, True)
@dbus.service.method(BUS_NAME)
def terminal_vsplit(self, uuid=None):
"""Split a terminal vertically, by UUID"""
self.terminal_split(uuid, False)
return self.terminal_split(uuid, False)
def terminal_split(self, uuid, horiz):
"""Split a terminal horizontally or vertically, by UUID"""
@ -85,6 +88,11 @@ class DBusService(Borg, dbus.service.Object):
else:
terminal.key_split_vert()
@dbus.service.method(BUS_NAME)
def get_terminals(self, uuid):
"""Return a list of all the terminals"""
return [x.uuid.urn for x in self.terminator.terminals]
def with_proxy(func):
"""Decorator function to connect to the session dbus bus"""
dbg('dbus client call: %s' % func.func_name)
@ -107,5 +115,10 @@ def terminal_hsplit(session, uuid):
@with_proxy
def terminal_vsplit(session, uuid):
"""Call the dbus method to vertically split a terminal"""
session.terminal_vsplit(uuid)
print session.terminal_vsplit(uuid)
@with_proxy
def get_terminals(session, uuid):
"""Call the dbus method to return a list of all terminals"""
print '\n'.join(session.get_terminals(uuid))

View File

@ -1203,9 +1203,15 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
except AttributeError:
pass
envv = []
envv.append('TERMINATOR_UUID=%s' % self.uuid.urn)
if self.terminator.dbus_name:
envv.append('TERMINATOR_DBUS_NAME=%s' % self.terminator.dbus_name)
if self.terminator.dbus_path:
envv.append('TERMINATOR_DBUS_PATH=%s' % self.terminator.dbus_path)
dbg('Forking shell: "%s" with args: %s' % (shell, args))
self.pid = self.vte.fork_command(command=shell, argv=args,
envv=['TERMINATOR_UUID=%s' % self.uuid.urn],
self.pid = self.vte.fork_command(command=shell, argv=args, envv=envv,
loglastlog=login,
logwtmp=update_records,
logutmp=update_records,

View File

@ -26,6 +26,8 @@ class Terminator(Borg):
keybindings = None
origcwd = None
dbus_path = None
dbus_name = None
pid_cwd = None
gnome_client = None
debug_address = None
@ -71,6 +73,12 @@ class Terminator(Borg):
os.chdir(cwd)
self.origcwd = cwd
def set_dbus_data(self, dbus_service):
"""Store the DBus bus details, if they are available"""
if dbus_service:
self.dbus_name = dbus_service.bus_name.get_name()
self.dbus_path = dbus_service.bus_path
def attempt_gnome_client(self):
"""Attempt to find a GNOME Session to register with"""
try: