Skip to content

Commit

Permalink
Fix #83 : Presets are no longer buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorgious56 committed Jul 24, 2022
1 parent efd622c commit 520c917
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 34 deletions.
11 changes: 8 additions & 3 deletions core/cache/prop.py
Expand Up @@ -57,11 +57,11 @@ class Cache(PropertyGroup):
op_tag_add_or_remove: PointerProperty(type=TagAddOrRemoveOperatorProperties)
op_custom_prop_set: PointerProperty(type=CustomPropertySetOperatorProperties)
op_custom_prop_remove: PointerProperty(type=RemoveCustomPropertyOperatorProperties)

op_preview_generate: PointerProperty(type=PreviewGenerateOperatorProperties)
op_preview_extract: PointerProperty(type=PreviewExtractOperatorProperties)
op_preview_import: PointerProperty(type=PreviewImportOperatorProperties)

op_catalog_move_from_a_to_b: PointerProperty(type=CatalogMoveFromAToBOperatorProperties)
op_catalog_move: PointerProperty(type=CatalogMoveOperatorProperties)
op_catalog_remove: PointerProperty(type=CatalogRemoveFromOperatorProperties)
Expand Down Expand Up @@ -97,4 +97,9 @@ def draw(self, layout, context, header=None, rename=False):
for attr in self.__annotations__:
default_setting = getattr(self, attr)
if hasattr(default_setting, "draw"):
default_setting.draw(layout, context)
box = layout.box()
name = default_setting.__class__.__name__
# https://stackoverflow.com/a/45778633/7092409
name = "".join(" " + char if char.isupper() else char.strip() for char in name).strip()
box.label(text=name)
default_setting.draw(box, context)
2 changes: 1 addition & 1 deletion core/filter/type.py
Expand Up @@ -80,7 +80,7 @@ class FilterTypes(PropertyGroup):
},
)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()

row = box.row(align=True)
Expand Down
9 changes: 5 additions & 4 deletions core/operator/tool.py
Expand Up @@ -11,7 +11,7 @@
from bpy_extras.io_utils import ImportHelper

from asset_browser_utilities.core.tool import copy_simple_property_group
from asset_browser_utilities.core.cache.tool import get_presets, get_from_cache
from asset_browser_utilities.core.cache.tool import get_current_operator_properties, get_presets, get_from_cache
from asset_browser_utilities.core.ui.message import message_box
from asset_browser_utilities.core.file.path import open_file_if_different_from_current
from asset_browser_utilities.core.file.save import save_if_possible_and_necessary, save_file_as
Expand Down Expand Up @@ -89,13 +89,14 @@ def update_preset(self, context):
preset = get_preferences().defaults
else:
preset = next(p for p in get_preferences().presets if p.name == preset_name)
current_op = get_current_operator_properties()
for attr in preset.__annotations__:
if attr == "library_settings":
continue
if not hasattr(self, attr):
continue
default_setting = getattr(preset, attr)
setting = getattr(self, attr)
if attr.startswith("op_") and not type(default_setting) == type(current_op):
continue
setting = get_from_cache(type(default_setting))
if hasattr(setting, "copy_from"): # Assume it's a "complicated" property group if copy_from is implemented
setting.copy_from(default_setting)
else:
Expand Down
8 changes: 4 additions & 4 deletions core/preferences/ui.py
Expand Up @@ -27,7 +27,7 @@ def draw(self, context):
layout.prop(self, "show_custom_props", icon="PROPERTIES")

self.defaults.asset_filter_settings.filter_selection.allow = True
self.defaults.asset_filter_settings.filter_catalog.allow = True
self.defaults.asset_filter_settings.filter_catalog.allow = False

box = layout.box()
self.defaults.draw(box, context, header="Set Defaults")
Expand All @@ -37,7 +37,7 @@ def draw(self, context):
row.label(text="Presets")
row.operator("abu.presets_add_or_remove", text="", icon="ADD").index = -1
for i, preset in enumerate(self.presets):
lay = box if preset.show else box.row(align=True)
preset.draw(lay, context, header="Expand", rename=True)
layout = box if preset.show else box.row(align=True)
preset.draw(layout, context, header="Expand", rename=True)
if not preset.show:
lay.operator("abu.presets_add_or_remove", text="", icon="REMOVE").index = i
layout.operator("abu.presets_add_or_remove", text="", icon="REMOVE").index = i
2 changes: 1 addition & 1 deletion module/asset/export/operator.py
Expand Up @@ -27,7 +27,7 @@ class AssetExportOperatorProperties(PropertyGroup):
default=True,
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "individual_files", icon="NEWFOLDER")
layout.prop(self, "overwrite", icon="ASSET_MANAGER")

Expand Down
4 changes: 2 additions & 2 deletions module/asset/import_/prop.py
Expand Up @@ -11,7 +11,7 @@ class CacheAssetPath(PropertyGroup):
# class CacheAssetPaths(PropertyGroup):
# items: CollectionProperty(type=CacheAssetPath)

# def draw(self, layout):
# def draw(self, layout, context=None):
# # Used for debugging purpose
# for item in self.items:
# for prop_name in item.__annotations__:
Expand All @@ -34,7 +34,7 @@ class ExportProperties(PropertyGroup):
description="If checked, the file where the assets will be exported will be opened in a new blender instance",
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "open_in_new_blender_instance", icon="WINDOW")
layout.prop(self, "individual_files", icon="NEWFOLDER")
layout.prop(self, "overwrite", icon="ASSET_MANAGER")
2 changes: 1 addition & 1 deletion module/asset/operator/copy.py
Expand Up @@ -58,7 +58,7 @@ class AssetCopyDataOperatorProperties(PropertyGroup):
author: BoolProperty(name="Author")
description: BoolProperty(name="Description")

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.label(text="Copy These Properties From Active Asset")
box.prop(self, "tags", icon="BOOKMARKS")
Expand Down
2 changes: 1 addition & 1 deletion module/asset/operator/mark.py
Expand Up @@ -41,7 +41,7 @@ class AssetMarkOperatorProperties(PropertyGroup):
description="When marking assets, automatically generate a preview\nUncheck to mark assets really fast",
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "overwrite", icon="ASSET_MANAGER")
row = layout.row(align=True)
row.prop(self, "generate_previews", icon="RESTRICT_RENDER_OFF")
Expand Down
2 changes: 1 addition & 1 deletion module/author/set.py
Expand Up @@ -19,7 +19,7 @@ def execute_one_file_and_the_next_when_finished(self):
class AuthorSetOperatorProperties(PropertyGroup):
author: StringProperty(name="Author")

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "author", icon="USER")


Expand Down
2 changes: 1 addition & 1 deletion module/catalog/operator/move_from_a_to_b.py
Expand Up @@ -29,7 +29,7 @@ class CatalogMoveFromAToBOperatorProperties(PropertyGroup):
catalog_from: PointerProperty(type=FilterCatalog)
catalog_to: PointerProperty(type=FilterCatalog)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.label(text="Move Assets :")
split = box.split(factor=0.35)
Expand Down
2 changes: 1 addition & 1 deletion module/catalog/operator/move_to.py
Expand Up @@ -86,7 +86,7 @@ class CatalogMoveOperatorProperties(PropertyGroup):
catalog: PointerProperty(type=FilterCatalog)
catalog_name: StringProperty(name="Name")

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.label(text="Move Assets to This Catalog")
box.prop(self, "mode")
Expand Down
2 changes: 1 addition & 1 deletion module/catalog/operator/remove_from.py
Expand Up @@ -30,7 +30,7 @@ class CatalogRemoveFromOperatorProperties(PropertyGroup):
filter: BoolProperty(default=True, description="")
catalog: PointerProperty(type=FilterCatalog)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
row = box.row(align=True)
row.label(text="Remove Assets From This Catalog" if self.filter else "Remove Assets From All Catalogs")
Expand Down
2 changes: 1 addition & 1 deletion module/catalog/operator/sort_catalogs_like_folders.py
Expand Up @@ -54,7 +54,7 @@ class CatalogSortLikeFoldersOperatorProperties(PropertyGroup):
default=False,
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "are_assets_in_subfolders", text="Assets are contained in individual folders")


Expand Down
2 changes: 1 addition & 1 deletion module/custom_property/operator/remove.py
Expand Up @@ -23,7 +23,7 @@ def do_on_asset(self, asset):
class RemoveCustomPropertyOperatorProperties(PropertyGroup):
name: StringProperty(name="Name", default="prop")

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "name", text="Custom Property Name")


Expand Down
2 changes: 1 addition & 1 deletion module/custom_property/operator/set.py
Expand Up @@ -44,7 +44,7 @@ def value(self):
else:
return getattr(self, self.type)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.prop(self, "name")
box.prop(self, "type")
Expand Down
2 changes: 1 addition & 1 deletion module/description/set.py
Expand Up @@ -20,7 +20,7 @@ def execute_one_file_and_the_next_when_finished(self):
class DescriptionSetOperatorProperties(PropertyGroup):
description: StringProperty(name="Description")

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "description", icon="FILE_TEXT")


Expand Down
2 changes: 1 addition & 1 deletion module/material/operator/merge.py
Expand Up @@ -54,7 +54,7 @@ class MaterialMergeOperatorProperties(PropertyGroup):
execute_all: BoolProperty(name="Merge all duplicate materials", default=False)
material_name: EnumProperty(name="Base Material", items=get_all_materials_for_an_enum_selector)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.label(text="Merge materials")
box.prop(self, "mode")
Expand Down
2 changes: 1 addition & 1 deletion module/material/operator/replace.py
Expand Up @@ -36,7 +36,7 @@ class MaterialReplaceOperatorProperties(PropertyGroup):
material_to: EnumProperty(name="Replace", items=get_all_materials_for_an_enum_selector)
material_from: EnumProperty(name="With", items=get_all_materials_for_an_enum_selector)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.prop(self, "material_to")
box.prop(self, "material_from")
Expand Down
2 changes: 1 addition & 1 deletion module/node_tree/operator/merge.py
Expand Up @@ -116,7 +116,7 @@ class NodeTreeMergeOperatorProperties(PropertyGroup):
execute_all: BoolProperty(name="Merge all duplicate node trees", default=False)
node_tree_name: EnumProperty(name="Base Node Tree", items=get_all_node_trees_for_an_enum_selector)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.label(text="Merge Node Trees")
box.prop(self, "tree_type")
Expand Down
2 changes: 1 addition & 1 deletion module/node_tree/operator/replace.py
Expand Up @@ -57,7 +57,7 @@ class NodeTreeReplaceOperatorProperties(PropertyGroup):
node_tree_old: EnumProperty(name="Replace", items=get_all_node_trees_for_an_enum_selector)
node_tree_new: EnumProperty(name="With", items=get_all_node_trees_for_an_enum_selector)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
box.prop(self, "tree_type")
box.prop(self, "node_tree_old")
Expand Down
2 changes: 1 addition & 1 deletion module/preview/operator/extract.py
Expand Up @@ -47,7 +47,7 @@ class PreviewExtractOperatorProperties(PropertyGroup):
default=False,
)

def draw(self, layout):
def draw(self, layout, context=None):
if get_from_cache(LibraryExportSettings).source != LibraryType.FileCurrent.value:
layout.prop(self, "place_at_root", icon="FILEBROWSER")

Expand Down
2 changes: 1 addition & 1 deletion module/preview/operator/generate.py
Expand Up @@ -25,7 +25,7 @@ class PreviewGenerateOperatorProperties(PropertyGroup):
default=False,
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "overwrite", icon="ASSET_MANAGER")


Expand Down
2 changes: 1 addition & 1 deletion module/preview/operator/import_.py
Expand Up @@ -58,7 +58,7 @@ class PreviewImportOperatorProperties(PropertyGroup):
default="",
)

def draw(self, layout):
def draw(self, layout, context=None):
layout.prop(self, "load_if_name_contains_image_name", icon="OUTLINER_OB_FONT")
layout.prop(self, "look_only_in_folder_with_name", icon="FILTER")

Expand Down
2 changes: 1 addition & 1 deletion module/tag/operator/tool.py
Expand Up @@ -14,7 +14,7 @@ def init(self, add=True):
self.tag_collection.add = add
self.tag_collection.init(tags=self.MAX_TAGS)

def draw(self, layout):
def draw(self, layout, context=None):
box = layout.box()
self.tag_collection.draw(box)
if self.tag_collection.remove_all:
Expand Down
2 changes: 1 addition & 1 deletion module/tag/tag_collection.py
Expand Up @@ -38,7 +38,7 @@ def init(self, tags: int = 10):
while len(self.items) < tags:
self.items.add()

def draw(self, layout):
def draw(self, layout, context=None):
box = layout
row = box.row()
split = row.split(factor=0.2)
Expand Down

0 comments on commit 520c917

Please sign in to comment.