57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
# Bryan Schumaker (8/13/2010)
|
|
|
|
import ocarina
|
|
|
|
libsaria = ocarina.libsaria
|
|
gtk = ocarina.gtk
|
|
|
|
|
|
class TabPage(gtk.VBox):
|
|
def __init__(self, content):
|
|
gtk.VBox.__init__(self)
|
|
self.content = content
|
|
self.pack_start(content, True, True, 0)
|
|
self.show()
|
|
|
|
def visible(self):
|
|
if hasattr(self.content, "visible"):
|
|
self.content.visible()
|
|
|
|
def invisible(self):
|
|
if hasattr(self.content, "invisible"):
|
|
self.content.invisible()
|
|
|
|
|
|
class Tabs(gtk.Notebook):
|
|
def __init__(self):
|
|
gtk.Notebook.__init__(self)
|
|
self.set_tab_pos(gtk.POS_LEFT)
|
|
self.connect("switch-page", self.switch_page)
|
|
self.cur_page = 0
|
|
self.contents = dict()
|
|
self.show()
|
|
|
|
def append_page(self, content, text):
|
|
label = gtk.Label(text)
|
|
label.set_angle(90)
|
|
page = TabPage(content)
|
|
self.contents[text] = page
|
|
gtk.Notebook.append_page(self, page, label)
|
|
self.set_tab_label_packing(page, True, True, gtk.PACK_START)
|
|
|
|
def remove_page(self, text):
|
|
page = self.contents.get(text, None)
|
|
if page == None:
|
|
return
|
|
n = self.page_num(page)
|
|
if n > 0:
|
|
gtk.Notebook.remove_page(self, n)
|
|
del self.contents[text]
|
|
|
|
def switch_page(self, notebook, page, page_num):
|
|
old = notebook.get_nth_page(self.cur_page)
|
|
old.invisible()
|
|
new = notebook.get_nth_page(page_num)
|
|
new.visible()
|
|
self.cur_page = page_num
|