From e0f22d29e81ffe5c060147f38d877a2956ef19fb Mon Sep 17 00:00:00 2001 From: Olivia Godone-Maresca Date: Mon, 6 Feb 2023 19:03:03 -0500 Subject: [PATCH 1/3] Sort models alphabetically --- ui/easydiffusion/model_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 0ca61c5d..20fa100b 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -182,7 +182,7 @@ def getModels(): def scan_directory(directory, suffixes): nonlocal models_scanned tree = [] - for entry in os.scandir(directory): + for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file(), entry.name.lower())): if entry.is_file(): matching_suffix = list(filter(lambda s: entry.name.endswith(s), suffixes)) if len(matching_suffix) == 0: continue From e7bf2ee58b163b56b7fd94b4423003891e4bed77 Mon Sep 17 00:00:00 2001 From: Olivia Godone-Maresca Date: Tue, 7 Feb 2023 21:13:06 -0500 Subject: [PATCH 2/3] Show models above folders in child folders to avoid models from appearing to belong the grandchild folder, prevent creating empty s --- ui/easydiffusion/model_manager.py | 9 +++++---- ui/media/js/main.js | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 20fa100b..9a7664ec 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -179,10 +179,10 @@ def getModels(): "Raised when picklescan reports a problem with a model" pass - def scan_directory(directory, suffixes): + def scan_directory(directory, suffixes, directoriesFirst:bool=True): nonlocal models_scanned tree = [] - for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file(), entry.name.lower())): + for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file() == directoriesFirst, entry.name.lower())): if entry.is_file(): matching_suffix = list(filter(lambda s: entry.name.endswith(s), suffixes)) if len(matching_suffix) == 0: continue @@ -197,9 +197,10 @@ def getModels(): known_models[entry.path] = mtime tree.append(entry.name[:-len(matching_suffix)]) elif entry.is_dir(): - scan=scan_directory(entry.path, suffixes) + scan=scan_directory(entry.path, suffixes, directoriesFirst=False) + if len(scan) != 0: - tree.append( (entry.name, scan ) ) + tree.append( (entry.name, scan ) ) return tree def listModels(model_type): diff --git a/ui/media/js/main.js b/ui/media/js/main.js index b0842620..d57e4f08 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -1322,9 +1322,12 @@ async function getModels() { } modelField.appendChild(modelOption) } else { - const modelGroup = document.createElement('optgroup') - modelGroup.label = path + modelName[0] - modelField.appendChild(modelGroup) + // Since s can't be nested, don't show empty groups + if (modelName[1].some(child => typeof(child) == 'string')) { + const modelGroup = document.createElement('optgroup') + modelGroup.label = path + modelName[0] + modelField.appendChild(modelGroup) + } modelName[1].forEach( createModelOptions(modelField, selectedModel, path + modelName[0] + "/" ) ) } } From ed9f18e22c49c37ca1c2ade715f493f11f2b8c60 Mon Sep 17 00:00:00 2001 From: Olivia Godone-Maresca Date: Thu, 9 Feb 2023 17:56:54 -0500 Subject: [PATCH 3/3] Trim lines --- ui/easydiffusion/model_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 9a7664ec..78508781 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -200,7 +200,7 @@ def getModels(): scan=scan_directory(entry.path, suffixes, directoriesFirst=False) if len(scan) != 0: - tree.append( (entry.name, scan ) ) + tree.append( (entry.name, scan ) ) return tree def listModels(model_type):