From 03f33af437efd1295d6250eb5585ac0f91917ef2 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 19:06:05 -0400 Subject: [PATCH 1/7] Common menu items Common menu items are drawn for all right click menus, so the same function won't need to be added multiple times to different menus. --- ocarina/menu.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/ocarina/menu.py b/ocarina/menu.py index bd8ed9a3..c74f807a 100644 --- a/ocarina/menu.py +++ b/ocarina/menu.py @@ -6,30 +6,48 @@ gtk = ocarina.gtk Menu = gtk.Menu MenuItem = gtk.MenuItem -lib_items = [] -plist_items = [] +common_items = [] +lib_items = [] +plist_items = [] def add_menu_item(items, text, func): items.append( (text, func) ) items.sort() +def add_common_menu_item(text, func): + add_menu_item(common_items, text, func) + def add_lib_menu_item(text, func): add_menu_item(lib_items, text, func) def add_plist_menu_item(text, func): add_menu_item(plist_items, text, func) +def make_menu_item(text, func): + item = MenuItem(text) + item.connect("activate", func) + item.show() + return item def make_menu(items, button, time): - if len(items) == 0: - return + show = False + if len(items) > 0: + show = True menu = Menu() + + if len(common_items) > 0: + show = True + for (text, func) in common_items: + menu.append(make_menu_item(text, func)) + if len(items) > 0: + div = MenuItem() + div.show() + menu.append(div) + for (text, func) in items: - item = MenuItem(text) - item.connect("activate", func) - item.show() - menu.append(item) - menu.popup(None, None, None, button, time) + menu.append(make_menu_item(text, func)) + if show == True: + menu.popup(None, None, None, button, time) def make_lib_menu(button, time): make_menu(lib_items, button, time) From bf014d92c62586e99f128b2b8a430080e8c47e70 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 19:07:24 -0400 Subject: [PATCH 2/7] pause_after.py use common menu The plugin for pausing playback after the current song should use the new common menu, instead of individual menus. --- plugins/pause_after.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/pause_after.py b/plugins/pause_after.py index 82785c6d..82028442 100644 --- a/plugins/pause_after.py +++ b/plugins/pause_after.py @@ -17,8 +17,7 @@ def start(): text = "Pause after current song" libsaria.init_var("PAUSEAFTER", False) - menu.add_lib_menu_item(text, set_pause) - menu.add_plist_menu_item(text, set_pause) + menu.add_common_menu_item(text, set_pause) libsaria.event.invite("POSTNEXT", check_pause) def stop(): From 2443eb40dd0672173bffb80f58043f816bc835bc Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 19:09:26 -0400 Subject: [PATCH 3/7] Bump the minor version number This reflects that I am working on Ocarina 4.2 / Libsaria 1.2 now. --- libsaria/__init__.py | 4 ++-- ocarina/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsaria/__init__.py b/libsaria/__init__.py index ec6b26fc..85f63c05 100644 --- a/libsaria/__init__.py +++ b/libsaria/__init__.py @@ -4,10 +4,10 @@ __all__ = [ "collection", "music", "data", "event", "map", "path", "plugin"] __major__ = 1 -__minor__ = 1 +__minor__ = 2 __dev__ = True __vers__ = "Libsaria %s.%s" % (__major__, __minor__) -if __dev__ == False: +if __dev__ == True: __vers__ += "-dev" import event diff --git a/ocarina/__init__.py b/ocarina/__init__.py index ffb6314f..efcc5c6f 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -8,10 +8,10 @@ import libsaria gdk = gtk.gdk __major__ = 4 -__minor__ = 1 +__minor__ = 2 __dev__ = True __vers__ = "Ocarina %s.%s" % (__major__, __minor__) -if __dev__ == False: +if __dev__ == True: __vers__ += "-dev" gdk.threads_init() From 08ce4b6af459b745cecbbac050cb66c9c1b562e7 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 19:14:43 -0400 Subject: [PATCH 4/7] Plugins bump version Plugins should now allow Ocarina 4.2 --- plugins/pause_after.py | 2 +- plugins/web_radio.py | 2 +- plugins/wm_tweaks.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pause_after.py b/plugins/pause_after.py index 82028442..1185597f 100644 --- a/plugins/pause_after.py +++ b/plugins/pause_after.py @@ -26,6 +26,6 @@ def stop(): def check_version(): if ocarina.__major__ != 4: return False - if ocarina.__minor__ != 1: + if ocarina.__minor__ != 2: return False return True diff --git a/plugins/web_radio.py b/plugins/web_radio.py index 78dc6ab5..2b628ec7 100644 --- a/plugins/web_radio.py +++ b/plugins/web_radio.py @@ -48,6 +48,6 @@ def stop(): def check_version(): if ocarina.__major__ != 4: return False - if ocarina.__minor__ != 1: + if ocarina.__minor__ >= 1: return False return True diff --git a/plugins/wm_tweaks.py b/plugins/wm_tweaks.py index 92778677..05ec78d1 100644 --- a/plugins/wm_tweaks.py +++ b/plugins/wm_tweaks.py @@ -33,6 +33,6 @@ def stop(): def check_version(): if ocarina.__major__ != 4: return False - if ocarina.__minor__ != 1: + if ocarina.__minor__ >= 1: return False return True From f1292471f01c257c1c8b41f7a1d394e2357d7775 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 19:18:21 -0400 Subject: [PATCH 5/7] fix check_version() in some plugins The conditions for returning True and returning False were off --- plugins/web_radio.py | 4 ++-- plugins/wm_tweaks.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/web_radio.py b/plugins/web_radio.py index 2b628ec7..b12d00a1 100644 --- a/plugins/web_radio.py +++ b/plugins/web_radio.py @@ -49,5 +49,5 @@ def check_version(): if ocarina.__major__ != 4: return False if ocarina.__minor__ >= 1: - return False - return True + return True + return False diff --git a/plugins/wm_tweaks.py b/plugins/wm_tweaks.py index 05ec78d1..933464e3 100644 --- a/plugins/wm_tweaks.py +++ b/plugins/wm_tweaks.py @@ -34,5 +34,5 @@ def check_version(): if ocarina.__major__ != 4: return False if ocarina.__minor__ >= 1: - return False - return True + return True + return False From 58ad3c7a9dc099b1666e980b0f238417b1cbd790 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 5 Nov 2010 21:52:10 -0400 Subject: [PATCH 6/7] Library class -> library module I think that the library will be cleaner if I turn it into a module instead of keeping it a class. --- libsaria/collection/__init__.py | 58 ++++++-------------- libsaria/collection/lens.py | 2 +- libsaria/collection/library.py | 97 +++++++++++++++++++++++++++++++++ libsaria/data.py | 2 +- libsaria/lastfm.py | 11 ++-- ocarina/collection.py | 17 +++--- ocarina/info.py | 9 +-- ocarina/label.py | 23 ++++---- plugins/wm_tweaks.py | 14 ++--- 9 files changed, 154 insertions(+), 79 deletions(-) create mode 100644 libsaria/collection/library.py diff --git a/libsaria/collection/__init__.py b/libsaria/collection/__init__.py index ad31f2d7..82801425 100644 --- a/libsaria/collection/__init__.py +++ b/libsaria/collection/__init__.py @@ -14,9 +14,16 @@ PLAYLIST = 1 QUEUE = 2 import lens -library = lens.Library() +import library +#library = lens.Library() playlist = lens.Playlist() +file_to_id = library.file_to_id +get_attr = library.get_attr +reset = library.reset +inc_score = library.inc_score +inc_count = library.inc_count + def init(): libsaria.init_pref("random", False) libsaria.event.invite("POSTINIT", init) @@ -33,44 +40,13 @@ def new_source(path, bg=True): return 0 return call("NEWSOURCE", library.scan, path) -def walk_library(): - global library - for track in library.walk_tags(): - yield track - -def lib_reset(): - global library - library.reset() - library.save() - -def lib_get_attr(id, attr): - global library - if id >= 0: - return library.get_attr(id, attr) - -def lib_inc_count(id): - global library - if id >= 0: - library.inc_count(id) - library.save() - -def lib_inc_score(id, amount=1): - global library - if id >= 0: - library.inc_score(id, amount) - library.save() - def lib_play_id(id): global cur_lib_id cur_lib_id = id - filepath = lib_get_attr(id, "filepath") + filepath = library.get_attr(id, "filepath") libsaria.music.load(filepath) libsaria.music.play() -def lib_find_id(file): - global library - return library.find_id(file) - def lib_get_cur_id(): global cur_lib_id return cur_lib_id @@ -101,9 +77,9 @@ def plist_add_libid(lib_id): # Hey, Future Bryan. I really want to use a lib_get_attrs() function # to return a list of attributes. Can you do that for me, please? # Thank you, Past Bryan - artist = lib_get_attr(lib_id, "artist") - album = lib_get_attr(lib_id, "album") - title = lib_get_attr(lib_id, "title") + artist = library.get_attr(lib_id, "artist") + album = library.get_attr(lib_id, "album") + title = library.get_attr(lib_id, "title") playlist.insert_tags(artist, album, title, lib_id) def plist_is_visible(id): @@ -135,18 +111,18 @@ def choose_next(): def change_score(): prcnt = libsaria.music.get_progress() if prcnt > 0.75: - lib_inc_count(cur_lib_id) - lib_inc_score(cur_lib_id) + inc_count(cur_lib_id) + inc_score(cur_lib_id) if prcnt < 0.33: - lib_inc_score(cur_lib_id, -1) + inc_score(cur_lib_id, -1) def plist_next(): change_score() choose_next() def catch_eos(*args): - lib_inc_count(cur_lib_id) - lib_inc_score(cur_lib_id) + inc_count(cur_lib_id) + inc_score(cur_lib_id) choose_next() libsaria.event.invite("POSTEOS", catch_eos) diff --git a/libsaria/collection/lens.py b/libsaria/collection/lens.py index fe89a57b..8a494788 100644 --- a/libsaria/collection/lens.py +++ b/libsaria/collection/lens.py @@ -96,7 +96,7 @@ class Playlist(collection.Collection): def random(self): if self.size == 0: return - getattr = libsaria.collection.lib_get_attr + getattr = libsaria.collection.get_attr last = self.last_tracks for i in xrange(15): id = self.get_rand_candidate() diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py new file mode 100644 index 00000000..f0a9b92e --- /dev/null +++ b/libsaria/collection/library.py @@ -0,0 +1,97 @@ +# Bryan Schumaker (11/05/2010) + +import libsaria + +fs_tree = None +tag_tree = None +index = None +tracks = None +next_id = None +sources = None +size = None + +def reset(): + from tree import DLTree + from index import Index + fs_tree = DLTree() + tag_tree = DLTree() + index = Index() + tracks = dict() + next_id = 0 + size = 0 + sources = [] + save() + +def load(): + global fs_tree + global tag_tree + global index + global tracks + global next_id + global sources + global size + objects = libsaria.data.load("library", ".dl_tree") + if objects == None or len(objects) != 6: + reset() + return + (fs_tree, tag_tree, index, tracks, next_id, size) = objects +load() + +def save(): + libsaria.data.save( + (fs_tree, tag_tree, index, tracks, next_id, size), + "library", ".dl_tree") + +def walk_tags(): + for tag in tag_tree.walk_forwards(): + rec = tracks[tag[3]] + yield tag + [rec.year] + [rec.lenstr] + +def file_to_id(file): + global fs_tree + stripped = file.strip(libsaria.path.sep) + split = stripped.split(libsaria.path.sep) + + res = fs_tree.walk_path(split) + if res == False: + return None + return res[0] + +def get_attr(id, attr): + rec = tracks.get(id, None) + if rec == None: + return None + if attr == "filepath": + cmp = rec.fs.walk_backwards() + return libsaria.path.sep.join([""] + cmp) + if attr == "playcount": + return rec.count + if attr == "year": + return rec.year + if attr == "lenstr": + return rec.lenstr + if attr == "score": + return rec.score + + tags = rec.tags.walk_backwards() + if attr == "artist": + return tags[0] + if attr == "album": + return tags[1] + if attr == "title": + return tags[2] + +def inc_score(id, amount=1): + rec = tracks.get(id, None) + if rec: + rec.score += amount + save() + +def inc_count(id): + rec = tracks.get(id, None) + if rec: + rec.count += 1 + save() + +def is_visible(id): + return True diff --git a/libsaria/data.py b/libsaria/data.py index f53ca140..9428cef5 100644 --- a/libsaria/data.py +++ b/libsaria/data.py @@ -54,7 +54,7 @@ def universal_open(file): plugin.install(file) return try: - id = libsaria.collection.lib_find_id(file) + id = libsaria.collection.file_to_id(file) if id: libsaria.collection.lib_play_id(id) else: diff --git a/libsaria/lastfm.py b/libsaria/lastfm.py index f3fd4935..bf25aedd 100644 --- a/libsaria/lastfm.py +++ b/libsaria/lastfm.py @@ -4,8 +4,9 @@ import libsaria import web import xm -cache = libsaria.cache -pref_attr = xm.find_preferred_attribute +file_to_id = libsaria.collection.file_to_id +cache = libsaria.cache +pref_attr = xm.find_preferred_attribute pref_sizes = ["extralarge", "large", "medium", "small"] @@ -61,11 +62,11 @@ def lfm_cache_album(file, artist, album): return False def get_artwork(filepath): - id = libsaria.collection.lib_find_id(filepath) + id = file_to_id(filepath) if id == None: return - artist = libsaria.collection.lib_get_attr(id, "artist") - album = libsaria.collection.lib_get_attr(id, "album") + artist = libsaria.collection.get_attr(id, "artist") + album = libsaria.collection.get_attr(id, "album") cached = cache[artist] file = cached.get("%s.jpg" % album, lfm_cache_album, artist, album) libsaria.event.start("POSTGETART", file) diff --git a/ocarina/collection.py b/ocarina/collection.py index 32210b0d..562bd6fa 100644 --- a/ocarina/collection.py +++ b/ocarina/collection.py @@ -6,6 +6,7 @@ import menu libsaria = ocarina.libsaria from libsaria import collection +library = collection.library event = ocarina.libsaria.event gtk = ocarina.gtk @@ -81,7 +82,7 @@ class Library(Collection): def populate(self): #import datetime #before = datetime.datetime.now() - Collection.populate(self, collection.walk_library) + Collection.populate(self, library.walk_tags) #after = datetime.datetime.now() #print "Populating took: %s" % (after - before) @@ -90,17 +91,17 @@ class Library(Collection): self.populate() def reset(self): - collection.lib_reset() + collection.reset() self.clear() def mouse_motion(self, row): - return (collection.lib_get_attr(row[0], "playcount"), - collection.lib_get_attr(row[0], "score")) + return (collection.get_attr(row[0], "playcount"), + collection.get_attr(row[0], "score")) def select_row(self, row): collection.change_score() collection.lib_play_id(row[0]) - collection.lib_inc_score(row[0], 1) + collection.inc_score(row[0], 1) def filter(self, text): collection.lib_filter(text) @@ -138,13 +139,13 @@ class Playlist(Collection): #print "Populating took: %s" % (after - before) def mouse_motion(self, row): - return (collection.lib_get_attr(row[0], "playcount"), - collection.lib_get_attr(row[0], "score")) + return (collection.get_attr(row[0], "playcount"), + collection.get_attr(row[0], "score")) def select_row(self, row): collection.change_score() collection.lib_play_id(row[0]) - collection.lib_inc_score(row[0], 1) + collection.inc_score(row[0], 1) def filter(self, text): collection.plist_filter(text) diff --git a/ocarina/info.py b/ocarina/info.py index f6641555..6cab2c1d 100644 --- a/ocarina/info.py +++ b/ocarina/info.py @@ -11,7 +11,8 @@ label = None image = None lib_get_cur_id = libsaria.collection.lib_get_cur_id -lib_get_attr = libsaria.collection.lib_get_attr +get_attr = libsaria.collection.get_attr +file_to_id = libsaria.collection.file_to_id filter = None info = None @@ -72,9 +73,9 @@ class InfoBar(Bar): libsaria.event.invite("POSTLOAD", self.change_title) def change_title(self, filepath): - id = libsaria.collection.lib_find_id(filepath) - title = lib_get_attr(id, "title") - artist = libsaria.collection.lib_get_attr(id, "artist") + id = file_to_id(filepath) + title = get_attr(id, "title") + artist = get_attr(id, "artist") self.title.set_text("%s by %s" % (title,artist)) diff --git a/ocarina/label.py b/ocarina/label.py index 4f53ff7b..e234aa5e 100644 --- a/ocarina/label.py +++ b/ocarina/label.py @@ -7,19 +7,19 @@ invite = ocarina.libsaria.event.invite libsaria = ocarina.libsaria #update = None -get_time = None -lib_get_attr = None -lib_find_id = None +get_time = None +get_attr = None +file_to_id = None def set_fns(): #global update global get_time - global lib_get_attr - global lib_find_id + global get_attr + global file_to_id #update = ocarina.libsaria.music.get_progress - get_time = ocarina.libsaria.music.get_time - lib_get_attr = libsaria.collection.lib_get_attr - lib_find_id = libsaria.collection.lib_find_id + get_time = ocarina.libsaria.music.get_time + get_attr = libsaria.collection.get_attr + file_to_id = libsaria.collection.file_to_id invite("POSTSTART", set_fns) @@ -45,11 +45,10 @@ class AttrLabel(gtk.Alignment): invite("POSTLOAD", self.update) def update(self, filepath): - global lib_find_id - global lib_get_attr - id = lib_find_id(filepath) + global get_attr + id = file_to_id(filepath) if id != None: - text = str(lib_get_attr(id, self.attr)) + text = str(get_attr(id, self.attr)) if self.other: text = "%s %s" % (self.other, text) self.label.set_text(text) diff --git a/plugins/wm_tweaks.py b/plugins/wm_tweaks.py index 933464e3..c5f21775 100644 --- a/plugins/wm_tweaks.py +++ b/plugins/wm_tweaks.py @@ -1,11 +1,11 @@ # Bryan Schumaker (10/30/2010) import ocarina -gdk = ocarina.gdk -libsaria = ocarina.libsaria -lib_find_id = libsaria.collection.lib_find_id -lib_get_attr = libsaria.collection.lib_get_attr -invite = libsaria.event.invite +gdk = ocarina.gdk +libsaria = ocarina.libsaria +file_to_id = libsaria.collection.file_to_id +get_attr = libsaria.collection.get_attr +invite = libsaria.event.invite def tweak_icon(file): @@ -17,8 +17,8 @@ def tweak_icon(file): def tweak_title(filepath): if filepath != None: - id = lib_find_id(filepath) - title = lib_get_attr(id, "title") + id = file_to_id(filepath) + title = get_attr(id, "title") else: title = ocarina.__vers__ ocarina.set_window_title(title) From 3cece3826fc9e0dcbdd16f96f845779b9334792d Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 6 Nov 2010 00:52:33 -0400 Subject: [PATCH 7/7] Library play_id() I have moved over the play_id function to the library module. --- libsaria/collection/__init__.py | 11 ++--------- libsaria/collection/library.py | 6 ++++++ libsaria/data.py | 2 +- ocarina/collection.py | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libsaria/collection/__init__.py b/libsaria/collection/__init__.py index 82801425..60863d9b 100644 --- a/libsaria/collection/__init__.py +++ b/libsaria/collection/__init__.py @@ -15,10 +15,10 @@ QUEUE = 2 import lens import library -#library = lens.Library() playlist = lens.Playlist() file_to_id = library.file_to_id +play_id = library.play_id get_attr = library.get_attr reset = library.reset inc_score = library.inc_score @@ -40,13 +40,6 @@ def new_source(path, bg=True): return 0 return call("NEWSOURCE", library.scan, path) -def lib_play_id(id): - global cur_lib_id - cur_lib_id = id - filepath = library.get_attr(id, "filepath") - libsaria.music.load(filepath) - libsaria.music.play() - def lib_get_cur_id(): global cur_lib_id return cur_lib_id @@ -106,7 +99,7 @@ def choose_next(): else: next = playlist.next_id(cur_lib_id) if next != None: - return call("NEXT", lib_play_id, next) + return call("NEXT", play_id, next) def change_score(): prcnt = libsaria.music.get_progress() diff --git a/libsaria/collection/library.py b/libsaria/collection/library.py index f0a9b92e..4add4f76 100644 --- a/libsaria/collection/library.py +++ b/libsaria/collection/library.py @@ -93,5 +93,11 @@ def inc_count(id): rec.count += 1 save() +def play_id(id): + libsaria.collection.cur_lib_id = id + filepath = get_attr(id, "filepath") + libsaria.music.load(filepath) + libsaria.music.play() + def is_visible(id): return True diff --git a/libsaria/data.py b/libsaria/data.py index 9428cef5..aa908d9b 100644 --- a/libsaria/data.py +++ b/libsaria/data.py @@ -56,7 +56,7 @@ def universal_open(file): try: id = libsaria.collection.file_to_id(file) if id: - libsaria.collection.lib_play_id(id) + libsaria.collection.play_id(id) else: libsaria.music.load(file) except Exception,e: diff --git a/ocarina/collection.py b/ocarina/collection.py index 562bd6fa..2dd7647e 100644 --- a/ocarina/collection.py +++ b/ocarina/collection.py @@ -100,7 +100,7 @@ class Library(Collection): def select_row(self, row): collection.change_score() - collection.lib_play_id(row[0]) + collection.play_id(row[0]) collection.inc_score(row[0], 1) def filter(self, text): @@ -144,7 +144,7 @@ class Playlist(Collection): def select_row(self, row): collection.change_score() - collection.lib_play_id(row[0]) + collection.play_id(row[0]) collection.inc_score(row[0], 1) def filter(self, text):