def __init__(self, as_list: list[SorterAndFilterer]) -> None:
self._list = as_list
- def __eq__(self, other):
+ def __eq__(self, other) -> bool:
return self._list == other._list
def __len__(self) -> int:
return self._list.__iter__()
@staticmethod
- def _list_from_store(store) -> list[SorterAndFilterer]:
+ def _list_from_store(store: Gio.ListStore) -> list[SorterAndFilterer]:
order = []
for i in range(store.get_n_items()):
order += [store.get_item(i)]
"""Create new, of equal order."""
return self.__class__(self._list[:])
+ def sync_from(self, other_order: Self) -> None:
+ """Sync internal state from other order."""
+ self._list = other_order._list
+
+ def remove(self, sorter_name: str) -> None:
+ """Remove sorter of sorter_name from self."""
+ for sorter in [s for s in self._list if sorter_name == s.name]:
+ self._list.remove(sorter)
+
def update_from_store(self, store: Gio.ListStore) -> None:
"""Update self from store."""
self._list = self._list_from_store(store)
sort_item: SorterAndFilterer = self._store.get_item(i)
sort_item.widget.add_css_class('temp')
+ def sync_sorter(self, order: SorterAndFiltererOrder) -> None:
+ """Update .order and its dependencies from order."""
+ self.order.sync_from(order)
+ self.update_box()
+
def update_box(self,
alt_order: Optional[SorterAndFiltererOrder] = None,
cur_selection: int = 0
class Gallery:
"""Representation of GalleryItems below a directory."""
update_config_box: Callable
+ sync_sorter: Callable
def __init__(self,
on_hit_item: Callable,
def _make_basic_items_attrs(self,
entries: list[GalleryItem]
) -> BasicItemsAttrs:
+
basic_items_attrs = {}
for attr_name in (s.name for s in self._sort_order):
vals: set[str] = set()
read_directory(path)
read_directory(self._img_dir_path, make_parent=True)
- self._basic_items_attrs = self._make_basic_items_attrs(
- self.dir_entries)
+ basic_items_attrs = self._make_basic_items_attrs(self.dir_entries)
+ ignorable_attrs = []
+ for attr_name, attr_vals in basic_items_attrs.items():
+ if len(attr_vals) < 2:
+ ignorable_attrs += [attr_name]
+ for attr_name in ignorable_attrs:
+ self._sort_order.remove(attr_name)
+ self._basic_items_attrs = basic_items_attrs
self._cache_db.write()
@property
for category in ('incl', 'semi', 'excl'):
final_values[category].sort()
self.items_attrs[attr_name] = final_values
+ self.sync_sorter(self._sort_order)
def filter_entries(items_attrs: ItemsAttrs) -> list[GalleryItem]:
entries_filtered: list[GalleryItem] = []
update_settings=self.gallery.update_settings,
items_attrs=self.gallery.items_attrs)
self.gallery.update_config_box = self.conf.update_box
+ self.gallery.sync_sorter = self.conf.sync_sorter
metadata_textview = Gtk.TextView(wrap_mode=Gtk.WrapMode.WORD_CHAR,
editable=False)
self.metadata = metadata_textview.get_buffer()