ocarina/ocarina/tabs.py

79 lines
1.5 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
bottom = None
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):
global bottom
if bottom is not None:
self.pack_end(bottom, False, False)
if hasattr(self.content, "visible"):
self.content.visible()
def invisible(self):
global bottom
if bottom is not None and bottom.get_parent() is not None:
self.remove(bottom)
if hasattr(self.content, "invisible"):
self.content.invisible()
def init():
import info
global bottom
info.init()
bottom = info.get_info()
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)
new = notebook.get_nth_page(page_num)
old.invisible()
new.visible()
cur_page = page_num