ocarina/ocarina/body.py

65 lines
1.4 KiB
Python

# Bryan Schumaker (11/24/2010)
import ocarina
gtk = ocarina.gtk
Label = gtk.Label
prefs = ocarina.libsaria.prefs
body = None
get_pref = None
set_pref = None
contents = dict()
class Page(gtk.VBox):
def __init__(self, content):
gtk.VBox.__init__(self)
self.content = content
self.vis_func = content.__dict__.get("visible", None)
self.invis_func = content.__dict__.get("invisible", None)
self.show()
def visible(self):
if self.vis_func:
self.vis_func()
def invisible(self):
if self.invis_func:
self.invis_func()
def init():
global body
global get_pref
global set_pref
get_pref = prefs.get_pref
set_pref = prefs.set_pref
body = gtk.Notebook()
body.set_tab_pos(gtk.POS_LEFT)
body.show()
def init_page(page_name):
page = prefs.init_pref("ocarina.body.page", page_name)
child = contents[page]
num = body.page_num(child)
body.set_current_page(num)
body.connect("switch-page", switch_page)
def add_page(text, content):
label = Label(text)
label.set_angle(90)
page = Page(content)
contents[text] = page
body.append_page(page, label)
body.set_tab_label_packing(page, True, True, gtk.PACK_START)
def switch_page(notebook, page, pagenum):
child = body.get_nth_page(pagenum)
next = None
for name, item in contents.iteritems():
if item == child:
next = name
cur = get_pref("ocarina.body.page")
set_pref("ocarina.body.page", next)
child.invisible()
item.visible()