From 0b958c7686593190081d7c406068730d5dff47ef Mon Sep 17 00:00:00 2001 From: samuel-w Date: Tue, 8 Dec 2020 02:24:03 -0600 Subject: [PATCH 1/5] Sort tree dialogs alphabetically --- src/vorta/utils.py | 13 ++++++++++++- src/vorta/views/partials/tree_view.py | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index c3ae92d57..1536710fe 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -7,7 +7,7 @@ import re import sys import unicodedata -from collections import defaultdict +from collections import defaultdict, OrderedDict from datetime import datetime as dt from functools import reduce @@ -197,6 +197,17 @@ def get_asset(path): return os.path.join(bundle_dir, path) +def sort_dict(unordered_dict): + ''' Recursively sort a dictionary of dictionaries, ignoring alpha case ''' + sorted_dict = OrderedDict() + for key, value in sorted(unordered_dict.items(), key=lambda x: x[0].upper()): + if isinstance(value, dict): + sorted_dict[key] = sort_dict(value) + else: + sorted_dict[key] = value + return sorted_dict + + def get_sorted_wifis(profile): """Get SSIDs from OS and merge with settings in DB.""" diff --git a/src/vorta/views/partials/tree_view.py b/src/vorta/views/partials/tree_view.py index 01cd05e20..454babf52 100644 --- a/src/vorta/views/partials/tree_view.py +++ b/src/vorta/views/partials/tree_view.py @@ -1,9 +1,8 @@ from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt - import os import abc -from vorta.utils import get_dict_from_list, pretty_bytes +from vorta.utils import get_dict_from_list, pretty_bytes, sort_dict class FolderItem: @@ -187,6 +186,9 @@ def __init__( selected_files_folders=None, parent=None, ): + files_with_attributes.sort(key=lambda x: x[2].upper()) # Sorts tuples by name ignoring case + nested_file_list = sort_dict(nested_file_list) # Recursively sorts folders + super(TreeModel, self).__init__(parent) self.rootItem = FolderItem( From 0efab269a5d9055a1c94d99182d86d81527f33c1 Mon Sep 17 00:00:00 2001 From: samuel-w Date: Tue, 8 Dec 2020 02:26:21 -0600 Subject: [PATCH 2/5] Whitespace --- src/vorta/views/partials/tree_view.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vorta/views/partials/tree_view.py b/src/vorta/views/partials/tree_view.py index 454babf52..edcc6d1cf 100644 --- a/src/vorta/views/partials/tree_view.py +++ b/src/vorta/views/partials/tree_view.py @@ -1,4 +1,5 @@ from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt + import os import abc From 7496884287e8693f553afd9b28d163af108f3dea Mon Sep 17 00:00:00 2001 From: samuel-w Date: Tue, 8 Dec 2020 02:29:03 -0600 Subject: [PATCH 3/5] Clarify comment --- src/vorta/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 1536710fe..fb57e2c66 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -198,7 +198,7 @@ def get_asset(path): def sort_dict(unordered_dict): - ''' Recursively sort a dictionary of dictionaries, ignoring alpha case ''' + ''' Recursively sort a dictionary of dictionaries by key, ignoring alpha case ''' sorted_dict = OrderedDict() for key, value in sorted(unordered_dict.items(), key=lambda x: x[0].upper()): if isinstance(value, dict): From 01ea6805bef23392caf3c8b7e31f0e0e224ff1ef Mon Sep 17 00:00:00 2001 From: samuel-w Date: Tue, 8 Dec 2020 02:41:04 -0600 Subject: [PATCH 4/5] Add note for future --- src/vorta/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index fb57e2c66..60dd45506 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -201,6 +201,7 @@ def sort_dict(unordered_dict): ''' Recursively sort a dictionary of dictionaries by key, ignoring alpha case ''' sorted_dict = OrderedDict() for key, value in sorted(unordered_dict.items(), key=lambda x: x[0].upper()): + # In the future we want to move all the dicts to the start of the dictionary, and all the strings to the bottom if isinstance(value, dict): sorted_dict[key] = sort_dict(value) else: From d00e7f651f760e46c0ac9200ac318aa5bf1b2096 Mon Sep 17 00:00:00 2001 From: samuel-w Date: Tue, 8 Dec 2020 14:52:06 -0600 Subject: [PATCH 5/5] Remove uneeded sort, move folders to top --- src/vorta/utils.py | 14 +------------- src/vorta/views/partials/tree_view.py | 4 ++-- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 60dd45506..c3ae92d57 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -7,7 +7,7 @@ import re import sys import unicodedata -from collections import defaultdict, OrderedDict +from collections import defaultdict from datetime import datetime as dt from functools import reduce @@ -197,18 +197,6 @@ def get_asset(path): return os.path.join(bundle_dir, path) -def sort_dict(unordered_dict): - ''' Recursively sort a dictionary of dictionaries by key, ignoring alpha case ''' - sorted_dict = OrderedDict() - for key, value in sorted(unordered_dict.items(), key=lambda x: x[0].upper()): - # In the future we want to move all the dicts to the start of the dictionary, and all the strings to the bottom - if isinstance(value, dict): - sorted_dict[key] = sort_dict(value) - else: - sorted_dict[key] = value - return sorted_dict - - def get_sorted_wifis(profile): """Get SSIDs from OS and merge with settings in DB.""" diff --git a/src/vorta/views/partials/tree_view.py b/src/vorta/views/partials/tree_view.py index edcc6d1cf..56b9e631f 100644 --- a/src/vorta/views/partials/tree_view.py +++ b/src/vorta/views/partials/tree_view.py @@ -3,7 +3,7 @@ import os import abc -from vorta.utils import get_dict_from_list, pretty_bytes, sort_dict +from vorta.utils import get_dict_from_list, pretty_bytes class FolderItem: @@ -188,7 +188,7 @@ def __init__( parent=None, ): files_with_attributes.sort(key=lambda x: x[2].upper()) # Sorts tuples by name ignoring case - nested_file_list = sort_dict(nested_file_list) # Recursively sorts folders + files_with_attributes.sort(key=lambda x: x[0] != 0) # Pushes folders (size zero) to start of list super(TreeModel, self).__init__(parent)