diff --git a/mirage/__init__.py b/mirage/__init__.py index 3cd1427..9ccf1e2 100755 --- a/mirage/__init__.py +++ b/mirage/__init__.py @@ -765,6 +765,27 @@ menu_item = Gio.MenuItem.new(name, "app." + action_name) custom_actions_section.insert_item(i, menu_item) + def thumbpane_do_update(self, force_upto_imgnum): + # Load all images up to the bottom of the visible thumbpane rect: + visible_range = self.thumbpane.get_visible_range() + if not visible_range: + return + + start_path, end_path = visible_range + start_image = max(0, start_path.get_indices()[0] - 1) + end_image = min(len(self.image_list), end_path.get_indices()[0]) + + if force_upto_imgnum > end_image: + end_image = force_upto_imgnum + + # update images: + thread = threading.Thread( + target=self.thumbpane_update_pending_images, + args=(start_image, end_image, force_upto_imgnum), + ) + thread.setDaemon(True) + thread.start() + def thumbpane_update_images(self, clear_first=False, force_upto_imgnum=-1): self.stop_now = False # When first populating the thumbpane, make sure we go up to at least @@ -772,29 +793,7 @@ if clear_first: self.thumbpane_clear_list() - # TODO: All of these are a hack and need to be removed - while Gtk.events_pending(): - Gtk.main_iteration() - - # Load all images up to the bottom of the visible thumbpane rect: - visible_range = self.thumbpane.get_visible_range() - if not visible_range: - return - - start_path, end_path = visible_range - start_image = max(0, start_path.get_indices()[0] - 1) - end_image = min(len(self.image_list), end_path.get_indices()[0]) - - if force_upto_imgnum > end_image: - end_image = force_upto_imgnum - - # update images: - thread = threading.Thread( - target=self.thumbpane_update_pending_images, - args=(start_image, end_image, force_upto_imgnum), - ) - thread.setDaemon(True) - thread.start() + GLib.idle_add(self.thumbpane_do_update, force_upto_imgnum) def thumbpane_create_dir(self): if not os.path.exists(os.path.expanduser("~/.thumbnails/")):