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
|
# Lazy loaded modules
|
||||||
window = None
|
window = None
|
||||||
tabs = None
|
tabs = None
|
||||||
|
box = None
|
||||||
|
|
||||||
|
|
||||||
# Function override variables
|
# Function override variables
|
||||||
|
@ -20,7 +21,6 @@ get_window = None
|
||||||
main_window = None
|
main_window = None
|
||||||
main_tabs = None
|
main_tabs = None
|
||||||
|
|
||||||
|
|
||||||
def startup():
|
def startup():
|
||||||
global gtk
|
global gtk
|
||||||
import gtk
|
import gtk
|
||||||
|
@ -47,14 +47,14 @@ def get_tabs_rest():
|
||||||
get_tabs = get_tabs_once
|
get_tabs = get_tabs_once
|
||||||
|
|
||||||
def add_tab(text, content):
|
def add_tab(text, content):
|
||||||
|
global tabs_dict
|
||||||
tabs = get_tabs()
|
tabs = get_tabs()
|
||||||
tabs.append_page(content, text)
|
tabs.append_page(content, text)
|
||||||
|
|
||||||
def remove_tab(content):
|
def remove_tab(text):
|
||||||
|
global tabs
|
||||||
tabs = get_tabs()
|
tabs = get_tabs()
|
||||||
n = tabs.page_num(content)
|
tabs.remove_page(text)
|
||||||
if n > 0:
|
|
||||||
tabs.remove_page(n)
|
|
||||||
|
|
||||||
|
|
||||||
def get_window_once(size):
|
def get_window_once(size):
|
||||||
|
|
|
@ -5,27 +5,52 @@ import ocarina
|
||||||
libsaria = ocarina.libsaria
|
libsaria = ocarina.libsaria
|
||||||
gtk = ocarina.gtk
|
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):
|
class Tabs(gtk.Notebook):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.Notebook.__init__(self)
|
gtk.Notebook.__init__(self)
|
||||||
self.set_tab_pos(gtk.POS_LEFT)
|
self.set_tab_pos(gtk.POS_LEFT)
|
||||||
self.connect("switch-page", self.switch_page)
|
self.connect("switch-page", self.switch_page)
|
||||||
self.cur_page = 0
|
self.cur_page = 0
|
||||||
|
self.contents = dict()
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
def append_page(self, content, text):
|
def append_page(self, content, text):
|
||||||
label = gtk.Label(text)
|
label = gtk.Label(text)
|
||||||
label.set_angle(90)
|
label.set_angle(90)
|
||||||
gtk.Notebook.append_page(self, content, label)
|
page = TabPage(content)
|
||||||
self.set_tab_label_packing(content, True, True, gtk.PACK_START)
|
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):
|
def switch_page(self, notebook, page, page_num):
|
||||||
old = notebook.get_nth_page(self.cur_page)
|
old = notebook.get_nth_page(self.cur_page)
|
||||||
if hasattr(old, "invisible"):
|
old.invisible()
|
||||||
old.invisible()
|
|
||||||
new = notebook.get_nth_page(page_num)
|
new = notebook.get_nth_page(page_num)
|
||||||
if hasattr(new, "visible"):
|
new.visible()
|
||||||
new.visible()
|
|
||||||
self.cur_page = page_num
|
self.cur_page = page_num
|
||||||
|
|
|
@ -9,7 +9,7 @@ webkit = None
|
||||||
children = []
|
children = []
|
||||||
|
|
||||||
|
|
||||||
class WebRadio(gtk.ScrolledWindow):
|
class WebPage(gtk.ScrolledWindow):
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
gtk.ScrolledWindow.__init__(self)
|
gtk.ScrolledWindow.__init__(self)
|
||||||
self.url = url
|
self.url = url
|
||||||
|
@ -33,12 +33,12 @@ def start():
|
||||||
global children
|
global children
|
||||||
import webkit
|
import webkit
|
||||||
|
|
||||||
pandora = WebRadio("http://www.pandora.com")
|
pandora = WebPage("http://www.pandora.com")
|
||||||
children.append(pandora)
|
children.append("Pandora")
|
||||||
ocarina.add_tab("Pandora", pandora)
|
ocarina.add_tab("Pandora", pandora)
|
||||||
|
|
||||||
groove = WebRadio("http://www.grooveshark.com")
|
groove = WebPage("http://www.grooveshark.com")
|
||||||
children.append(groove)
|
children.append("Groove Shark")
|
||||||
ocarina.add_tab("Groove Shark", groove)
|
ocarina.add_tab("Groove Shark", groove)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue