From 3a764343d0df7cbff22fa58ca74d62e4437f25ac Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 20 Aug 2010 22:00:15 -0400 Subject: [PATCH] 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!) --- ocarina/__init__.py | 10 +++++----- ocarina/tabs.py | 39 ++++++++++++++++++++++++++++++++------- plugins/web_radio.py | 10 +++++----- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/ocarina/__init__.py b/ocarina/__init__.py index 30371f98..340a7d65 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -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): diff --git a/ocarina/tabs.py b/ocarina/tabs.py index a489878d..a180d483 100644 --- a/ocarina/tabs.py +++ b/ocarina/tabs.py @@ -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 diff --git a/plugins/web_radio.py b/plugins/web_radio.py index 9c8d42df..7f521051 100644 --- a/plugins/web_radio.py +++ b/plugins/web_radio.py @@ -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)