Added header

The header is shown at the top of each notebook page.
This commit is contained in:
Bryan Schumaker 2010-11-25 13:29:45 -05:00
parent dc43c27ead
commit 5cb70a8b4d
3 changed files with 68 additions and 16 deletions

View File

@ -4,35 +4,47 @@ import ocarina
gtk = ocarina.gtk
Label = gtk.Label
prefs = ocarina.libsaria.prefs
get_pref = prefs.get_pref
set_pref = prefs.set_pref
body = None
get_pref = None
set_pref = None
contents = dict()
body = None
page_header = None
page_footer = None
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.attrs = content.__dict__
self.vis_func = self.attrs.get("visible", None)
self.invis_func = self.attrs.get("invisible", None)
self.show()
def filter(self, text):
self.content.filter(text)
def visible(self):
self.pack_start(page_header, False, False)
self.pack_start(self.content, True, True)
if self.vis_func:
self.vis_func()
def invisible(self):
self.remove(page_header)
self.remove(self.content)
if self.invis_func:
self.invis_func()
def init():
global body
global get_pref
global set_pref
global page_header
global page_footer
import header
page_header = header.header
get_pref = prefs.get_pref
set_pref = prefs.set_pref
body = gtk.Notebook()
body.set_tab_pos(gtk.POS_LEFT)
body.show()
@ -42,6 +54,7 @@ def init_page(page_name):
child = contents[page]
num = body.page_num(child)
body.set_current_page(num)
child.visible()
body.connect("switch-page", switch_page)
def add_page(text, content):
@ -53,12 +66,18 @@ def add_page(text, content):
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
cur_num = body.get_current_page()
child = body.get_nth_page(cur_num)
next_pg = body.get_nth_page(pagenum)
next = None
for name, item in contents.iteritems():
if item == child:
if item == next_pg:
next = name
cur = get_pref("ocarina.body.page")
set_pref("ocarina.body.page", next)
child.invisible()
item.visible()
next_pg.visible()
def cur_page_filter(text):
cur_num = body.get_current_page()
page = body.get_nth_page(cur_num)
page.filter(text)

View File

@ -4,7 +4,7 @@ import ocarina
timeout = ocarina.gobject.timeout_add
gtk = ocarina.gtk
tabs = ocarina.tabs
body = ocarina.body
class FilterEntry(gtk.Entry):
def __init__(self):
@ -20,4 +20,4 @@ class FilterEntry(gtk.Entry):
def filter(self, text):
self.count -= 1
if self.count == 0:
tabs.filter(text)
body.cur_page_filter(text)

33
ocarina/header.py Normal file
View File

@ -0,0 +1,33 @@
# Bryan Schumaker (11/25/2010)
import ocarina
from components import button
from components import entry
gtk = ocarina.gtk
header = None
bar = None
def init():
global header
global bar
header = gtk.VBox()
bar = gtk.HBox()
sep = gtk.HSeparator()
header.pack_start(bar)
header.pack_start(sep)
header.show_all()
add(entry.FilterEntry(), True, True)
add(button.OpenButton())
add(button.ExportButton())
add(button.ClearButton())
add(button.RandomButton())
add(button.VolumeButton())
def add(widget, expand = False, fill = False):
bar.pack_start(widget, expand, fill)
init()