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

@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# 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
"""remotinator by Chris Jones <cmsj@tenshu.net>"""
@ -45,6 +45,7 @@ COMMANDS={
'get_window_title': [True, _('Get the title of a parent window')],
'get_tab': [True, _('Get the UUID 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__':
@ -60,14 +61,21 @@ if __name__ == '__main__':
# Parse args
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
usage='%(prog)s command [options]',
description=_('Run one of the following Terminator DBus commands:\n\n%s') % (command_desc),
usage='%(prog)s command [options]',
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.'))
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()),
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))
options = vars(parser.parse_args()) # Straight to dict
# Pull out the command
@ -75,8 +83,8 @@ if __name__ == '__main__':
del options['command']
func = getattr(ipc, command)
uuid_required = COMMANDS[command][0]
if uuid_required:
uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID'))
if uuid:

View File

@ -75,7 +75,7 @@ class DBusService(Borg, dbus.service.Object):
self.terminator.config.options_set(oldopts)
self.terminator.create_layout(oldopts.layout)
self.terminator.layout_done()
@dbus.service.method(BUS_NAME, in_signature='a{ss}')
def new_tab_cmdline(self, options=dbus.Dictionary()):
"""Create a new tab"""
@ -197,6 +197,13 @@ class DBusService(Borg, dbus.service.Object):
if terminal in terms:
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):
"""Decorator function to connect to the session dbus bus"""
dbg('dbus client call: %s' % func.__name__)
@ -209,7 +216,7 @@ def with_proxy(func):
sys.exit(
"Remotinator can't connect to terminator. " +
"May be terminator is not running.")
func(proxy, *args, **argd)
return _exec
@ -272,3 +279,8 @@ def get_tab_title(session, uuid, options):
"""Call the dbus method to return the title of a tab"""
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)