Files
test/scripts/addons_core/pose_library/keymaps.py
Julian Eisel 450f428434 Fix #143699: Pose library asset shelf does not apply poses
This was quite involved to get to work. Basic idea is to make
`bl_activate_operator` work for the pose library asset shelf, and
introducing a `bl_drag_operator` for blending poses.

- Make pose asset operators take an asset reference, which is how
  `bl_activate_operator` usually gets the asset to operate on. This way
  poses references can be assigned to a shortcut, identified by asset
  library and relative asset path within the library. Falls back to
  getting the asset from context.
- Trigger `bl_activate_operator` on every click, instead of only when
  an un-active item becomes active. Needed so poses can be re-applied
  as before.
- Fix button context not passed to the `bl_activate_operator` when
  force-activating, e.g. on right-click events.
- Allow registering a `bl_drag_operator` in the asset shelf definition.
  Executed when dragging an asset in the shelf.
- When dragging an asset, highlight it as active, without calling the
  `bl_activate_operator`. This is important feedback to the user.
- Activate/select view items on click instead of drag, so dragging is
  possible.
- Let pose applying operators handle the Ctrl key to apply poses
  flipped. There's no simple way to attach such alternative behaviors
  to `bl_activate_operator`/`bl_drag_operator`
- Remove keymap items that were there for the previous "hacky" solution
  to apply & blend poses.

Pull Request: https://projects.blender.org/blender/blender/pulls/144023
2025-08-28 12:04:31 +02:00

30 lines
809 B
Python

# SPDX-FileCopyrightText: 2010-2023 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
from typing import List, Tuple
import bpy
addon_keymaps: List[Tuple[bpy.types.KeyMap, bpy.types.KeyMapItem]] = []
def register() -> None:
wm = bpy.context.window_manager
if wm.keyconfigs.addon is None:
# This happens when Blender is running in the background.
return
km = wm.keyconfigs.addon.keymaps.new(name="File Browser Main", space_type="FILE_BROWSER")
# DblClick to apply pose.
kmi = km.keymap_items.new("poselib.apply_pose_asset", "LEFTMOUSE", "DOUBLE_CLICK")
addon_keymaps.append((km, kmi))
def unregister() -> None:
# Clear shortcuts from the keymap.
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()