Add dbus mechanism to obtain a list of terminals
This commit is contained in:
parent
fdebe10d9d
commit
007ca36723
|
@ -30,6 +30,7 @@ APP_VERSION='1.0'
|
||||||
COMMANDS={
|
COMMANDS={
|
||||||
'hsplit': ['terminal_hsplit', 'Split the current terminal horizontally'],
|
'hsplit': ['terminal_hsplit', 'Split the current terminal horizontally'],
|
||||||
'vsplit': ['terminal_vsplit', 'Split the current terminal vertically'],
|
'vsplit': ['terminal_vsplit', 'Split the current terminal vertically'],
|
||||||
|
'terminals': ['get_terminals', 'Get a list of all terminals'],
|
||||||
}
|
}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -50,6 +51,10 @@ if __name__ == '__main__':
|
||||||
err("Unknown command: %s" % command)
|
err("Unknown command: %s" % command)
|
||||||
sys.exit(1)
|
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 = getattr(ipc, COMMANDS[command][0])
|
||||||
func(os.environ['TERMINATOR_UUID'])
|
func(os.environ['TERMINATOR_UUID'])
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ from terminatorlib.version import APP_NAME, APP_VERSION
|
||||||
from terminatorlib.util import dbg, err
|
from terminatorlib.util import dbg, err
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
dbus_service = None
|
||||||
|
|
||||||
dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))
|
dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))
|
||||||
|
|
||||||
OPTIONS = terminatorlib.optionparse.parse_options()
|
OPTIONS = terminatorlib.optionparse.parse_options()
|
||||||
|
@ -61,7 +63,7 @@ if __name__ == '__main__':
|
||||||
raise ImportError
|
raise ImportError
|
||||||
from terminatorlib import ipc
|
from terminatorlib import ipc
|
||||||
try:
|
try:
|
||||||
ipc.DBusService()
|
dbus_service = ipc.DBusService()
|
||||||
except ipc.DBusException:
|
except ipc.DBusException:
|
||||||
dbg('Unable to become master process, requesting a new window')
|
dbg('Unable to become master process, requesting a new window')
|
||||||
ipc.new_window(OPTIONS.layout)
|
ipc.new_window(OPTIONS.layout)
|
||||||
|
@ -73,6 +75,7 @@ if __name__ == '__main__':
|
||||||
MAKER = Factory()
|
MAKER = Factory()
|
||||||
TERMINATOR = Terminator()
|
TERMINATOR = Terminator()
|
||||||
TERMINATOR.set_origcwd(ORIGCWD)
|
TERMINATOR.set_origcwd(ORIGCWD)
|
||||||
|
TERMINATOR.set_dbus_data(dbus_service)
|
||||||
TERMINATOR.reconfigure()
|
TERMINATOR.reconfigure()
|
||||||
try:
|
try:
|
||||||
dbg('Creating a terminal with layout: %s' % OPTIONS.layout)
|
dbg('Creating a terminal with layout: %s' % OPTIONS.layout)
|
||||||
|
|
|
@ -30,6 +30,7 @@ except:
|
||||||
class DBusService(Borg, dbus.service.Object):
|
class DBusService(Borg, dbus.service.Object):
|
||||||
"""DBus Server class. This is implemented as a Borg"""
|
"""DBus Server class. This is implemented as a Borg"""
|
||||||
bus_name = None
|
bus_name = None
|
||||||
|
bus_path = None
|
||||||
terminator = None
|
terminator = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -52,6 +53,8 @@ class DBusService(Borg, dbus.service.Object):
|
||||||
"Couldn't get DBus name %s: Name exists" % BUS_NAME)
|
"Couldn't get DBus name %s: Name exists" % BUS_NAME)
|
||||||
self.bus_name = dbus.service.BusName(BUS_NAME,
|
self.bus_name = dbus.service.BusName(BUS_NAME,
|
||||||
bus=dbus.SessionBus())
|
bus=dbus.SessionBus())
|
||||||
|
if not self.bus_path:
|
||||||
|
self.bus_path = BUS_PATH
|
||||||
if not self.terminator:
|
if not self.terminator:
|
||||||
self.terminator = Terminator()
|
self.terminator = Terminator()
|
||||||
|
|
||||||
|
@ -65,12 +68,12 @@ class DBusService(Borg, dbus.service.Object):
|
||||||
@dbus.service.method(BUS_NAME)
|
@dbus.service.method(BUS_NAME)
|
||||||
def terminal_hsplit(self, uuid=None):
|
def terminal_hsplit(self, uuid=None):
|
||||||
"""Split a terminal horizontally, by UUID"""
|
"""Split a terminal horizontally, by UUID"""
|
||||||
self.terminal_split(uuid, True)
|
return self.terminal_split(uuid, True)
|
||||||
|
|
||||||
@dbus.service.method(BUS_NAME)
|
@dbus.service.method(BUS_NAME)
|
||||||
def terminal_vsplit(self, uuid=None):
|
def terminal_vsplit(self, uuid=None):
|
||||||
"""Split a terminal vertically, by UUID"""
|
"""Split a terminal vertically, by UUID"""
|
||||||
self.terminal_split(uuid, False)
|
return self.terminal_split(uuid, False)
|
||||||
|
|
||||||
def terminal_split(self, uuid, horiz):
|
def terminal_split(self, uuid, horiz):
|
||||||
"""Split a terminal horizontally or vertically, by UUID"""
|
"""Split a terminal horizontally or vertically, by UUID"""
|
||||||
|
@ -85,6 +88,11 @@ class DBusService(Borg, dbus.service.Object):
|
||||||
else:
|
else:
|
||||||
terminal.key_split_vert()
|
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):
|
def with_proxy(func):
|
||||||
"""Decorator function to connect to the session dbus bus"""
|
"""Decorator function to connect to the session dbus bus"""
|
||||||
dbg('dbus client call: %s' % func.func_name)
|
dbg('dbus client call: %s' % func.func_name)
|
||||||
|
@ -107,5 +115,10 @@ def terminal_hsplit(session, uuid):
|
||||||
@with_proxy
|
@with_proxy
|
||||||
def terminal_vsplit(session, uuid):
|
def terminal_vsplit(session, uuid):
|
||||||
"""Call the dbus method to vertically split a terminal"""
|
"""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))
|
||||||
|
|
||||||
|
|
|
@ -1203,9 +1203,15 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
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))
|
dbg('Forking shell: "%s" with args: %s' % (shell, args))
|
||||||
self.pid = self.vte.fork_command(command=shell, argv=args,
|
self.pid = self.vte.fork_command(command=shell, argv=args, envv=envv,
|
||||||
envv=['TERMINATOR_UUID=%s' % self.uuid.urn],
|
|
||||||
loglastlog=login,
|
loglastlog=login,
|
||||||
logwtmp=update_records,
|
logwtmp=update_records,
|
||||||
logutmp=update_records,
|
logutmp=update_records,
|
||||||
|
|
|
@ -26,6 +26,8 @@ class Terminator(Borg):
|
||||||
keybindings = None
|
keybindings = None
|
||||||
|
|
||||||
origcwd = None
|
origcwd = None
|
||||||
|
dbus_path = None
|
||||||
|
dbus_name = None
|
||||||
pid_cwd = None
|
pid_cwd = None
|
||||||
gnome_client = None
|
gnome_client = None
|
||||||
debug_address = None
|
debug_address = None
|
||||||
|
@ -71,6 +73,12 @@ class Terminator(Borg):
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
self.origcwd = 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):
|
def attempt_gnome_client(self):
|
||||||
"""Attempt to find a GNOME Session to register with"""
|
"""Attempt to find a GNOME Session to register with"""
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue