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-08 15:21:32 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-08 15:21:32 +0300
commite6e981e9d1f3a5523391a656a1363552285ad522 (patch)
tree1c9efdacef67ec24d3f6e7a78b20d386eedc6195 /pose_library
parentd920e6a3785f054ee306ba7712cd0cdafc3e02ce (diff)
Pose Library: refresh dopesheet & 3D view when changing asset library
The Create Pose Asset (`POSELIB_OT_create_pose_asset`) operator stores the created asset in the current blend file. To avoid confusion, its poll function refuses the use of the operator when the asset browser is showing a different asset library. This means that the panels containing a button for this operator need to be refreshed whenever another asset library is selected.
Diffstat (limited to 'pose_library')
-rw-r--r--pose_library/gui.py43
-rw-r--r--pose_library/operators.py3
2 files changed, 45 insertions, 1 deletions
diff --git a/pose_library/gui.py b/pose_library/gui.py
index da7b77c7..397f24bd 100644
--- a/pose_library/gui.py
+++ b/pose_library/gui.py
@@ -205,6 +205,42 @@ class DOPESHEET_PT_asset_panel(PoseLibraryPanel, Panel):
layout.operator("poselib.convert_old_poselib")
+### Messagebus subscription to monitor asset library changes.
+_msgbus_owner = object()
+
+def _on_asset_library_changed() -> None:
+ """Update areas when a different asset library is selected."""
+ refresh_area_types = {'DOPESHEET_EDITOR', 'VIEW_3D'}
+ for win in bpy.context.window_manager.windows:
+ for area in win.screen.areas:
+ if area.type not in refresh_area_types:
+ continue
+
+ area.tag_redraw()
+
+def register_message_bus() -> None:
+ bpy.msgbus.subscribe_rna(
+ key=(bpy.types.FileAssetSelectParams, "asset_library_ref"),
+ owner=_msgbus_owner,
+ args=(),
+ notify=_on_asset_library_changed,
+ options={'PERSISTENT'},
+ )
+
+def unregister_message_bus() -> None:
+ bpy.msgbus.clear_by_owner(_msgbus_owner)
+
+@bpy.app.handlers.persistent
+def _on_blendfile_load_pre(none, other_none) -> None:
+ # The parameters are required, but both are None.
+ unregister_message_bus()
+
+@bpy.app.handlers.persistent
+def _on_blendfile_load_post(none, other_none) -> None:
+ # The parameters are required, but both are None.
+ register_message_bus()
+
+
classes = (
ASSETBROWSER_PT_pose_library_editing,
ASSETBROWSER_PT_pose_library_usage,
@@ -230,12 +266,19 @@ def register() -> None:
bpy.types.UI_MT_list_item_context_menu.prepend(pose_library_list_item_context_menu)
bpy.types.ASSETBROWSER_MT_context_menu.prepend(pose_library_list_item_context_menu)
+ register_message_bus()
+ bpy.app.handlers.load_pre.append(_on_blendfile_load_pre)
+ bpy.app.handlers.load_post.append(_on_blendfile_load_post)
+
def unregister() -> None:
_unregister()
+ unregister_message_bus()
+
del WorkSpace.active_pose_asset_index
del WindowManager.pose_assets
bpy.types.UI_MT_list_item_context_menu.remove(pose_library_list_item_context_menu)
bpy.types.ASSETBROWSER_MT_context_menu.remove(pose_library_list_item_context_menu)
+
diff --git a/pose_library/operators.py b/pose_library/operators.py
index 9aa0333e..956a41a0 100644
--- a/pose_library/operators.py
+++ b/pose_library/operators.py
@@ -75,7 +75,8 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator):
bl_idname = "poselib.create_pose_asset"
bl_label = "Create Pose Asset"
bl_description = (
- "Create a new Action that contains the pose of the selected bones, and mark it as Asset"
+ "Create a new Action that contains the pose of the selected bones, and mark it as Asset. "
+ "The asset will be stored in the current blend file"
)
bl_options = {"REGISTER", "UNDO"}