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)
This commit is contained in:
2011-12-29 21:39:09 +01:00
parent d76b0dee7f
commit abdcc0f201
4 changed files with 42 additions and 28 deletions

View File

@ -62,11 +62,23 @@ if __name__ == '__main__':
dbg('dbus disabled by command line') dbg('dbus disabled by command line')
raise ImportError raise ImportError
from terminatorlib import ipc from terminatorlib import ipc
import dbus
try: try:
dbus_service = 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, 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() sys.exit()
except ImportError: except ImportError:
dbg('dbus not imported') dbg('dbus not imported')

View File

@ -58,15 +58,14 @@ class DBusService(Borg, dbus.service.Object):
if not self.terminator: if not self.terminator:
self.terminator = Terminator() self.terminator = Terminator()
@dbus.service.method(BUS_NAME) @dbus.service.method(BUS_NAME, in_signature='a{ss}')
def new_window(self, layout, command=''): def new_window(self, options=dbus.Dictionary()):
"""Create a new Window""" """Create a new Window"""
dbg('dbus method called: new_window with parameters %s, %s'%(layout, command)) dbg('dbus method called: new_window with parameters %s'%(options))
if command: oldopts = self.terminator.config.options_get()
options = self.terminator.config.options_get() oldopts.__dict__ = options
options.command = command self.terminator.config.options_set(oldopts)
self.terminator.config.options_set(options) self.terminator.create_layout(oldopts.layout)
self.terminator.create_layout(layout)
self.terminator.layout_done() self.terminator.layout_done()
@ -108,9 +107,9 @@ def with_proxy(func):
return _exec return _exec
@with_proxy @with_proxy
def new_window(session, layout='default', command=''): def new_window(session, options):
"""Call the dbus method to open a new window""" """Call the dbus method to open a new window"""
session.new_window(layout, command) session.new_window(options)
@with_proxy @with_proxy
def terminal_hsplit(session, uuid): def terminal_hsplit(session, uuid):

View File

@ -53,22 +53,25 @@ def parse_options():
dest='borderless', help=_('Disable window borders')) dest='borderless', help=_('Disable window borders'))
parser.add_option('-H', '--hidden', action='store_true', dest='hidden', parser.add_option('-H', '--hidden', action='store_true', dest='hidden',
help=_('Hide the window at startup')) help=_('Hide the window at startup'))
parser.add_option('-T', '--title', dest='forcedtitle', help=_('Specify a \ parser.add_option('-T', '--title', dest='forcedtitle',
title for the window')) help=_('Specify a title for the window'))
parser.add_option('--geometry', dest='geometry', type='string', help=_('Set \ parser.add_option('--geometry', dest='geometry', type='string',
the preferred size and position of the window (see X man page)')) help=_('Set the preferred size and position of the window'
parser.add_option('-e', '--command', dest='command', help=_('Specify a \ '(see X man page)'))
command to execute inside the terminal')) 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', parser.add_option('-x', '--execute', dest='execute', action='callback',
callback=execute_cb, help=_('Use the rest of the command line as a \ callback=execute_cb,
command to execute inside the terminal, and its arguments')) 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', parser.add_option('--working-directory', metavar='DIR',
dest='working_directory', help=_('Set the working directory')) dest='working_directory', help=_('Set the working directory'))
parser.add_option('-r', '--role', dest='role', help=_('Set a custom \ parser.add_option('-r', '--role', dest='role',
WM_WINDOW_ROLE property on the window')) 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('-l', '--layout', dest='layout',
parser.add_option('-p', '--profile', dest='profile', help=_('Use a \ help=_('Select a layout'))
different profile as the default')) 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', parser.add_option('-u', '--no-dbus', action='store_true', dest='nodbus',
help=_('Disable DBus')) help=_('Disable DBus'))
parser.add_option('-d', '--debug', action='count', dest='debug', 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', parser.add_option('--debug-methods', action='store', dest='debug_methods',
help=_('Comma separated list of methods to limit debugging to')) help=_('Comma separated list of methods to limit debugging to'))
for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n', for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n',
'--no-gconf' ]: '--no-gconf' ]:
parser.add_option(item, dest='dummy', action='store', parser.add_option(item, dest='dummy', action='store',
help=SUPPRESS_HELP) help=SUPPRESS_HELP)

View File

@ -70,13 +70,13 @@ class Window(Container, gtk.Window):
options = self.config.options_get() options = self.config.options_get()
if options: if options:
if options.forcedtitle is not None: if options.forcedtitle:
self.title.force_title(options.forcedtitle) self.title.force_title(options.forcedtitle)
if options.role is not None: if options.role:
self.set_role(options.role) self.set_role(options.role)
if options.geometry is not None: if options.geometry:
if not self.parse_geometry(options.geometry): if not self.parse_geometry(options.geometry):
err('Window::__init__: Unable to parse geometry: %s' % err('Window::__init__: Unable to parse geometry: %s' %
options.geometry) options.geometry)