Main Tabs Implemented

I can now add pages to the main tab widget that is attached to the
window.  My next step is to work on libsaria plugins for Pandora and
Last.fm
This commit is contained in:
Bryan Schumaker 2010-08-15 00:25:24 -04:00
parent 7ce3da1a2a
commit a87653f056
4 changed files with 53 additions and 22 deletions

View File

@ -9,6 +9,12 @@ libsaria.init_pref("window_size", (800,600))
prefs = libsaria.prefs
import gtk
label = gtk.Label("Ocarina 4.1")
label.show()
win = ocarina.get_window(prefs["window_size"])
#win.move(0,0)
ocarina.add_tab("Test", label)
ocarina.startup()

View File

@ -8,6 +8,11 @@ window = None
tabs = None
# Function override variables
get_main_tabs = None
get_window = None
# Global variables for some objects
main_window = None
main_tabs = None
@ -18,38 +23,40 @@ def startup():
import gtk
gtk.main()
def exit(widget, event):
gtk.main_quit()
def get_main_tabs_init():
global tabs
import tabs
global get_main_tabs
get_main_tabs = get_main_tabs_always
return get_main_tabs_always()
def get_main_tabs_always():
global tabs
global main_tabs
if main_tabs == None:
main_tabs = tabs.Tabs()
import tabs
main_tabs = tabs.Tabs()
main_tabs
get_main_tabs = get_main_tabs_always
return main_tabs
def get_main_tabs_always():
global main_tabs
return main_tabs
get_main_tabs = get_main_tabs_init
def add_tab(text, content):
tabs = get_main_tabs()
tabs.append_page(content, text)
def get_window_init(size):
global window
import window
global get_window
get_window = get_window_always
return get_window_always(size)
def get_window_always(size=None):
global window
global main_window
if main_window == None:
main_window = window.Window()
main_window.add(get_main_tabs())
import window
main_window = window.Window(size)
main_window.add(get_main_tabs())
get_window = get_window_always
return main_window
def get_window_always(size=None):
global main_window
if size != None:
main_window.resize(size[0], size[1])
return main_window

View File

@ -8,4 +8,12 @@ gtk = ocarina.gtk
class Tabs(gtk.Notebook):
def __init__(self):
gtk.Notebook.__init__(self)
self.set_tab_pos(gtk.POS_LEFT)
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)

View File

@ -4,17 +4,22 @@ import ocarina
libsaria = ocarina.libsaria
gtk = ocarina.gtk
TARGET_TYPE_URI_LIST = 80
class Window(gtk.Window):
def __init__(self):
def __init__(self, size):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
connect = self.connect
connect("delete-event", ocarina.exit)
connect("size-allocate", self.resized)
connect("drag_motion", self.dnd)
connect("drag_drop", self.dnd)
connect("drag-data-received", self.dnd_receive)
self.drag_dest_set(0, [], 0)
mask = gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP
dnd_list = [("text/uri-list", 0, TARGET_TYPE_URI_LIST)]
self.drag_dest_set(mask, dnd_list, gtk.gdk.ACTION_COPY)
self.resize(size[0], size[1])
self.show()
@ -22,5 +27,10 @@ class Window(gtk.Window):
libsaria.prefs["window_size"] = (geom.width, geom.height)
def dnd(self, widget, *args):
print widget, args
def dnd_receive(self, widget, context, x, y, selection, type, time):
if type == TARGET_TYPE_URI_LIST:
uri = selection.data.strip('\r\n\x00')
import os
for file in uri.split():
file = file[7:]
print file, os.path.isfile(file)