From a87653f056c2f8ad6f12b2a8c459cb40643d44e7 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 15 Aug 2010 00:25:24 -0400 Subject: [PATCH] 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 --- ocarina.py | 6 ++++++ ocarina/__init__.py | 39 +++++++++++++++++++++++---------------- ocarina/tabs.py | 8 ++++++++ ocarina/window.py | 22 ++++++++++++++++------ 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/ocarina.py b/ocarina.py index 2d095bf3..a5e27fb8 100755 --- a/ocarina.py +++ b/ocarina.py @@ -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() diff --git a/ocarina/__init__.py b/ocarina/__init__.py index e0915981..d6c9d396 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -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 diff --git a/ocarina/tabs.py b/ocarina/tabs.py index ee7f1d82..143e72c3 100644 --- a/ocarina/tabs.py +++ b/ocarina/tabs.py @@ -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) diff --git a/ocarina/window.py b/ocarina/window.py index 0c75d11a..8d1a83c9 100644 --- a/ocarina/window.py +++ b/ocarina/window.py @@ -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)