Merge pull request #361 from leandrost/feature/switch-profile

Remotinator "switch_profile" command
This commit is contained in:
Matt Rose 2021-01-14 14:48:44 -05:00 committed by GitHub
commit 440b0a22e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -45,6 +45,7 @@ COMMANDS={
'get_window_title': [True, _('Get the title of a parent window')], 'get_window_title': [True, _('Get the title of a parent window')],
'get_tab': [True, _('Get the UUID of a parent tab')], 'get_tab': [True, _('Get the UUID of a parent tab')],
'get_tab_title': [True, _('Get the title of a parent tab')], 'get_tab_title': [True, _('Get the title of a parent tab')],
'switch_profile': [True, _('Switch current terminal profile')],
} }
if __name__ == '__main__': if __name__ == '__main__':
@ -63,11 +64,18 @@ if __name__ == '__main__':
usage='%(prog)s command [options]', usage='%(prog)s command [options]',
description=_('Run one of the following Terminator DBus commands:\n\n%s') % (command_desc), description=_('Run one of the following Terminator DBus commands:\n\n%s') % (command_desc),
epilog=_('* These entries require either TERMINATOR_UUID environment var,\n or the --uuid option must be used.')) epilog=_('* These entries require either TERMINATOR_UUID environment var,\n or the --uuid option must be used.'))
parser.add_argument('-u', '--uuid', dest='uuid', type=str, metavar='UUID', default=argparse.SUPPRESS,
help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
parser.add_argument('command', type=str, nargs=1, choices=sorted(COMMANDS.keys()), parser.add_argument('command', type=str, nargs=1, choices=sorted(COMMANDS.keys()),
help=argparse.SUPPRESS) help=argparse.SUPPRESS)
parser.add_argument('-u', '--uuid', dest='uuid', type=str, metavar='UUID', default=argparse.SUPPRESS,
help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
parser.add_argument('-p', '--profile', dest='profile', type=str, default=argparse.SUPPRESS,
help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
parser.add_argument('-v', '--version', action='version', version='%%(prog)s %s' %(APP_VERSION)) parser.add_argument('-v', '--version', action='version', version='%%(prog)s %s' %(APP_VERSION))
options = vars(parser.parse_args()) # Straight to dict options = vars(parser.parse_args()) # Straight to dict
# Pull out the command # Pull out the command
@ -75,8 +83,8 @@ if __name__ == '__main__':
del options['command'] del options['command']
func = getattr(ipc, command) func = getattr(ipc, command)
uuid_required = COMMANDS[command][0] uuid_required = COMMANDS[command][0]
if uuid_required: if uuid_required:
uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID')) uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID'))
if uuid: if uuid:

View File

@ -197,6 +197,13 @@ class DBusService(Borg, dbus.service.Object):
if terminal in terms: if terminal in terms:
return root_widget.get_tab_label(tab_child).get_label() return root_widget.get_tab_label(tab_child).get_label()
@dbus.service.method(BUS_NAME)
def switch_profile(self, uuid=None, options=dbus.Dictionary()):
"""Switch profile of a given terminal"""
terminal = self.terminator.find_terminal_by_uuid(uuid)
profile_name = options.get('profile')
terminal.force_set_profile(False, profile_name)
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.__name__) dbg('dbus client call: %s' % func.__name__)
@ -272,3 +279,8 @@ def get_tab_title(session, uuid, options):
"""Call the dbus method to return the title of a tab""" """Call the dbus method to return the title of a tab"""
print(session.get_tab_title(uuid)) print(session.get_tab_title(uuid))
@with_proxy
def switch_profile(session, uuid, options):
"""Call the dbus method to return the title of a tab"""
session.switch_profile(uuid, options)