From 7ce3da1a2ab1567a6e3511b33dfb3006e3e49701 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 13 Aug 2010 23:58:19 -0400 Subject: [PATCH] Ocarina GUI I have begun creating the Ocarina 4.1 gui. So far, I can create and resize a window. After a resize, the new size is saved and used again when Ocarina is next started. I am also investigating drag and drop for use with plugin loading. --- libsaria/__init__.py | 8 +++++- libsaria/collection/tree.py | 26 +++++++++++------ libsaria/data.py | 4 +-- ocarina.py | 14 ++++++++++ ocarina/__init__.py | 56 +++++++++++++++++++++++++++++++++++++ ocarina/tabs.py | 11 ++++++++ ocarina/window.py | 26 +++++++++++++++++ saria-test.py | 3 ++ 8 files changed, 136 insertions(+), 12 deletions(-) create mode 100755 ocarina.py create mode 100644 ocarina/tabs.py create mode 100644 ocarina/window.py diff --git a/libsaria/__init__.py b/libsaria/__init__.py index 61c01a55..66d2d4a2 100644 --- a/libsaria/__init__.py +++ b/libsaria/__init__.py @@ -16,5 +16,11 @@ def startup(): global vars global prefs vars = Map() - prefs = Map() + prefs = Map("preferences") event.start("POSTINIT") + + +def init_pref(key, value): + global prefs + if prefs.get(key) == None: + prefs[key] = value diff --git a/libsaria/collection/tree.py b/libsaria/collection/tree.py index 9bbaee13..9372db97 100644 --- a/libsaria/collection/tree.py +++ b/libsaria/collection/tree.py @@ -2,19 +2,27 @@ get = dict.get -class TagNode: +class TagNode(dict): def __init__(self): - pass + dict.__init__(self) def insert(self, tag_list, tags, audio, filepath): - self.artist = tags.artist - self.album = tags.album - self.title = tags.title - self.year = tags.year + self["artist"] = tags.artist + self["album"] = tags.album + self["title"] = tags.title + self["year"] = tags.year - self.filepath = filepath - self.playcount = 0 - self.length = audio.length + self["filepath"] = filepath + self["playcount"] = 0 + self["length"] = audio.length + #self.artist = tags.artist + #self.album = tags.album + #self.title = tags.title + #self.year = tags.year + + #self.filepath = filepath + #self.playcount = 0 + #self.length = audio.length def sort(self, level): pass diff --git a/libsaria/data.py b/libsaria/data.py index 0d11e19b..e7afb8aa 100644 --- a/libsaria/data.py +++ b/libsaria/data.py @@ -6,7 +6,7 @@ import cPickle as pickle PROTO = pickle.HIGHEST_PROTOCOL def save(item, file, ext="pickle"): - file = "%s%s" % (path.join(path.sariadir(),file), ext) + file = "%s.%s" % (path.join(path.sariadir(),file), ext) savefile(item, file) @@ -18,7 +18,7 @@ def savefile(item, file): def load(file, ext="pickle"): - file = "%s%s" % (path.join(path.sariadir(),file),ext) + file = "%s.%s" % (path.join(path.sariadir(),file),ext) return loadfile(file) diff --git a/ocarina.py b/ocarina.py new file mode 100755 index 00000000..2d095bf3 --- /dev/null +++ b/ocarina.py @@ -0,0 +1,14 @@ +#!/usr/bin/python +# Bryan Schumaker (8/13/2010) + +import libsaria +import ocarina + +libsaria.startup() +libsaria.init_pref("window_size", (800,600)) + +prefs = libsaria.prefs + +win = ocarina.get_window(prefs["window_size"]) + +ocarina.startup() diff --git a/ocarina/__init__.py b/ocarina/__init__.py index e69de29b..e0915981 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -0,0 +1,56 @@ +# Bryan Schumaker (8/13/2010) + +import gtk +import libsaria + +# Lazy loaded modules +window = None +tabs = None + + +# Global variables for some objects +main_window = None +main_tabs = None + + +def startup(): + global gtk + 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() + return main_tabs +get_main_tabs = get_main_tabs_init + + +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()) + if size != None: + main_window.resize(size[0], size[1]) + return main_window +get_window = get_window_init diff --git a/ocarina/tabs.py b/ocarina/tabs.py new file mode 100644 index 00000000..ee7f1d82 --- /dev/null +++ b/ocarina/tabs.py @@ -0,0 +1,11 @@ +# Bryan Schumaker (8/13/2010) + +import ocarina + +libsaria = ocarina.libsaria +gtk = ocarina.gtk + +class Tabs(gtk.Notebook): + def __init__(self): + gtk.Notebook.__init__(self) + self.show() diff --git a/ocarina/window.py b/ocarina/window.py new file mode 100644 index 00000000..0c75d11a --- /dev/null +++ b/ocarina/window.py @@ -0,0 +1,26 @@ +# Bryan Schumaker (8/13/2010) + +import ocarina +libsaria = ocarina.libsaria +gtk = ocarina.gtk + + +class Window(gtk.Window): + def __init__(self): + 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) + + self.drag_dest_set(0, [], 0) + self.show() + + + def resized(self, widget, geom): + libsaria.prefs["window_size"] = (geom.width, geom.height) + + + def dnd(self, widget, *args): + print widget, args diff --git a/saria-test.py b/saria-test.py index d9030c83..cf4cfc40 100755 --- a/saria-test.py +++ b/saria-test.py @@ -15,7 +15,10 @@ after = now() print "libsaria loaded (", after-before, ")" if len(sys.argv) == 1: + before = now() libsaria.startup() + after = now() + print "startup took", after-before print print "Available tests:" for file in os.listdir("tests"):