Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remotinator "switch_profile" command #361

Merged
merged 1 commit into from Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions remotinator
Expand Up @@ -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>"""
Expand Down Expand Up @@ -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__':
Expand All @@ -60,23 +61,30 @@ 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
command = options['command'][0]
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:
Expand Down
16 changes: 14 additions & 2 deletions terminatorlib/ipc.py
Expand Up @@ -75,7 +75,7 @@ def new_window_cmdline(self, options=dbus.Dictionary()):
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"""
Expand Down Expand Up @@ -197,6 +197,13 @@ def get_tab_title(self, uuid=None):
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__)
Expand All @@ -209,7 +216,7 @@ def _exec(*args, **argd):
sys.exit(
"Remotinator can't connect to terminator. " +
"May be terminator is not running.")

func(proxy, *args, **argd)
return _exec

Expand Down Expand Up @@ -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)