self.update_gallery()
item.props.item.box = item
- label = f'{item.props.item.name} '
+ sorter_name = item.props.item.name
+ diversity = self.sort_attribute_diversities.get(sorter_name, 0)
+ label = f'{sorter_name} ({diversity}) '
item.props.item.filterer = item.props.child.get_last_child()
item.props.child.get_first_child().set_text(label)
filter_entry = item.props.child.get_last_child()
'clicked', lambda _: self.activate_sort_order())
sort_box.append(self.button_activate_sort)
self.filter_inputs = {}
+ self.sort_attribute_diversities = {}
return sort_box
def init_gallery_content():
init_key_control()
init_gallery_content()
self.load_directory(update_gallery=False)
- self.update_sort_order_box(self.sort_order)
GLib.idle_add(self.update_gallery)
def on_resize(self):
json_dump(list(bookmarks), f)
self.update_file_selection()
self.update_gallery_view()
+ self.update_sort_order_box(self.sort_order)
- def update_gallery(self, suggested_selection=None, sort=True):
+ def update_gallery(self, suggested_selection=None):
"""Build gallery based on .per_row and .gallery_selection."""
def sorter(a, b):
return slot
self.gallery.bind_model(None, lambda _: Gtk.Box())
- if sort:
- self.gallery_store.sort(sorter)
+ self.gallery_store.sort(sorter)
self.gallery.bind_model(self.gallery_selection, init_gallery_slot)
to_select = self.gallery.get_child_at_index(0)
if suggested_selection:
to_select.activate()
else:
self.counter.set_text(' (nothing) ')
+ for i in range(self.gallery_store_filtered.get_n_items()):
+ item = self.gallery.get_child_at_index(i).props.child.item
+ self.update_sort_order_box(self.sort_order)
self.update_gallery_view()
def update_gallery_view(self, refocus=False):
self.counter.set_text(f' {idx} of {total} ')
def update_sort_order_box(self, sort_order_source, cur_selection=0):
- """Rebuild self.sort_store from self.sort_order."""
+ """Rebuild .sort_store from .sort_order, update diversity counts."""
+ values = {}
+ for k in sort_order_source:
+ values[k] = set()
+ for i in range(self.gallery_store_filtered.get_n_items()):
+ item = self.gallery.get_child_at_index(i).props.child.item
+ if isinstance(item, ImgItem):
+ for attr_name in values.keys():
+ val = None
+ if hasattr(item, attr_name):
+ val = getattr(item, attr_name)
+ values[attr_name].add(val)
+ for attr_name in values.keys():
+ self.sort_attribute_diversities[attr_name] = len(values[attr_name])
self.sort_store.remove_all()
for s in sort_order_source:
self.sort_store.append(SortLabelItem(s))