From: Christian Heller Date: Mon, 9 Sep 2024 23:58:29 +0000 (+0200) Subject: In browser.py, fix continuously broken sorting algorithm. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/ledger?a=commitdiff_plain;h=38032cacf5d1de769acbdbd277fc01b554e3cc10;p=stable_plom In browser.py, fix continuously broken sorting algorithm. --- diff --git a/browser.py b/browser.py index 41b33d5..9de8ca7 100755 --- a/browser.py +++ b/browser.py @@ -277,31 +277,26 @@ class MainWindow(Gtk.Window): def sorter(a, b): # ensure ".." and all DirItems at start of order if self.include_dirs: - if isinstance(a, DirItem) and isinstance(b, DirItem): - cmp_upper_dir = f' {UPPER_DIR}' - if a.name == cmp_upper_dir: - return +1 - if b.name == cmp_upper_dir: - return -1 - elif isinstance(a, DirItem): + cmp_upper_dir = f' {UPPER_DIR}' + if isinstance(a, DirItem) and a.name == cmp_upper_dir: + return -1 + if isinstance(b, DirItem) and b.name == cmp_upper_dir: return +1 - elif isinstance(b, DirItem): + if isinstance(a, DirItem) and not isinstance(b, DirItem): + return -1 + if isinstance(b, DirItem) and not isinstance(a, DirItem): return +1 # apply self.sort_order within DirItems and FileItems (separately) for key in self.sort_order: - a_cmp = None - b_cmp = None - if hasattr(a, key): - a_cmp = getattr(a, key) - if hasattr(b, key): - b_cmp = getattr(b, key) - if a_cmp is None and b_cmp is not None: + if a_cmp is None and b_cmp is None: + continue + if a_cmp is None: return -1 - elif a_cmp is not None and b_cmp is None: + if b_cmp is None: return +1 - elif a_cmp > b_cmp: + if a_cmp > b_cmp: return +1 - elif a_cmp < b_cmp: + if a_cmp < b_cmp: return -1 return 0