Declassify Tabs()

We only have one instance of the main tabs, so there is no reason for it
to be a class.  I have changed this into a set of functions that do
everything the old class did.
This commit is contained in:
Bryan Schumaker 2010-08-22 09:07:09 -04:00
parent 3a764343d0
commit 1139ba09c3
4 changed files with 66 additions and 40 deletions

View File

@ -19,7 +19,7 @@ get_window = None
# Global variables for some objects # Global variables for some objects
main_window = None main_window = None
main_tabs = None #main_tabs = None
def startup(): def startup():
global gtk global gtk
@ -35,25 +35,21 @@ def exit(widget, event):
def get_tabs_once(): def get_tabs_once():
global tabs global tabs
global get_tabs global get_tabs
global main_tabs
import tabs import tabs
main_tabs = tabs.Tabs() tabs.init()
main_tabs
get_tabs = get_tabs_rest get_tabs = get_tabs_rest
return main_tabs return tabs.tabs
def get_tabs_rest(): def get_tabs_rest():
global main_tabs global tabs
return main_tabs return tabs.tabs
get_tabs = get_tabs_once get_tabs = get_tabs_once
def add_tab(text, content): def add_tab(text, content):
global tabs_dict global tabs
tabs = get_tabs()
tabs.append_page(content, text) tabs.append_page(content, text)
def remove_tab(text): def remove_tab(text):
global tabs global tabs
tabs = get_tabs()
tabs.remove_page(text) tabs.remove_page(text)

16
ocarina/box.py Normal file
View File

@ -0,0 +1,16 @@
# Bryan Schumaker (8/20/2010)
import ocarina
gtk = ocarina.gtk
class VBox(gtk.VBox):
def __init__(self):
gtk.VBox.__init__(self)
self.show()
class HBox(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)
self.show()

View File

@ -3,7 +3,13 @@
import ocarina import ocarina
libsaria = ocarina.libsaria libsaria = ocarina.libsaria
gtk = ocarina.gtk gtk = ocarina.gtk
Label = gtk.Label
tabs = None
contents = dict()
cur_page = 0
class TabPage(gtk.VBox): class TabPage(gtk.VBox):
@ -22,35 +28,39 @@ class TabPage(gtk.VBox):
self.content.invisible() self.content.invisible()
class Tabs(gtk.Notebook): def init():
def __init__(self): global tabs
gtk.Notebook.__init__(self) tabs = gtk.Notebook()
self.set_tab_pos(gtk.POS_LEFT) tabs.set_tab_pos(gtk.POS_LEFT)
self.connect("switch-page", self.switch_page) tabs.connect("switch-page", switch_page)
self.cur_page = 0 tabs.show()
self.contents = dict()
self.show()
def append_page(self, content, text): def append_page(content, text):
label = gtk.Label(text) global Label
label.set_angle(90) global contents
page = TabPage(content) global tabs
self.contents[text] = page label = Label(text)
gtk.Notebook.append_page(self, page, label) label.set_angle(90)
self.set_tab_label_packing(page, True, True, gtk.PACK_START) page = TabPage(content)
contents[text] = page
tabs.append_page(page, label)
tabs.set_tab_label_packing(page, True, True, gtk.PACK_START)
def remove_page(self, text): def remove_page(text):
page = self.contents.get(text, None) global contents
if page == None: global tabs
return page = contents.get(text, None)
n = self.page_num(page) if page == None:
if n > 0: return
gtk.Notebook.remove_page(self, n) n = tabs.page_num(page)
del self.contents[text] if n > 0:
tabs.remove_page( n)
del contents[text]
def switch_page(self, notebook, page, page_num): def switch_page(notebook, page, page_num):
old = notebook.get_nth_page(self.cur_page) global cur_page
old.invisible() old = notebook.get_nth_page(cur_page)
new = notebook.get_nth_page(page_num) old.invisible()
new.visible() new = notebook.get_nth_page(page_num)
self.cur_page = page_num new.visible()
cur_page = page_num

View File

@ -33,6 +33,10 @@ def start():
global children global children
import webkit import webkit
#google = WebPage("http://www.google.com")
#children.append("Google")
#ocarina.add_tab("Google", google)
pandora = WebPage("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)