From: Christian Heller Date: Thu, 12 Sep 2024 16:14:27 +0000 (+0200) Subject: browser: Minor fixes to bookmarking. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/templates?a=commitdiff_plain;h=b4f6d37d2df9268f91f14dd2dc4e6b5257d33313;p=stable_plom browser: Minor fixes to bookmarking. --- diff --git a/browser.py b/browser.py index 905f02b..1798fec 100755 --- a/browser.py +++ b/browser.py @@ -195,7 +195,7 @@ class MainWindow(Gtk.Window): text = entry.get_buffer().get_text() if '' != text.rstrip(): self.filter_inputs[item.props.item.name] = text - else: + elif item.props.item.name in self.filter_inputs.keys(): del self.filter_inputs[item.props.item.name] self.update_gallery() @@ -386,12 +386,6 @@ class MainWindow(Gtk.Window): to_select.activate() else: self.counter.set_text(' (nothing) ') - with open(BOOKMARKS_PATH, 'r', encoding='utf8') as f: - bookmarks = json_load(f) - for i in range(self.gallery_store_filtered.get_n_items()): - slot = self.gallery_store.get_item(i) - if slot.full_path in bookmarks: - slot.bookmarked = True self.update_gallery_view() def update_gallery_view(self, refocus=False): @@ -444,19 +438,6 @@ class MainWindow(Gtk.Window): elif slot_bottom > vp_bottom: vp_scroll.set_value(slot_bottom - vp_height) vp_scroll.emit('value-changed') - # # DEBUG: mere statistics - # from datetime import datetime - # n_imgs, n_buttons, n_others = 0, 0, 0 - # for i in range(self.gallery_store_filtered.props.n_items): - # child = self.gallery.get_child_at_index(i).props.child - # grandchild = child.get_first_child() - # if isinstance(grandchild, Gtk.Image): - # n_imgs += 1 - # elif isinstance(grandchild, Gtk.Button): - # n_buttons += 1 - # else: - # n_others += 1 - # print(datetime.now(), "DEBUG", n_imgs, n_buttons, n_others) def hit_file_selection(self): """If current file selection is directory, reload into that one.""" @@ -598,8 +579,7 @@ class MainWindow(Gtk.Window): def load_directory(self, update_gallery=True): """Load into gallery directory at .app.img_dir_absolute.""" - def read_directory_into_gallery_items(cache, dir_path, - make_parent=False): + def read_directory_into_gallery_items(dir_path, make_parent=False): directory = Gio.File.new_for_path(dir_path) query_attrs = 'standard::name,time::*' if make_parent: @@ -620,10 +600,12 @@ class MainWindow(Gtk.Window): self.gallery_store.append(DirItem(dir_path, info)) if self.recurse_dirs: read_directory_into_gallery_items( - cache, path_join(dir_path, info.get_name())) + path_join(dir_path, info.get_name())) elif info.get_content_type()\ and info.get_content_type().startswith('image/'): item = ImgItem(dir_path, info, cache) + if item.full_path in bookmarks: + item.bookmarked = True if '' == item.model: to_set_metadata_on += [item] self.gallery_store.append(item) @@ -635,10 +617,11 @@ class MainWindow(Gtk.Window): self.block_file_selection_updates = True self.gallery_store.remove_all() self.block_file_selection_updates = False + with open(BOOKMARKS_PATH, 'r', encoding='utf8') as f: + bookmarks = json_load(f) with open(CACHE_PATH, 'r', encoding='utf8') as f: cache = json_load(f) - read_directory_into_gallery_items(cache, self.app.img_dir_absolute, - True) + read_directory_into_gallery_items(self.app.img_dir_absolute, True) with open(CACHE_PATH, 'w', encoding='utf8') as f: json_dump(cache, f) if update_gallery: