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
|
print "Startup took:", after-before
|
||||||
|
|
||||||
ocarina.startup()
|
ocarina.startup()
|
||||||
|
body.init_page("Library")
|
||||||
|
ocarina.main()
|
||||||
|
|
|
@ -5,7 +5,8 @@ import gobject
|
||||||
import pango
|
import pango
|
||||||
import libsaria
|
import libsaria
|
||||||
|
|
||||||
gdk = gtk.gdk
|
gdk = gtk.gdk
|
||||||
|
main = gtk.main
|
||||||
|
|
||||||
__major__ = 4
|
__major__ = 4
|
||||||
__minor__ = 2
|
__minor__ = 2
|
||||||
|
@ -26,12 +27,10 @@ get_tabs = None
|
||||||
|
|
||||||
|
|
||||||
def startup():
|
def startup():
|
||||||
global gtk
|
|
||||||
import gtk
|
|
||||||
libsaria.startup()
|
libsaria.startup()
|
||||||
gdk.threads_init()
|
gdk.threads_init()
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
gtk.main()
|
#gtk.main()
|
||||||
|
|
||||||
def exit(widget, event):
|
def exit(widget, event):
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
|
@ -3,39 +3,62 @@
|
||||||
import ocarina
|
import ocarina
|
||||||
gtk = ocarina.gtk
|
gtk = ocarina.gtk
|
||||||
Label = gtk.Label
|
Label = gtk.Label
|
||||||
|
prefs = ocarina.libsaria.prefs
|
||||||
|
|
||||||
body = None
|
body = None
|
||||||
|
get_pref = None
|
||||||
|
set_pref = None
|
||||||
contents = dict()
|
contents = dict()
|
||||||
|
|
||||||
class TabPage(gtk.VBox):
|
class Page(gtk.VBox):
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
gtk.VBox.__init__(self)
|
gtk.VBox.__init__(self)
|
||||||
self.content = content
|
self.content = content
|
||||||
#self.pack_start(content)
|
self.vis_func = content.__dict__.get("visible", None)
|
||||||
|
self.invis_func = content.__dict__.get("invisible", None)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def visible(self):
|
def visible(self):
|
||||||
if hasattr(self.content, "visible"):
|
if self.vis_func:
|
||||||
self.content.visible()
|
self.vis_func()
|
||||||
|
|
||||||
def invisible(self):
|
def invisible(self):
|
||||||
if hasattr(self.content, "invisible"):
|
if self.invis_func:
|
||||||
self.content.invisible()
|
self.invis_func()
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global body
|
global body
|
||||||
|
global get_pref
|
||||||
|
global set_pref
|
||||||
|
|
||||||
|
get_pref = prefs.get_pref
|
||||||
|
set_pref = prefs.set_pref
|
||||||
body = gtk.Notebook()
|
body = gtk.Notebook()
|
||||||
body.set_tab_pos(gtk.POS_LEFT)
|
body.set_tab_pos(gtk.POS_LEFT)
|
||||||
body.connect("switch-page", switch_page)
|
|
||||||
body.show()
|
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):
|
def add_page(text, content):
|
||||||
label = Label(text)
|
label = Label(text)
|
||||||
label.set_angle(90)
|
label.set_angle(90)
|
||||||
page = TabPage(content)
|
page = Page(content)
|
||||||
contents[text] = page
|
contents[text] = page
|
||||||
body.append_page(page, label)
|
body.append_page(page, label)
|
||||||
body.set_tab_label_packing(page, True, True, gtk.PACK_START)
|
body.set_tab_label_packing(page, True, True, gtk.PACK_START)
|
||||||
|
|
||||||
def switch_page(notebook, page, pagenum):
|
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