Add switch profile command to remotinator

This commit is contained in:
Leandro Thimóteo 2021-01-12 14:35:10 -03:00
parent 4891680119
commit f998353f9f
2 changed files with 28 additions and 8 deletions

View File

@ -14,7 +14,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA # USA
"""remotinator by Chris Jones <cmsj@tenshu.net>""" """remotinator by Chris Jones <cmsj@tenshu.net>"""
@ -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__':
@ -60,14 +61,21 @@ if __name__ == '__main__':
# Parse args # Parse args
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
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

@ -75,7 +75,7 @@ class DBusService(Borg, dbus.service.Object):
self.terminator.config.options_set(oldopts) self.terminator.config.options_set(oldopts)
self.terminator.create_layout(oldopts.layout) self.terminator.create_layout(oldopts.layout)
self.terminator.layout_done() self.terminator.layout_done()
@dbus.service.method(BUS_NAME, in_signature='a{ss}') @dbus.service.method(BUS_NAME, in_signature='a{ss}')
def new_tab_cmdline(self, options=dbus.Dictionary()): def new_tab_cmdline(self, options=dbus.Dictionary()):
"""Create a new tab""" """Create a new tab"""
@ -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__)
@ -209,7 +216,7 @@ def with_proxy(func):
sys.exit( sys.exit(
"Remotinator can't connect to terminator. " + "Remotinator can't connect to terminator. " +
"May be terminator is not running.") "May be terminator is not running.")
func(proxy, *args, **argd) func(proxy, *args, **argd)
return _exec return _exec
@ -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)