Merge pull request #435 from yusufgungor/master

Added set_tab_title command to remotinator.
This commit is contained in:
Matt Rose 2021-05-09 10:35:12 -04:00 committed by GitHub
commit fec99bc234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 10 deletions

View File

@ -46,7 +46,8 @@ 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')], 'set_tab_title': [True, _('Set the title of a parent tab')],
'switch_profile': [True, _('Switch current terminal profile')],
} }
if __name__ == '__main__': if __name__ == '__main__':
@ -75,6 +76,9 @@ if __name__ == '__main__':
parser.add_argument('-p', '--profile', dest='profile', type=str, default=argparse.SUPPRESS, parser.add_argument('-p', '--profile', dest='profile', type=str, default=argparse.SUPPRESS,
help=_('Terminal UUID for when not in env var TERMINATOR_UUID')) help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
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.'))
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

View File

@ -56,14 +56,14 @@ class DBusService(Borg, dbus.service.Object):
except Exception as e: except Exception as e:
err('Unable to connect to DBUS Server, proceeding as standalone') err('Unable to connect to DBUS Server, proceeding as standalone')
raise ImportError raise ImportError
proxy = bus.get_object('org.freedesktop.DBus', proxy = bus.get_object('org.freedesktop.DBus',
'/org/freedesktop/DBus') '/org/freedesktop/DBus')
flags = 1 | 4 # allow replacement | do not queue flags = 1 | 4 # allow replacement | do not queue
if not proxy.RequestName(BUS_NAME, dbus.UInt32(flags)) in (1, 4): if not proxy.RequestName(BUS_NAME, dbus.UInt32(flags)) in (1, 4):
dbg('bus name unavailable: %s' % BUS_NAME) dbg('bus name unavailable: %s' % BUS_NAME)
raise dbus.exceptions.DBusException( raise dbus.exceptions.DBusException(
"Couldn't get DBus name %s: Name exists" % BUS_NAME) "Couldn't get DBus name %s: Name exists" % BUS_NAME)
self.bus_name = dbus.service.BusName(BUS_NAME, self.bus_name = dbus.service.BusName(BUS_NAME,
bus=dbus.SessionBus()) bus=dbus.SessionBus())
if not self.bus_path: if not self.bus_path:
self.bus_path = BUS_PATH self.bus_path = BUS_PATH
@ -265,6 +265,24 @@ 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 set_tab_title(self, uuid=None, options=dbus.Dictionary()):
"""Set the title of a parent tab of a given terminal"""
tab_title = options.get('tab-title')
maker = Factory()
terminal = self.terminator.find_terminal_by_uuid(uuid)
window = terminal.get_toplevel()
if not window.is_child_notebook():
return
notebook = window.get_children()[0]
n_page = notebook.get_current_page()
page = notebook.get_nth_page(n_page)
label = notebook.get_tab_label(page)
label.set_custom_label(tab_title, force=True)
@dbus.service.method(BUS_NAME) @dbus.service.method(BUS_NAME)
def switch_profile(self, uuid=None, options=dbus.Dictionary()): def switch_profile(self, uuid=None, options=dbus.Dictionary()):
"""Switch profile of a given terminal""" """Switch profile of a given terminal"""
@ -362,6 +380,11 @@ 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 set_tab_title(session, uuid, options):
"""Call the dbus method to set the title of a tab"""
session.set_tab_title(uuid, options)
@with_proxy @with_proxy
def switch_profile(session, uuid, options): def switch_profile(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"""

View File

@ -202,7 +202,7 @@ class Notebook(Container, Gtk.Notebook):
"""Remove a widget from the container""" """Remove a widget from the container"""
page_num = self.page_num(widget) page_num = self.page_num(widget)
if page_num == -1: if page_num == -1:
err('%s not found in Notebook. Actual parent is: %s' % err('%s not found in Notebook. Actual parent is: %s' %
(widget, widget.get_parent())) (widget, widget.get_parent()))
return(False) return(False)
self.remove_page(page_num) self.remove_page(page_num)
@ -410,7 +410,7 @@ class Notebook(Container, Gtk.Notebook):
if not label: if not label:
err('Notebook::update_tab_label_text: %s not found' % widget) err('Notebook::update_tab_label_text: %s not found' % widget)
return return
label.set_label(text) label.set_label(text)
def hoover(self): def hoover(self):
@ -474,7 +474,7 @@ class Notebook(Container, Gtk.Notebook):
"""Prime a single idle tab switch signal, using the most recent set of params""" """Prime a single idle tab switch signal, using the most recent set of params"""
tabs_last_active_term = self.last_active_term.get(self.get_nth_page(page_num), None) tabs_last_active_term = self.last_active_term.get(self.get_nth_page(page_num), None)
data = {'tabs_last_active_term':tabs_last_active_term} data = {'tabs_last_active_term':tabs_last_active_term}
self.pending_on_tab_switch_args = (notebook, page, page_num, data) self.pending_on_tab_switch_args = (notebook, page, page_num, data)
if self.pending_on_tab_switch == True: if self.pending_on_tab_switch == True:
return return
@ -507,7 +507,7 @@ class Notebook(Container, Gtk.Notebook):
return False return False
event_widget = Gtk.get_event_widget(event) event_widget = Gtk.get_event_widget(event)
if event_widget == None or \ if event_widget == None or \
event_widget == child or \ event_widget == child or \
event_widget.is_ancestor(child): event_widget.is_ancestor(child):
@ -583,9 +583,9 @@ class TabLabel(Gtk.HBox):
def get_label(self): def get_label(self):
return self.label.get_text() return self.label.get_text()
def set_custom_label(self, text): def set_custom_label(self, text, force=False):
"""Set a permanent label as if the user had edited it""" """Set a permanent label as if the user had edited it"""
self.label.set_text(text) self.label.set_text(text, force=force)
self.label.set_custom() self.label.set_custom()
def get_custom_label(self): def get_custom_label(self):
@ -615,7 +615,7 @@ class TabLabel(Gtk.HBox):
if not self.icon: if not self.icon:
self.icon = Gio.ThemedIcon.new_with_default_fallbacks("window-close-symbolic") self.icon = Gio.ThemedIcon.new_with_default_fallbacks("window-close-symbolic")
self.icon = Gtk.Image.new_from_gicon(self.icon, Gtk.IconSize.MENU) self.icon = Gtk.Image.new_from_gicon(self.icon, Gtk.IconSize.MENU)
self.button.set_focus_on_click(False) self.button.set_focus_on_click(False)
self.button.set_relief(Gtk.ReliefStyle.NONE) self.button.set_relief(Gtk.ReliefStyle.NONE)
# style = Gtk.RcStyle() # FIXME FOR GTK3 how to do it there? actually do we really want to override the theme? # style = Gtk.RcStyle() # FIXME FOR GTK3 how to do it there? actually do we really want to override the theme?