From 2587ae0954adc54c643636e3526d7e06a1dbe258 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 21 May 2011 08:20:44 -0400 Subject: [PATCH] ocarina: Fill new library I make the list of songs visible, I also update the number of songs. Finally, I respond to the library_updated() callback when songs are added / removed from the library. --- ocarina/callbacks.py | 5 +++++ ocarina/library.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ocarina/callbacks.py b/ocarina/callbacks.py index a4bd5359..a626ee73 100644 --- a/ocarina/callbacks.py +++ b/ocarina/callbacks.py @@ -6,6 +6,7 @@ from ocarina import body from ocarina.body import footer from libsaria import callbacks import playlist +import library import oldlibrary def on_play(): @@ -42,6 +43,10 @@ def on_load_library(): oldlibrary.refresh() callbacks.on_new_source = on_load_library +def library_updated(): + library.refresh() +callbacks.on_library_updated = library_updated + def on_queue_changed(): queue.refresh() callbacks.on_queue_changed = on_queue_changed diff --git a/ocarina/library.py b/ocarina/library.py index 51c0e19e..352a7f85 100644 --- a/ocarina/library.py +++ b/ocarina/library.py @@ -1,8 +1,24 @@ # Bryan Schumaker (5 / 20 / 2011) +import libsaria import sources import body +library = libsaria.sources.library lib_page = sources.Source() LIB_PAGE = body.add_page(lib_page, "Library") LIB_PAGE.goto = lib_page.goto + +def set_label_text(): + LIB_PAGE.label.set_text("Library (%s)" % library.num_visible()) + +def fill_library(): + attrs = ("id", "title", "lenstr", "artist", "album", "year") + songs = libsaria.sources.list_library(*attrs) + lib_page.insert(songs) + set_label_text() +fill_library() + +def refresh(): + lib_page.clear() + fill_library()