Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-05 11:13:02 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-05 11:13:02 +0300
commit2fee3336a85ac5d5fb7c7765cd8ae2aa4e7621ac (patch)
tree29370a247279051a5e91b4233584ff594916bafc /pose_library
parent1f38515d87fb78443f2ead17b4e95411f43dc1b2 (diff)
Pose Library: avoid breakage due to changes in the asset browser
Asset browser moved from Categories (the big, fixed buttons) to Catalogs (the tree-based, user-creatable organisation system). This required some changes to the Pose Library code, as that was still expecting to be able to use the categories system. The entire workflow has to be looked at better, but at least now it's not broken anymore.
Diffstat (limited to 'pose_library')
-rw-r--r--pose_library/asset_browser.py31
-rw-r--r--pose_library/operators.py18
2 files changed, 28 insertions, 21 deletions
diff --git a/pose_library/asset_browser.py b/pose_library/asset_browser.py
index 3983e610..8bedd968 100644
--- a/pose_library/asset_browser.py
+++ b/pose_library/asset_browser.py
@@ -14,20 +14,17 @@ else:
functions = importlib.reload(functions)
-def area_for_category(screen: bpy.types.Screen, category: str) -> Optional[bpy.types.Area]:
- """Return the asset browser area that is most suitable for managing the category.
+def biggest_asset_browser_area(screen: bpy.types.Screen) -> Optional[bpy.types.Area]:
+ """Return the asset browser Area that's largest on screen.
:param screen: context.window.screen
- :param category: asset category, see asset_category_items in rna_space.c
- :return: the area, or None if no Asset Browser area exists.
+ :return: the Area, or None if no Asset Browser area exists.
"""
def area_sorting_key(area: bpy.types.Area) -> Tuple[bool, int]:
- """Return tuple (is correct category, area size in pixels)"""
- space_data = area.spaces[0]
- asset_cat: str = space_data.params.asset_category
- return (asset_cat == category, area.width * area.height)
+ """Return area size in pixels."""
+ return (area.width * area.height)
areas = list(suitable_areas(screen))
if not areas:
@@ -46,20 +43,17 @@ def suitable_areas(screen: bpy.types.Screen) -> Iterable[bpy.types.Area]:
yield area
-def area_from_context(context: bpy.types.Context, category: str) -> Optional[bpy.types.Area]:
+def area_from_context(context: bpy.types.Context) -> Optional[bpy.types.Area]:
"""Return an Asset Browser suitable for the given category.
Prefers the current Asset Browser if available, otherwise the biggest.
"""
space_data = context.space_data
- if not asset_utils.SpaceAssetInfo.is_asset_browser(space_data):
- return area_for_category(context.screen, category)
-
- if space_data.params.asset_category != category:
- return area_for_category(context.screen, category)
+ if asset_utils.SpaceAssetInfo.is_asset_browser(space_data):
+ return context.area
- return context.area
+ return biggest_asset_browser_area(context.screen)
def activate_asset(
@@ -72,6 +66,13 @@ def activate_asset(
space_data.activate_asset_by_id(asset, deferred=deferred)
+def active_catalog_id(asset_browser: bpy.types.Area) -> str:
+ """Return the ID of the catalog shown in the asset browser."""
+ space_data = asset_browser.spaces[0]
+ assert asset_utils.SpaceAssetInfo.is_asset_browser(space_data)
+ return space_data.params.catalog_id
+
+
def tag_redraw(screen: bpy.types.Screen) -> None:
"""Tag all asset browsers for redrawing."""
diff --git a/pose_library/operators.py b/pose_library/operators.py
index c0c8b332..3b038709 100644
--- a/pose_library/operators.py
+++ b/pose_library/operators.py
@@ -106,9 +106,7 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator):
This makes it possible to immediately check & edit the created pose asset.
"""
- asset_browse_area: Optional[bpy.types.Area] = asset_browser.area_for_category(
- context.screen, "ANIMATION"
- )
+ asset_browse_area: Optional[bpy.types.Area] = asset_browser.biggest_asset_browser_area(context.screen)
if not asset_browse_area:
return
@@ -277,9 +275,17 @@ class POSELIB_OT_paste_asset(Operator):
self.report({"INFO"}, "Pasted %d assets" % len(assets))
bpy.ops.file.refresh()
- asset_browser_area = asset_browser.area_from_context(context, 'ANIMATIONS')
- if asset_browser_area:
- asset_browser.activate_asset(assets[0], asset_browser_area, deferred=True)
+
+ asset_browser_area = asset_browser.area_from_context(context)
+ if not asset_browser_area:
+ return {"FINISHED"}
+
+ # Assign same catalog as in asset browser.
+ catalog_id = asset_browser.active_catalog_id(asset_browser_area)
+ for asset in assets:
+ print(f"{asset}.asset_data.catalog_id = {catalog_id}")
+ asset.asset_data.catalog_id = catalog_id
+ asset_browser.activate_asset(assets[0], asset_browser_area, deferred=True)
return {"FINISHED"}