ocarina.body improvements
The current tab is saved between sessions, and the visible / invisible functions are called for each page.
This commit is contained in:
parent
ea4b4cad37
commit
dc43c27ead
|
@ -32,3 +32,5 @@ after = now()
|
|||
print "Startup took:", after-before
|
||||
|
||||
ocarina.startup()
|
||||
body.init_page("Library")
|
||||
ocarina.main()
|
||||
|
|
|
@ -5,7 +5,8 @@ import gobject
|
|||
import pango
|
||||
import libsaria
|
||||
|
||||
gdk = gtk.gdk
|
||||
gdk = gtk.gdk
|
||||
main = gtk.main
|
||||
|
||||
__major__ = 4
|
||||
__minor__ = 2
|
||||
|
@ -26,12 +27,10 @@ get_tabs = None
|
|||
|
||||
|
||||
def startup():
|
||||
global gtk
|
||||
import gtk
|
||||
libsaria.startup()
|
||||
gdk.threads_init()
|
||||
gobject.threads_init()
|
||||
gtk.main()
|
||||
#gtk.main()
|
||||
|
||||
def exit(widget, event):
|
||||
gtk.main_quit()
|
||||
|
|
|
@ -3,39 +3,62 @@
|
|||
import ocarina
|
||||
gtk = ocarina.gtk
|
||||
Label = gtk.Label
|
||||
prefs = ocarina.libsaria.prefs
|
||||
|
||||
body = None
|
||||
get_pref = None
|
||||
set_pref = None
|
||||
contents = dict()
|
||||
|
||||
class TabPage(gtk.VBox):
|
||||
class Page(gtk.VBox):
|
||||
def __init__(self, content):
|
||||
gtk.VBox.__init__(self)
|
||||
self.content = content
|
||||
#self.pack_start(content)
|
||||
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 hasattr(self.content, "visible"):
|
||||
self.content.visible()
|
||||
if self.vis_func:
|
||||
self.vis_func()
|
||||
|
||||
def invisible(self):
|
||||
if hasattr(self.content, "invisible"):
|
||||
self.content.invisible()
|
||||
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.connect("switch-page", switch_page)
|
||||
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 = TabPage(content)
|
||||
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):
|
||||
pass
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue