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
main_window = None
main_tabs = None
#main_tabs = None
def startup():
global gtk
@ -35,25 +35,21 @@ def exit(widget, event):
def get_tabs_once():
global tabs
global get_tabs
global main_tabs
import tabs
main_tabs = tabs.Tabs()
main_tabs
tabs.init()
get_tabs = get_tabs_rest
return main_tabs
return tabs.tabs
def get_tabs_rest():
global main_tabs
return main_tabs
global tabs
return tabs.tabs
get_tabs = get_tabs_once
def add_tab(text, content):
global tabs_dict
tabs = get_tabs()
global tabs
tabs.append_page(content, text)
def remove_tab(text):
global tabs
tabs = get_tabs()
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
libsaria = ocarina.libsaria
gtk = ocarina.gtk
gtk = ocarina.gtk
Label = gtk.Label
tabs = None
contents = dict()
cur_page = 0
class TabPage(gtk.VBox):
@ -22,35 +28,39 @@ class TabPage(gtk.VBox):
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 init():
global tabs
tabs = gtk.Notebook()
tabs.set_tab_pos(gtk.POS_LEFT)
tabs.connect("switch-page", switch_page)
tabs.show()
def append_page(self, content, text):
label = gtk.Label(text)
label.set_angle(90)
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 append_page(content, text):
global Label
global contents
global tabs
label = Label(text)
label.set_angle(90)
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):
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 remove_page(text):
global contents
global tabs
page = contents.get(text, None)
if page == None:
return
n = tabs.page_num(page)
if n > 0:
tabs.remove_page( n)
del contents[text]
def switch_page(self, notebook, page, page_num):
old = notebook.get_nth_page(self.cur_page)
old.invisible()
new = notebook.get_nth_page(page_num)
new.visible()
self.cur_page = page_num
def switch_page(notebook, page, page_num):
global cur_page
old = notebook.get_nth_page(cur_page)
old.invisible()
new = notebook.get_nth_page(page_num)
new.visible()
cur_page = page_num

View File

@ -33,6 +33,10 @@ def start():
global children
import webkit
#google = WebPage("http://www.google.com")
#children.append("Google")
#ocarina.add_tab("Google", google)
pandora = WebPage("http://www.pandora.com")
children.append("Pandora")
ocarina.add_tab("Pandora", pandora)