From 1ef22029433236f95b8c0044563df629ed3b3379 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 2 Feb 2023 17:04:17 +0100 Subject: [PATCH 01/13] Use asset-shelf (partially prototype) for the pose library add-on --- pose_library/gui.py | 48 +++++++++++++++++++++++------------------ pose_library/keymaps.py | 9 ++++++++ 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index c5b5747ec..374f14d43 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 37eccce6c..7de037b1d 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. -- 2.30.2 From 2b118a1cda2905a7126ff94ea5cb231808b5e9a7 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 21 Feb 2023 18:51:46 +0100 Subject: [PATCH 02/13] Update pose library add-on for new asset shelf BPY support --- pose_library/gui.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index 374f14d43..a842ee742 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -27,24 +27,21 @@ class PoseLibraryPanel: return cls.pose_library_panel_poll(context) -class VIEW3D_HT_pose_library_asset_shelf(PoseLibraryPanel, Header): +class VIEW3D_AST_pose_library(bpy.types.AssetShelf): bl_space_type = "VIEW_3D" - bl_region_type = "ASSET_SHELF" - def draw(self, context: Context) -> None: - layout = self.layout + # TODO flipped pose option? + # TODO create/copy poses? - 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) + @classmethod + def poll(cls, context: Context) -> bool: + return PoseLibraryPanel.poll(context) + # XXX temporary design. Should be like this instead: + # bl_asset_traits = {'ACTION'} + @classmethod + def asset_poll__(cls, asset: AssetHandle) -> bool: + return asset.file_data.id_type == 'ACTION' class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): bl_space_type = "VIEW_3D" @@ -198,7 +195,7 @@ classes = ( DOPESHEET_PT_asset_panel, VIEW3D_PT_pose_library, ASSETBROWSER_MT_asset, - VIEW3D_HT_pose_library_asset_shelf, + VIEW3D_AST_pose_library, ) _register, _unregister = bpy.utils.register_classes_factory(classes) -- 2.30.2 From ed87062a24d0b88cb3856ba31adc079cce5c90d6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 17 May 2023 17:23:12 +0200 Subject: [PATCH 03/13] Bring back old asset-view template UI (additionally) The asset shelf will be merged as experimental feature at first, so keep the old UI available. --- pose_library/gui.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index db207f5ca..6d3578afc 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -8,7 +8,6 @@ import bpy from bpy.types import ( AssetHandle, Context, - Header, Menu, Panel, UIList, @@ -43,19 +42,35 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): def asset_poll__(cls, asset: AssetHandle) -> bool: return asset.file_data.id_type == 'ACTION' + class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): bl_space_type = "VIEW_3D" - bl_region_type = "ASSET_SHELF" + bl_region_type = "UI" + bl_category = "Animation" bl_label = "Pose Library" def draw(self, context: Context) -> None: layout = self.layout - 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="") + 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 def pose_library_list_item_context_menu(self: UIList, context: Context) -> None: -- 2.30.2 From 2dc9f9fd9dc9798a2c276da61ce53af6df4e4001 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 18 May 2023 01:48:26 +0200 Subject: [PATCH 04/13] Make dragging work Follow up to 67db4448de. --- pose_library/gui.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pose_library/gui.py b/pose_library/gui.py index 6d3578afc..c496b3395 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -28,6 +28,7 @@ class PoseLibraryPanel: class VIEW3D_AST_pose_library(bpy.types.AssetShelf): bl_space_type = "VIEW_3D" + bl_options = {'NO_ASSET_DRAG'} # TODO flipped pose option? # TODO create/copy poses? -- 2.30.2 From 1e9a0da49c24d3a0fb5a811746fa198a06cda3be Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 18 May 2023 01:48:56 +0200 Subject: [PATCH 05/13] Context menu for pose library asset shelf --- pose_library/gui.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pose_library/gui.py b/pose_library/gui.py index c496b3395..de1bb1e6a 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -10,6 +10,7 @@ from bpy.types import ( Context, Menu, Panel, + UILayout, UIList, WindowManager, WorkSpace, @@ -43,6 +44,26 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): def asset_poll__(cls, asset: AssetHandle) -> bool: return asset.file_data.id_type == 'ACTION' + @classmethod + def draw_context_menu(cls, _context: Context, _asset: AssetHandle, layout: UILayout): + # Make sure these operator properties match those used in `VIEW3D_PT_pose_library`. + layout.operator("poselib.apply_pose_asset", text="Apply Pose").flipped = False + layout.operator("poselib.apply_pose_asset", text="Apply Pose Flipped").flipped = True + + old_op_ctx = layout.operator_context + layout.operator_context = 'INVOKE_DEFAULT' + props = layout.operator("poselib.blend_pose_asset", text="Blend Pose") + layout.operator_context = old_op_ctx + + layout.separator() + 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 + + layout.separator() + layout.operator("asset.open_containing_blend_file") + class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): bl_space_type = "VIEW_3D" -- 2.30.2 From e102a4de5513f22cf22cd37e8b587d07ec3d62ac Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 19 May 2023 15:46:29 +0200 Subject: [PATCH 06/13] Don't show old pose library UI when experimental asset shelf is enabled --- pose_library/gui.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pose_library/gui.py b/pose_library/gui.py index de1bb1e6a..1e50fe371 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -71,6 +71,15 @@ class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): bl_category = "Animation" bl_label = "Pose Library" + @classmethod + def poll(cls, context: Context) -> bool: + prefs = bpy.context.preferences + # Use Asset Shelf as UI instead of the old asset-view template in the sidebar. + if prefs.experimental.use_asset_shelf: + return False + + return PoseLibraryPanel.poll(context) + def draw(self, context: Context) -> None: layout = self.layout -- 2.30.2 From 557d58e195f6b77870cd62f901622f36e47f6587 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 19 May 2023 16:55:37 +0200 Subject: [PATCH 07/13] Cleanup: Use passed in context, not `bpy.context` --- pose_library/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index 1e50fe371..4b8cc36be 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -73,7 +73,7 @@ class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): @classmethod def poll(cls, context: Context) -> bool: - prefs = bpy.context.preferences + prefs = context.preferences # Use Asset Shelf as UI instead of the old asset-view template in the sidebar. if prefs.experimental.use_asset_shelf: return False -- 2.30.2 From c9f294930f1f502e637cfe47f03cf66cbe78cf63 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 19 May 2023 16:58:32 +0200 Subject: [PATCH 08/13] Cleanup: Remove outdated TODO comments These options are now handled via the context menu in the main branch and in this branch. --- pose_library/gui.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index 4b8cc36be..de9c3f85f 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -31,9 +31,6 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): bl_space_type = "VIEW_3D" bl_options = {'NO_ASSET_DRAG'} - # TODO flipped pose option? - # TODO create/copy poses? - @classmethod def poll(cls, context: Context) -> bool: return PoseLibraryPanel.poll(context) -- 2.30.2 From c4ffacbbfecead209b8e3abb1db8103b90eb1958 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 6 Jun 2023 12:57:40 +0200 Subject: [PATCH 09/13] Refactor: pose library, use `bl_ui_utils.layout.operator_context` See aab2ce8987, apply this change to the new pose library asset shelf ase well. --- pose_library/gui.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index 1602e13e2..48f9805b5 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -48,10 +48,8 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): layout.operator("poselib.apply_pose_asset", text="Apply Pose").flipped = False layout.operator("poselib.apply_pose_asset", text="Apply Pose Flipped").flipped = True - old_op_ctx = layout.operator_context - layout.operator_context = 'INVOKE_DEFAULT' - props = layout.operator("poselib.blend_pose_asset", text="Blend Pose") - layout.operator_context = old_op_ctx + with operator_context(layout, 'INVOKE_DEFAULT'): + layout.operator("poselib.blend_pose_asset", text="Blend Pose") layout.separator() props = layout.operator("poselib.pose_asset_select_bones", text="Select Pose Bones") -- 2.30.2 From 6f8650f3a04b55917c40bc8bad0d390c9e5907df Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 8 Jun 2023 11:49:27 +0200 Subject: [PATCH 10/13] Fix asset trait comment --- pose_library/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index 48f9805b5..17c359a21 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -37,7 +37,7 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): return PoseLibraryPanel.poll(context) # XXX temporary design. Should be like this instead: - # bl_asset_traits = {'ACTION'} + # bl_asset_traits = {"Action"} @classmethod def asset_poll__(cls, asset: AssetHandle) -> bool: return asset.file_data.id_type == 'ACTION' -- 2.30.2 From dca343a2599e5bbf849faf53cd89d9b79c0f97ee Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 27 Jul 2023 15:04:20 +0200 Subject: [PATCH 11/13] Pose Library: Correct changed asset shelf function name --- pose_library/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index d5a809e8f..b4fdaa984 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -41,7 +41,7 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): # XXX temporary design. Should be like this instead: # bl_asset_traits = {"Action"} @classmethod - def asset_poll__(cls, asset: AssetHandle) -> bool: + def asset_poll_temp_api(cls, asset: AssetHandle) -> bool: return asset.file_data.id_type == 'ACTION' @classmethod -- 2.30.2 From c415f0783303dd8273f04d2cfa69203471d725fb Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 2 Aug 2023 16:18:51 +0200 Subject: [PATCH 12/13] Pose Library: Correct asset shelf callback name, remove outdated TODO --- pose_library/gui.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index b4fdaa984..588bdad2b 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -38,10 +38,8 @@ class VIEW3D_AST_pose_library(bpy.types.AssetShelf): def poll(cls, context: Context) -> bool: return PoseLibraryPanel.poll(context) - # XXX temporary design. Should be like this instead: - # bl_asset_traits = {"Action"} @classmethod - def asset_poll_temp_api(cls, asset: AssetHandle) -> bool: + def asset_poll(cls, asset: AssetHandle) -> bool: return asset.file_data.id_type == 'ACTION' @classmethod -- 2.30.2 From 169093f1bc80bfe8f0e5efc8ac09cc3c2fac10f8 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 2 Aug 2023 17:28:04 +0200 Subject: [PATCH 13/13] Pose Library: Add comment on asset shelf option --- pose_library/gui.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pose_library/gui.py b/pose_library/gui.py index 588bdad2b..ec3e9fa59 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -32,6 +32,8 @@ class PoseLibraryPanel: class VIEW3D_AST_pose_library(bpy.types.AssetShelf): bl_space_type = "VIEW_3D" + # We have own keymap items to add custom drag behavior (pose blending), disable the default + # asset dragging. bl_options = {'NO_ASSET_DRAG'} @classmethod -- 2.30.2