From c31ec8001686fe01a2f5daa710fd838e1ba59009 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 18 Jun 2011 11:37:48 -0400 Subject: [PATCH] ocarina: Function for refreshing library source list The settings page may need to be updated once it has been created. This patch adds a function for recreating the list of sources. --- ocarina/settings/library.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ocarina/settings/library.py b/ocarina/settings/library.py index 4b93475c..0ab27533 100644 --- a/ocarina/settings/library.py +++ b/ocarina/settings/library.py @@ -5,18 +5,20 @@ import libsaria page = gtk.VBox() text = "Library" +panels = {} -def remove_path(button, path, panel): +def remove_path(button, path): + page.remove(panels[path]) + del panels[path] libsaria.sources.library.rm_path(path) - page.remove(panel) -def add_panel(panel): +def add_panel(panel, path): full_box = gtk.VBox() full_box.pack_start(panel) full_box.pack_start(gtk.HSeparator()) full_box.show_all() + panels[path] = full_box page.pack_start(full_box, False, False) - return full_box def show_source(path, lib): panel = gtk.HBox() @@ -25,15 +27,21 @@ def show_source(path, lib): path_lbl = gtk.Label() path_lbl.set_markup("%s" % path) count_lbl = gtk.Label() - count_lbl.set_markup("%s songs" % len(lib)) + count_lbl.set_markup("%s files" % len(lib)) remove_button = gtk.Button("Remove", gtk.STOCK_REMOVE) + remove_button.connect("clicked", remove_path, path) info_box.pack_start(path_lbl) info_box.pack_start(count_lbl) panel.pack_start(info_box) panel.pack_start(remove_button, False, False) - full = add_panel(panel) - remove_button.connect("clicked", remove_path, path, full) + add_panel(panel, path) + +def refresh(): + for path in panels: + page.remove(panels[path]) + + for path, lib in libsaria.sources.library.list_paths(): + show_source(path, lib) +refresh() -for path, lib in libsaria.sources.library.list_paths(): - show_source(path, lib)