Generic TabPage for the main tabs
The main tabs now have a generic TabPage class that contains the content added to the tab. This TabPage will control visibility of the content and make it easier to find a page with specific content (no looping through gtk boxes!)
This commit is contained in:
parent
8594c3b330
commit
3a764343d0
|
@ -9,6 +9,7 @@ gobject.threads_init()
|
|||
# Lazy loaded modules
|
||||
window = None
|
||||
tabs = None
|
||||
box = None
|
||||
|
||||
|
||||
# Function override variables
|
||||
|
@ -20,7 +21,6 @@ get_window = None
|
|||
main_window = None
|
||||
main_tabs = None
|
||||
|
||||
|
||||
def startup():
|
||||
global gtk
|
||||
import gtk
|
||||
|
@ -47,14 +47,14 @@ def get_tabs_rest():
|
|||
get_tabs = get_tabs_once
|
||||
|
||||
def add_tab(text, content):
|
||||
global tabs_dict
|
||||
tabs = get_tabs()
|
||||
tabs.append_page(content, text)
|
||||
|
||||
def remove_tab(content):
|
||||
def remove_tab(text):
|
||||
global tabs
|
||||
tabs = get_tabs()
|
||||
n = tabs.page_num(content)
|
||||
if n > 0:
|
||||
tabs.remove_page(n)
|
||||
tabs.remove_page(text)
|
||||
|
||||
|
||||
def get_window_once(size):
|
||||
|
|
|
@ -5,27 +5,52 @@ import ocarina
|
|||
libsaria = ocarina.libsaria
|
||||
gtk = ocarina.gtk
|
||||
|
||||
|
||||
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):
|
||||
if hasattr(self.content, "visible"):
|
||||
self.content.visible()
|
||||
|
||||
def invisible(self):
|
||||
if hasattr(self.content, "invisible"):
|
||||
self.content.invisible()
|
||||
|
||||
|
||||
class Tabs(gtk.Notebook):
|
||||
def __init__(self):
|
||||
gtk.Notebook.__init__(self)
|
||||
self.set_tab_pos(gtk.POS_LEFT)
|
||||
self.connect("switch-page", self.switch_page)
|
||||
self.cur_page = 0
|
||||
self.contents = dict()
|
||||
self.show()
|
||||
|
||||
|
||||
def append_page(self, content, text):
|
||||
label = gtk.Label(text)
|
||||
label.set_angle(90)
|
||||
gtk.Notebook.append_page(self, content, label)
|
||||
self.set_tab_label_packing(content, True, True, gtk.PACK_START)
|
||||
page = TabPage(content)
|
||||
self.contents[text] = page
|
||||
gtk.Notebook.append_page(self, page, label)
|
||||
self.set_tab_label_packing(page, True, True, gtk.PACK_START)
|
||||
|
||||
def remove_page(self, text):
|
||||
page = self.contents.get(text, None)
|
||||
if page == None:
|
||||
return
|
||||
n = self.page_num(page)
|
||||
if n > 0:
|
||||
gtk.Notebook.remove_page(self, n)
|
||||
del self.contents[text]
|
||||
|
||||
def switch_page(self, notebook, page, page_num):
|
||||
old = notebook.get_nth_page(self.cur_page)
|
||||
if hasattr(old, "invisible"):
|
||||
old.invisible()
|
||||
old.invisible()
|
||||
new = notebook.get_nth_page(page_num)
|
||||
if hasattr(new, "visible"):
|
||||
new.visible()
|
||||
new.visible()
|
||||
self.cur_page = page_num
|
||||
|
|
|
@ -9,7 +9,7 @@ webkit = None
|
|||
children = []
|
||||
|
||||
|
||||
class WebRadio(gtk.ScrolledWindow):
|
||||
class WebPage(gtk.ScrolledWindow):
|
||||
def __init__(self, url):
|
||||
gtk.ScrolledWindow.__init__(self)
|
||||
self.url = url
|
||||
|
@ -33,12 +33,12 @@ def start():
|
|||
global children
|
||||
import webkit
|
||||
|
||||
pandora = WebRadio("http://www.pandora.com")
|
||||
children.append(pandora)
|
||||
pandora = WebPage("http://www.pandora.com")
|
||||
children.append("Pandora")
|
||||
ocarina.add_tab("Pandora", pandora)
|
||||
|
||||
groove = WebRadio("http://www.grooveshark.com")
|
||||
children.append(groove)
|
||||
groove = WebPage("http://www.grooveshark.com")
|
||||
children.append("Groove Shark")
|
||||
ocarina.add_tab("Groove Shark", groove)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue