[Bf-extensions-cvs] [1ef22029] asset-shelf: Use asset-shelf (partially prototype) for the pose library add-on

Julian Eisel noreply at git.blender.org
Thu Feb 2 17:05:07 CET 2023


Commit: 1ef22029433236f95b8c0044563df629ed3b3379
Author: Julian Eisel
Date:   Thu Feb 2 17:04:17 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBA1ef22029433236f95b8c0044563df629ed3b3379

Use asset-shelf (partially prototype) for the pose library add-on

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

M	pose_library/gui.py
M	pose_library/keymaps.py

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

diff --git a/pose_library/gui.py b/pose_library/gui.py
index c5b5747e..374f14d4 100644
--- a/pose_library/gui.py
+++ b/pose_library/gui.py
@@ -8,6 +8,7 @@ import bpy
 from bpy.types import (
     AssetHandle,
     Context,
+    Header,
     Menu,
     Panel,
     UIList,
@@ -26,34 +27,38 @@ class PoseLibraryPanel:
         return cls.pose_library_panel_poll(context)
 
 
+class VIEW3D_HT_pose_library_asset_shelf(PoseLibraryPanel, Header):
+    bl_space_type = "VIEW_3D"
+    bl_region_type = "ASSET_SHELF"
+
+    def draw(self, context: Context) -> None:
+        layout = self.layout
+
+        is_poses_only = PoseLibraryPanel.poll(context)
+
+        wm = context.window_manager
+
+        # TODO flipped pose option?
+        # TODO create/copy poses?
+
+        if hasattr(layout, "template_asset_shelf"):
+            filter_id_types = {"filter_action"} if is_poses_only else {"filter_object", "filter_material"}
+            layout.template_asset_shelf(filter_id_types=filter_id_types)
+
+
 class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel):
     bl_space_type = "VIEW_3D"
-    bl_region_type = "UI"
-    bl_category = "Animation"
+    bl_region_type = "ASSET_SHELF"
     bl_label = "Pose Library"
 
     def draw(self, context: Context) -> None:
         layout = self.layout
 
-        if hasattr(layout, "template_asset_view"):
-            workspace = context.workspace
-            wm = context.window_manager
-            activate_op_props, drag_op_props = layout.template_asset_view(
-                "pose_assets",
-                workspace,
-                "asset_library_ref",
-                wm,
-                "pose_assets",
-                workspace,
-                "active_pose_asset_index",
-                filter_id_types={"filter_action"},
-                activate_operator="poselib.apply_pose_asset",
-                drag_operator="poselib.blend_pose_asset",
-            )
-
-            # Make sure operators properties match those used in
-            # `pose_library_list_item_context_menu` so shortcuts show in menus (see T103267).
-            activate_op_props.flipped = False
+        row = layout.row(align=True)
+        row.operator("poselib.create_pose_asset").activate_new_action = False
+        if bpy.types.POSELIB_OT_restore_previous_action.poll(context):
+            row.operator("poselib.restore_previous_action", text="", icon='LOOP_BACK')
+        row.operator("poselib.copy_as_asset", icon="COPYDOWN", text="")
 
 
 def pose_library_list_item_context_menu(self: UIList, context: Context) -> None:
@@ -193,6 +198,7 @@ classes = (
     DOPESHEET_PT_asset_panel,
     VIEW3D_PT_pose_library,
     ASSETBROWSER_MT_asset,
+    VIEW3D_HT_pose_library_asset_shelf,
 )
 
 _register, _unregister = bpy.utils.register_classes_factory(classes)
diff --git a/pose_library/keymaps.py b/pose_library/keymaps.py
index 37eccce6..7de037b1 100644
--- a/pose_library/keymaps.py
+++ b/pose_library/keymaps.py
@@ -19,6 +19,15 @@ def register() -> None:
     kmi = km.keymap_items.new("poselib.apply_pose_asset", "LEFTMOUSE", "DOUBLE_CLICK")
     addon_keymaps.append((km, kmi))
 
+    # Asset Shelf
+    km = wm.keyconfigs.addon.keymaps.new(name="Asset Shelf")
+    # Click to apply pose.
+    kmi = km.keymap_items.new("poselib.apply_pose_asset", "LEFTMOUSE", "CLICK")
+    addon_keymaps.append((km, kmi))
+    # Drag to blend pose.
+    kmi = km.keymap_items.new("poselib.blend_pose_asset", "LEFTMOUSE", "CLICK_DRAG")
+    addon_keymaps.append((km, kmi))
+
 
 def unregister() -> None:
     # Clear shortcuts from the keymap.



More information about the Bf-extensions-cvs mailing list