class TabLabel(gtk.HBox): """Class implementing a label widget for Notebook tabs""" notebook = None terminator = None config = None label = None icon = None button = None __gsignals__ = { 'close-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT,)), } def __init__(self, title, notebook): """Class initialiser""" gtk.HBox.__init__(self) self.__gobject_init__() self.notebook = notebook self.terminator = Terminator() self.config = Config() self.label = EditableLabel(title) self.update_angle() self.pack_start(self.label, True, True) self.update_button() self.show_all() def set_label(self, text): """Update the text of our label""" self.label.set_text(text) def get_label(self): return self.label.get_text() def set_custom_label(self, text): """Set a permanent label as if the user had edited it""" self.label.set_text(text) self.label.set_custom() def get_custom_label(self): """Return a custom label if we have one, otherwise None""" if self.label.is_custom(): return(self.label.get_text()) else: return(None) def edit(self): self.label.edit() def update_button(self): """Update the state of our close button""" if not self.config['close_button_on_tab']: if self.button: self.button.remove(self.icon) self.remove(self.button) del(self.button) del(self.icon) self.button = None self.icon = None return if not self.button: self.button = gtk.Button() if not self.icon: self.icon = gtk.Image() self.icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self.button.set_focus_on_click(False) self.button.set_relief(gtk.RELIEF_NONE) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('terminator-tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text(_('Close Tab')) self.pack_start(self.button, False, False) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == gtk.POS_LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(90) elif position == gtk.POS_RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_HORIZONTAL) self.label.set_angle(0) def on_close(self, _widget): """The close button has been clicked. Destroy the tab""" self.emit('close-clicked', self)
class TabLabel(Gtk.HBox): """Class implementing a label widget for Notebook tabs""" notebook = None terminator = None config = None label = None icon = None button = None __gsignals__ = { 'close-clicked': (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_OBJECT,)), } def __init__(self, title, notebook): """Class initialiser""" GObject.GObject.__init__(self) self.notebook = notebook self.terminator = Terminator() self.config = Config() self.label = EditableLabel(title) self.update_angle() self.pack_start(self.label, True, True, 0) self.update_button() self.show_all() def set_label(self, text): """Update the text of our label""" self.label.set_text(text) def get_label(self): return self.label.get_text() def set_custom_label(self, text): """Set a permanent label as if the user had edited it""" self.label.set_text(text) self.label.set_custom() def get_custom_label(self): """Return a custom label if we have one, otherwise None""" if self.label.is_custom(): return(self.label.get_text()) else: return(None) def edit(self): self.label.edit() def update_button(self): """Update the state of our close button""" if not self.config['close_button_on_tab']: if self.button: self.button.remove(self.icon) self.remove(self.button) del(self.button) del(self.icon) self.button = None self.icon = None return if not self.button: self.button = Gtk.Button() if not self.icon: self.icon = Gio.ThemedIcon.new_with_default_fallbacks("window-close-symbolic") self.icon = Gtk.Image.new_from_gicon(self.icon, Gtk.IconSize.MENU) self.button.set_focus_on_click(False) 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.xthickness = 0 # style.ythickness = 0 # self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('terminator-tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text(_('Close Tab')) self.pack_start(self.button, False, False, 0) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == Gtk.PositionType.LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.VERTICAL) self.label.set_angle(90) elif position == Gtk.PositionType.RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.HORIZONTAL) self.label.set_angle(0) def on_close(self, _widget): """The close button has been clicked. Destroy the tab""" self.emit('close-clicked', self)
class GshellTabLabel(gtk.HBox): __gsignals__ = { 'close-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT, )), } def __init__(self, title, notebook): gtk.HBox.__init__(self) self.notebook = notebook self.config = Config() self.terminal = None self.label = EditableLabel(title) self.update_angle() self.broadcast_image = None self.prefix_box = gtk.HBox() self.pack_start(self.prefix_box, False, False) self.pack_start(self.label, True, True) self.update_button() self.connect('button-press-event', self.show_popupmenu) self.show_all() def show_popupmenu(self, widget, event): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3 and self.terminal: popupmenu = GshellTabPopupMenu(tablabel=self, notebook=self.notebook) popupmenu.popup(None, None, None, event.button, event.time) return False def on_enable_broadcast(self, widget, *args): if self.terminal: self.terminal.emit('enable-broadcast', self) def enable_log(self, widget, *args): if self.terminal and self.terminal.logger: if self.terminal.logger.logging: self.terminal.logger.stop_logger() else: if self.terminal.host and self.terminal.host['log']: self.terminal.logger.start_logger( self.terminal.host['log']) else: self.terminal.logger.start_logger() def update_button(self): self.button = gtk.Button() self.icon = gtk.Image() self.icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self.button.set_focus_on_click(False) self.button.set_relief(gtk.RELIEF_NONE) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text('Close Tab') self.pack_start(self.button, False, False) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == gtk.POS_LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(90) elif position == gtk.POS_RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_HORIZONTAL) self.label.set_angle(0) def on_close(self, widget, data=None): print 'GshellTabLabel::on_close called' self.emit('close-clicked', self) def mark_close(self): text = self.label._label.get_text() self.label._label.set_markup( "<span color='darkgray' strikethrough='true'>%s</span>" % text) def unmark_close(self): text = self.label._label.get_text() self.label.set_text(text)
class TabLabel(gtk.HBox): """Class implementing a label widget for Notebook tabs""" notebook = None terminator = None config = None label = None icon = None button = None __gsignals__ = { 'close-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_OBJECT, )), } def __init__(self, title, notebook): """Class initialiser""" gtk.HBox.__init__(self) self.__gobject_init__() self.notebook = notebook self.terminator = Terminator() self.config = Config() self.label = EditableLabel(title) self.update_angle() self.pack_start(self.label, True, True) self.update_button() self.show_all() def set_label(self, text): """Update the text of our label""" self.label.set_text(text) def get_label(self): return self.label.get_text() def set_custom_label(self, text): """Set a permanent label as if the user had edited it""" self.label.set_text(text) self.label.set_custom() def get_custom_label(self): """Return a custom label if we have one, otherwise None""" if self.label.is_custom(): return (self.label.get_text()) else: return (None) def update_button(self): """Update the state of our close button""" if not self.config['close_button_on_tab']: if self.button: self.button.remove(self.icon) self.remove(self.button) del (self.button) del (self.icon) self.button = None self.icon = None return if not self.button: self.button = gtk.Button() if not self.icon: self.icon = gtk.Image() self.icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self.button.set_focus_on_click(False) self.button.set_relief(gtk.RELIEF_NONE) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('terminator-tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text(_('Close Tab')) self.pack_start(self.button, False, False) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == gtk.POS_LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(90) elif position == gtk.POS_RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_HORIZONTAL) self.label.set_angle(0) def on_close(self, _widget): """The close button has been clicked. Destroy the tab""" self.emit('close-clicked', self)
class TabLabel(Gtk.HBox): """Class implementing a label widget for Notebook tabs""" notebook = None terminator = None config = None label = None icon = None button = None __gsignals__ = { 'close-clicked': (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_OBJECT, )), } def __init__(self, title, notebook): """Class initialiser""" GObject.GObject.__init__(self) self.notebook = notebook self.terminator = Terminator() self.config = Config() self.label = EditableLabel(title) self.label.connect("button-press-event", self.on_title_click) self.update_angle() self.pack_start(self.label, True, True, 0) self.update_button() self.show_all() def set_label(self, text): """Update the text of our label""" self.label.set_text(text) def get_label(self): return self.label.get_text() def set_custom_label(self, text): """Set a permanent label as if the user had edited it""" self.label.set_text(text) self.label.set_custom() def get_custom_label(self): """Return a custom label if we have one, otherwise None""" if self.label.is_custom(): return (self.label.get_text()) else: return (None) def edit(self): self.label.edit() def update_button(self): """Update the state of our close button""" if not self.config['close_button_on_tab']: if self.button: self.button.remove(self.icon) self.remove(self.button) del (self.button) del (self.icon) self.button = None self.icon = None return if not self.button: self.button = Gtk.Button() if not self.icon: self.icon = Gio.ThemedIcon.new_with_default_fallbacks( "window-close-symbolic") self.icon = Gtk.Image.new_from_gicon(self.icon, Gtk.IconSize.MENU) self.button.set_focus_on_click(False) 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.xthickness = 0 # style.ythickness = 0 # self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('terminator-tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text(_('Close Tab')) self.pack_start(self.button, False, False, 0) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == Gtk.PositionType.LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.VERTICAL) self.label.set_angle(90) elif position == Gtk.PositionType.RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(Gtk.Orientation.HORIZONTAL) self.label.set_angle(0) def on_close(self, _widget): """The close button has been clicked. Destroy the tab""" self.emit('close-clicked', self) def on_title_click(self, widget, event): """The tab label was clicked. This is probably not the best way to do it, but it works.""" if event.button == 2: self.emit('close-clicked', self)
class GshellTabLabel(gtk.HBox): __gsignals__ = { 'close-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_OBJECT,)), } def __init__(self, title, notebook): gtk.HBox.__init__(self) self.notebook = notebook self.config = Config() self.terminal = None self.label = EditableLabel(title) self.update_angle() self.broadcast_image = None self.prefix_box = gtk.HBox() self.pack_start(self.prefix_box, False, False) self.pack_start(self.label, True, True) self.update_button() self.connect('button-press-event', self.show_popupmenu) self.show_all() def show_popupmenu(self, widget, event): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3 and self.terminal: popupmenu = GshellTabPopupMenu(tablabel=self, notebook=self.notebook) popupmenu.popup(None, None, None, event.button, event.time) return False def on_enable_broadcast(self, widget, *args): if self.terminal: self.terminal.emit('enable-broadcast', self) def enable_log(self, widget, *args): if self.terminal and self.terminal.logger: if self.terminal.logger.logging: self.terminal.logger.stop_logger() else: if self.terminal.host and self.terminal.host['log']: self.terminal.logger.start_logger(self.terminal.host['log']) else: self.terminal.logger.start_logger() def update_button(self): self.button = gtk.Button() self.icon = gtk.Image() self.icon.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) self.button.set_focus_on_click(False) self.button.set_relief(gtk.RELIEF_NONE) style = gtk.RcStyle() style.xthickness = 0 style.ythickness = 0 self.button.modify_style(style) self.button.add(self.icon) self.button.connect('clicked', self.on_close) self.button.set_name('tab-close-button') if hasattr(self.button, 'set_tooltip_text'): self.button.set_tooltip_text('Close Tab') self.pack_start(self.button, False, False) self.show_all() def update_angle(self): """Update the angle of a label""" position = self.notebook.get_tab_pos() if position == gtk.POS_LEFT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(90) elif position == gtk.POS_RIGHT: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_VERTICAL) self.label.set_angle(270) else: if hasattr(self, 'set_orientation'): self.set_orientation(gtk.ORIENTATION_HORIZONTAL) self.label.set_angle(0) def on_close(self, widget, data=None): print 'GshellTabLabel::on_close called' self.emit('close-clicked', self) def mark_close(self): text = self.label._label.get_text() self.label._label.set_markup("<span color='darkgray' strikethrough='true'>%s</span>" % text) def unmark_close(self): text = self.label._label.get_text() self.label.set_text(text)