ocarina/ocarina/tabs.py

67 lines
1.3 KiB
Python

# Bryan Schumaker (8/13/2010)
import ocarina
libsaria = ocarina.libsaria
gtk = ocarina.gtk
Label = gtk.Label
tabs = None
contents = dict()
cur_page = 0
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()
def init():
global tabs
tabs = gtk.Notebook()
tabs.set_tab_pos(gtk.POS_LEFT)
tabs.connect("switch-page", switch_page)
tabs.show()
def append_page(content, text):
global Label
global contents
global tabs
label = Label(text)
label.set_angle(90)
page = TabPage(content)
contents[text] = page
tabs.append_page(page, label)
tabs.set_tab_label_packing(page, True, True, gtk.PACK_START)
def remove_page(text):
global contents
global tabs
page = contents.get(text, None)
if page == None:
return
n = tabs.page_num(page)
if n > 0:
tabs.remove_page( n)
del contents[text]
def switch_page(notebook, page, page_num):
global cur_page
old = notebook.get_nth_page(cur_page)
old.invisible()
new = notebook.get_nth_page(page_num)
new.visible()
cur_page = page_num