From c7e9fb5deb4f85b69d437c250396937e5458030d Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 6 Apr 2017 23:55:17 +0200 Subject: [PATCH] Show indicator while loading lists --- mtg-collector/cardlist.py | 13 ++++++++++--- mtg-collector/library.py | 16 ++++++++++++++-- mtg-collector/search.py | 2 +- mtg-collector/util.py | 5 ++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/mtg-collector/cardlist.py b/mtg-collector/cardlist.py index 85dda96..9e064c0 100644 --- a/mtg-collector/cardlist.py +++ b/mtg-collector/cardlist.py @@ -105,17 +105,20 @@ class CardList(Gtk.ScrolledWindow): self.list.append_column(col_mana) self.list.append_column(col_cmc) - def update(self, library, progressbar=None): + def update(self, library, progressbar=None, loading_indicator=None): progress_step = 1 / len(library) progress = 0.0 + self.store.clear() if self.filtered: self.list.freeze_child_notify() self.list.set_model(None) - self.store.clear() if progressbar is not None: progressbar.set_fraction(progress) + if loading_indicator is not None: + GObject.idle_add(loading_indicator.set_visible, True, priority=GObject.PRIORITY_DEFAULT) + for multiverse_id, card in library.items(): if card.multiverse_id is not None: if card.supertypes is None: @@ -134,11 +137,15 @@ class CardList(Gtk.ScrolledWindow): card.set_name] self.store.append(item) progress += progress_step + if progressbar is not None: progressbar.set_fraction(progress) + if loading_indicator is not None: + GObject.idle_add(loading_indicator.set_visible, False, priority=GObject.PRIORITY_DEFAULT) if self.filtered: - self.list.set_model(self.store) + self.list.set_model(self.filter_and_sort) self.list.thaw_child_notify() + GObject.idle_add(util.push_status, "Library ready.", priority=GObject.PRIORITY_DEFAULT) def update_generate(self, library, step=128): n = 0 diff --git a/mtg-collector/library.py b/mtg-collector/library.py index 05222aa..f5ff1bb 100644 --- a/mtg-collector/library.py +++ b/mtg-collector/library.py @@ -64,6 +64,17 @@ class LibraryView(Gtk.Grid): right_pane.pack_start(Gtk.VSeparator(), False, False, 2) right_pane.pack_start(self.remove_button, False, False, 2) + spinner = Gtk.Spinner() + spinner.start() + label = Gtk.Label("Loading List") + + self.spinner_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.spinner_box.pack_start(spinner, True, False, 0) + self.overlay = Gtk.Overlay() + self.overlay.add(self.lib_list) + self.overlay.add_overlay(self.spinner_box) + self.overlay.show_all() + # Bring it all together self.attach(topbox, 0, 0, 3, 1) @@ -74,7 +85,7 @@ class LibraryView(Gtk.Grid): self.attach(Gtk.VSeparator(), 1, 2, 1, 1) - self.attach(self.lib_list, 2, 2, 1, 1) + self.attach(self.overlay, 2, 2, 1, 1) self.attach(Gtk.VSeparator(), 3, 0, 1, 3) @@ -84,6 +95,7 @@ class LibraryView(Gtk.Grid): self.refresh_library() def refresh_library(self, button=None): + util.push_status("Loading Library") self.search_entry.activate() self.fill_lib_list() @@ -113,7 +125,7 @@ class LibraryView(Gtk.Grid): def fill_lib_list(self): # Fill List in thread - load_thread = threading.Thread(target=self.lib_list.update, args=(util.library, )) + load_thread = threading.Thread(target=self.lib_list.update, args=(util.library, None, self.spinner_box, )) load_thread.setDaemon(True) load_thread.start() diff --git a/mtg-collector/search.py b/mtg-collector/search.py index 7e7f01c..c354ade 100644 --- a/mtg-collector/search.py +++ b/mtg-collector/search.py @@ -242,7 +242,7 @@ class SearchView(Gtk.Grid): # region Public Functions def reload(self): - pass + self.searchEntry.grab_focus() def load_cards(self): # Get search term diff --git a/mtg-collector/util.py b/mtg-collector/util.py index fa40b24..0bf55d7 100644 --- a/mtg-collector/util.py +++ b/mtg-collector/util.py @@ -70,7 +70,7 @@ def import_library(): library.clear() for id, card in imported.items(): library[id] = card - unsaved_changes = True + save_library() push_status("Library imported") print("Library imported") dialog.destroy() @@ -243,7 +243,6 @@ def create_mana_icons(mana_string): pixbuf = GdkPixbuf.Pixbuf.new_from_file(path) pixbuf = pixbuf.scale_simple(image.width / 5, image.height / 5, GdkPixbuf.InterpType.HYPER) except: - print("Error while loading file " + path) return - # os.remove(config.cache_path + filename) + # os.remove(path) return pixbuf