From 0434880f137d59c36f78b03ac737ae2434fa6b50 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Sat, 14 Aug 2021 11:38:49 -0400 Subject: [PATCH 1/2] initial commit for remotinator background image command --- remotinator | 4 ++++ terminatorlib/ipc.py | 14 ++++++++++++++ terminatorlib/terminal.py | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/remotinator b/remotinator index 3760b34b..f846ae19 100755 --- a/remotinator +++ b/remotinator @@ -47,6 +47,7 @@ COMMANDS={ 'get_tab': [True, _('Get the UUID of a parent tab')], 'get_tab_title': [True, _('Get the title of a parent tab')], 'set_tab_title': [True, _('Set the title of a parent tab')], + 'bg_img': [True, _('Set the background image')]. 'switch_profile': [True, _('Switch current terminal profile')], 'switch_profile_all': [False, _('Switch profile of all currently running terminals')], } @@ -77,6 +78,9 @@ if __name__ == '__main__': 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('-f', '--file', dest='file', type=str, default=argparse.SUPPRESS, + help=_('File to pass to command')) + parser.add_argument('-x', '--execute', dest='execute', type=str, default=argparse.SUPPRESS, help=_('Terminal UUID for when not in env var TERMINATOR_UUID')) diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index a06516d9..a1161526 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -124,6 +124,16 @@ def new_tab(self, uuid=None): """Create a new tab""" return self.new_terminal(uuid, 'tab') + @dbus.service.method(BUS_NAME) + def bg_img(self,uuid=None,options=None): + terminals = [] + if uuid: + terminals.append(self.terminator.find_terminal_by_uuid(uuid)) + else: + terminals = self.get_terminals() + for terminal in terminals: + terminal.set_background_image(options.get('file')) + @dbus.service.method(BUS_NAME) def hsplit(self, uuid=None,options=None): """Split a terminal horizontally, by UUID""" @@ -422,3 +432,7 @@ def switch_profile(session, uuid, options): def switch_profile_all(session,options): """Call the dbus method to return the title of a tab""" session.switch_profile_all(options) + +@with_proxy +def bg_img(session,uuid,options): + session.bg_img(uuid,options) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 0226cc1b..6bc3f9e8 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -203,6 +203,16 @@ def __init__(self): self.reconfigure() self.vte.set_size(80, 24) + def set_background_image(self,image): + try: + self.background_image = GdkPixbuf.Pixbuf.new_from_file(image) + self.vte.set_clear_background(False) + self.vte.connect("draw",self.background_draw) + except Exception as e: + self.background_image = None + self.vte.set_clear_background(True) + err('error loading background image: %s, %s' % (type(e).__name__,e)) + def get_vte(self): """This simply returns the vte widget we are using""" return(self.vte) From c11c9a0db030f18ff590da15b9caa45fd08785ed Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Mon, 16 Aug 2021 19:16:21 -0400 Subject: [PATCH 2/2] add bg_img_all command to switch background on all terminals --- remotinator | 7 ++++--- terminatorlib/ipc.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/remotinator b/remotinator index f846ae19..4cf30b93 100755 --- a/remotinator +++ b/remotinator @@ -47,7 +47,8 @@ COMMANDS={ 'get_tab': [True, _('Get the UUID of a parent tab')], 'get_tab_title': [True, _('Get the title of a parent tab')], 'set_tab_title': [True, _('Set the title of a parent tab')], - 'bg_img': [True, _('Set the background image')]. + 'bg_img': [True, _('Set the background image')], + 'bg_img_all': [False, _('Set the background image for all terminals')], 'switch_profile': [True, _('Switch current terminal profile')], 'switch_profile_all': [False, _('Switch profile of all currently running terminals')], } @@ -76,13 +77,13 @@ if __name__ == '__main__': 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')) + help=_('Profile name to switch to')) parser.add_argument('-f', '--file', dest='file', type=str, default=argparse.SUPPRESS, help=_('File to pass to command')) parser.add_argument('-x', '--execute', dest='execute', type=str, default=argparse.SUPPRESS, - help=_('Terminal UUID for when not in env var TERMINATOR_UUID')) + help=_('Command to run in new terminal')) parser.add_argument('-t', '--tab-title', dest='tab-title', type=str, default="Missing Tab Title! Use -t argument!", help=_('Tab name to set. Only used with "set_tab_title" command.')) diff --git a/terminatorlib/ipc.py b/terminatorlib/ipc.py index a1161526..1e24f124 100644 --- a/terminatorlib/ipc.py +++ b/terminatorlib/ipc.py @@ -125,14 +125,13 @@ def new_tab(self, uuid=None): return self.new_terminal(uuid, 'tab') @dbus.service.method(BUS_NAME) - def bg_img(self,uuid=None,options=None): - terminals = [] - if uuid: - terminals.append(self.terminator.find_terminal_by_uuid(uuid)) - else: - terminals = self.get_terminals() - for terminal in terminals: + def bg_img_all (self,options=dbus.Dictionary()): + for terminal in self.terminator.terminals: terminal.set_background_image(options.get('file')) + + @dbus.service.method(BUS_NAME) + def bg_img(self,uuid=None,options=dbus.Dictionary()): + self.terminator.find_terminal_by_uuid(uuid).set_background_image(options.get('file')) @dbus.service.method(BUS_NAME) def hsplit(self, uuid=None,options=None): @@ -212,7 +211,7 @@ def new_terminal_cmd(self, uuid=None, title=None, cmd=None, split_vert=False): return new_terminal_set[0] def new_terminal(self, uuid, type): - """Split a terminal horizontally or vertically, by UUID""" + """Split a terminal horizontally o?r vertically, by UUID""" dbg('dbus method called: %s' % type) if not uuid: return "ERROR: No UUID specified" @@ -433,6 +432,10 @@ def switch_profile_all(session,options): """Call the dbus method to return the title of a tab""" session.switch_profile_all(options) +@with_proxy +def bg_img_all(session,options): + session.bg_img_all(options) + @with_proxy def bg_img(session,uuid,options): session.bg_img(uuid,options)