Skip to content

Commit

Permalink
fix #4256 again...
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Aug 11, 2021
1 parent 978a830 commit a5d0742
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions ui/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,30 @@ def get_presets_directory(category=None, mkdir=True, standard=False):
if standard:
presets = join(get_sverchok_directory(), path_partial)
else:
presets = join(bpy.utils.user_resource('DATAFILES', path=path_partial, create=mkdir))
presets = join(bpy.utils.user_resource('DATAFILES', path=path_partial, create=False))
if not os.path.exists(presets) and mkdir and not standard:
os.makedirs(presets)
return presets

def get_category_names(mkdir=True):
def get_category_names(mkdir=True, include_empty=False):
standard = get_presets_directory(standard=True)
user = get_presets_directory(standard=False, mkdir=mkdir)
categories = []
for base in [standard, user]:
for path in sorted(glob(join(base, "*"))):
if isdir(path) and os.listdir(path):
name = basename(path)
if name not in categories:
categories.append(name)
if isdir(path):
is_empty = len(os.listdir(path)) == 0
if include_empty or not is_empty:
name = basename(path)
if name not in categories:
categories.append(name)
return categories

def get_category_items(self, context):
def get_category_items(self, context, include_empty=False):
category_items = None
category_items = [(GENERAL, "General", "Uncategorized presets", 0)]
node_category_items = []
for idx, category in enumerate(get_category_names()):
for idx, category in enumerate(get_category_names(include_empty=include_empty)):
node_class = get_node_class_reference(category)
if node_class and hasattr(node_class, 'bl_label'):
title = "/Node/ {}".format(node_class.bl_label)
Expand All @@ -92,6 +94,12 @@ def get_category_items(self, context):
category_items = category_items + [None] + node_category_items
return category_items

def get_category_items_all(self, context):
return get_category_items(self, context, include_empty=True)

def get_category_items_nonempty(self, context):
return get_category_items(self, context, include_empty=False)

def get_preset_path(name, category=None, standard=False, mkdir=True):
presets = get_presets_directory(category, standard=standard, mkdir=mkdir)
return join(presets, name + ".json")
Expand Down Expand Up @@ -387,7 +395,7 @@ class SvUserPresetsPanelProps(bpy.types.PropertyGroup):
category : EnumProperty(
name = "Category",
description = "Select presets category",
items = get_category_items)
items = get_category_items_nonempty)

search_text : StringProperty(
name = "Search",
Expand Down Expand Up @@ -464,7 +472,7 @@ class SvPresetProps(bpy.types.Operator):
bl_options = {'INTERNAL'}

old_category: StringProperty(name="Old category", description="Preset category")
new_category: EnumProperty(name="Category", description="New preset category", items = get_category_items)
new_category: EnumProperty(name="Category", description="New preset category", items = get_category_items_all)
allow_change_category : BoolProperty(default = True)
include_node_categories : BoolProperty(default = False)

Expand Down Expand Up @@ -720,7 +728,7 @@ class SvPresetFromGist(bpy.types.Operator):
category : EnumProperty(
name = "Category",
description = "Select presets category",
items = get_category_items)
items = get_category_items_all)

def execute(self, context):
if not self.preset_name:
Expand Down

0 comments on commit a5d0742

Please sign in to comment.