Port TabLabel across and integrate it.

This commit is contained in:
Chris Jones 2009-11-23 15:17:33 +00:00
parent 9cbc6f1282
commit 1d7adc8283
1 changed files with 99 additions and 1 deletions

View File

@ -6,13 +6,17 @@
import gobject import gobject
import gtk import gtk
from container import Container
from newterminator import Terminator from newterminator import Terminator
from config import Config
from container import Container
from terminal import Terminal from terminal import Terminal
from editablelabel import EditableLabel
from translation import _
from util import err from util import err
class Notebook(Container, gtk.Notebook): class Notebook(Container, gtk.Notebook):
"""Class implementing a gtk.Notebook container""" """Class implementing a gtk.Notebook container"""
window = None
def __init__(self, window): def __init__(self, window):
"""Class initialiser""" """Class initialiser"""
@ -23,6 +27,7 @@ class Notebook(Container, gtk.Notebook):
Container.__init__(self) Container.__init__(self)
gtk.Notebook.__init__(self) gtk.Notebook.__init__(self)
self.terminator = Terminator() self.terminator = Terminator()
self.window = window
gobject.type_register(Notebook) gobject.type_register(Notebook)
self.register_signals(Notebook) self.register_signals(Notebook)
self.configure() self.configure()
@ -31,6 +36,13 @@ class Notebook(Container, gtk.Notebook):
window.remove(child) window.remove(child)
window.add(self) window.add(self)
self.newtab(child) self.newtab(child)
label = TabLabel(self.window.get_title(), self)
self.set_tab_label(child, label)
self.set_tab_label_packing(child, not self.config['scroll_tabbar'],
not self.config['scroll_tabbar'],
gtk.PACK_START)
self.show_all() self.show_all()
def configure(self): def configure(self):
@ -63,6 +75,17 @@ class Notebook(Container, gtk.Notebook):
widget.spawn_child() widget.spawn_child()
self.set_tab_reorderable(widget, True) self.set_tab_reorderable(widget, True)
label = TabLabel(self.window.get_title(), self)
label.show_all()
widget.show_all()
self.set_tab_label(widget, label)
self.set_tab_label_packing(widget, not self.config['scroll_tabbar'],
not self.config['scroll_tabbar'],
gtk.PACK_START)
self.append_page(widget, None) self.append_page(widget, None)
widget.grab_focus() widget.grab_focus()
@ -78,4 +101,79 @@ class Notebook(Container, gtk.Notebook):
"""Unzoom a terminal""" """Unzoom a terminal"""
raise NotImplementedError('unzoom') raise NotImplementedError('unzoom')
class TabLabel(gtk.HBox):
"""Class implementing a label widget for Notebook tabs"""
notebook = None
terminator = None
config = None
label = None
icon = None
button = None
def __init__(self, title, notebook):
"""Class initialiser"""
gtk.HBox.__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)
self.update_button()
self.show_all()
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_relief(gtk.RELIEF_NONE)
self.button.set_focus_on_click(False)
# FIXME: Why on earth are we doing this twice?
self.button.set_relief(gtk.RELIEF_NONE)
self.button.add(self.icon)
self.button.connect('clicked', self.on_close)
self.button.set_name('terminator-tab-close-button')
self.button.connect('style-set', self.on_style_set)
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:
self.label.set_angle(90)
elif position == gtk.POS_RIGHT:
self.label.set_angle(270)
else:
self.label.set_angle(0)
def on_style_set(self, widget, prevstyle):
"""Style changed, recalculate icon size"""
x, y = gtk.icon_size_lookup_for_settings(self.button.get_settings(),
gtk.ICON_SIZE_MENU)
self.button.set_size_request(x + 2, y + 2)
def on_close(self, widget):
"""The close button has been clicked. Destroy the tab"""
pass
# vim: set expandtab ts=4 sw=4: # vim: set expandtab ts=4 sw=4: