[Bf-extensions-cvs] [4422b945] asset-browser-poselib: Pose Library: Add operators to context menu of poses in the asset view

Julian Eisel noreply at git.blender.org
Thu Apr 1 17:42:23 CEST 2021


Commit: 4422b945d5ade1decbd81c3b69c5c8b54868b67d
Author: Julian Eisel
Date:   Thu Apr 1 17:39:20 2021 +0200
Branches: asset-browser-poselib
https://developer.blender.org/rBA4422b945d5ade1decbd81c3b69c5c8b54868b67d

Pose Library: Add operators to context menu of poses in the asset view

Adds the following operators to the menu:
* Apply Pose
* Blend Pose
* Select Pose Bones
* Deselect Pose Bones

Note that the latter two don't work yet with the asset view template (they are
implemented based on Asset Browser context) and are grayed out. They need to be
updated to also work with the asset view context.

===================================================================

M	pose_library/gui.py

===================================================================

diff --git a/pose_library/gui.py b/pose_library/gui.py
index fe131496..57fb9f1f 100644
--- a/pose_library/gui.py
+++ b/pose_library/gui.py
@@ -61,6 +61,32 @@ class VIEW3D_PT_pose_library(Panel):
             drag_op_props.release_confirm = True
 
 
+def pose_library_list_item_context_menu(self, context) -> None:
+    def _poll(context) -> bool:
+        # Important: Must check context first, or the menu is added for every kind of list.
+        list = context.ui_list
+        if not list or list.bl_idname != "UI_UL_asset_view" or list.list_id != "pose_assets":
+            return False
+        if not context.asset_handle:
+            return False
+        return True
+
+    if _poll(context) == False:
+        return
+
+    layout = self.layout
+
+    layout.separator()
+
+    layout.operator("poselib.apply_pose_asset", text="Apply Pose")
+    layout.operator("poselib.blend_pose_asset", text="Blend Pose")
+
+    props = layout.operator("poselib.pose_asset_select_bones", text="Select Pose Bones")
+    props.select = True
+    props = layout.operator("poselib.pose_asset_select_bones", text="Deselect Pose Bones")
+    props.select = False
+
+
 class ASSETBROWSER_PT_pose_library_usage(asset_utils.AssetBrowserPanel, Panel):
     bl_region_type = "TOOLS"
     bl_label = "Pose Library"
@@ -127,4 +153,16 @@ classes = (
     VIEW3D_PT_pose_library,
 )
 
-register, unregister = bpy.utils.register_classes_factory(classes)
+def register():
+    from bpy.utils import register_class
+    for cls in classes:
+        register_class(cls)
+
+    bpy.types.UI_MT_list_item_context_menu.prepend(pose_library_list_item_context_menu)
+
+def unregister():
+    from bpy.utils import unregister_class
+    for cls in classes:
+        unregister_class(cls)
+
+    bpy.types.UI_MT_list_item_context_menu.remove(pose_library_list_item_context_menu)
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list