Skip to content
Snippets Groups Projects
Commit a9d4443c authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Cleanup: pose library, reformat the code

Use `black --skip-string-normalization` to reformat the Python code.

No functional changes.
parent 5aae6aa6
No related branches found
Tags
No related merge requests found
...@@ -26,7 +26,7 @@ def biggest_asset_browser_area(screen: bpy.types.Screen) -> Optional[bpy.types.A ...@@ -26,7 +26,7 @@ def biggest_asset_browser_area(screen: bpy.types.Screen) -> Optional[bpy.types.A
def area_sorting_key(area: bpy.types.Area) -> Tuple[bool, int]: def area_sorting_key(area: bpy.types.Area) -> Tuple[bool, int]:
"""Return area size in pixels.""" """Return area size in pixels."""
return (area.width * area.height) return area.width * area.height
areas = list(suitable_areas(screen)) areas = list(suitable_areas(screen))
if not areas: if not areas:
...@@ -70,9 +70,7 @@ def area_from_context(context: bpy.types.Context) -> Optional[bpy.types.Area]: ...@@ -70,9 +70,7 @@ def area_from_context(context: bpy.types.Context) -> Optional[bpy.types.Area]:
return None return None
def activate_asset( def activate_asset(asset: bpy.types.Action, asset_browser: bpy.types.Area, *, deferred: bool) -> None:
asset: bpy.types.Action, asset_browser: bpy.types.Area, *, deferred: bool
) -> None:
"""Select & focus the asset in the browser.""" """Select & focus the asset in the browser."""
space_data = asset_browser.spaces[0] space_data = asset_browser.spaces[0]
......
...@@ -28,11 +28,7 @@ def convert_old_poselib(old_poselib: Action) -> Collection[Action]: ...@@ -28,11 +28,7 @@ def convert_old_poselib(old_poselib: Action) -> Collection[Action]:
marker will be converted to an Action by itself and marked as asset. marker will be converted to an Action by itself and marked as asset.
""" """
pose_assets = [ pose_assets = [action for marker in old_poselib.pose_markers if (action := convert_old_pose(old_poselib, marker))]
action
for marker in old_poselib.pose_markers
if (action := convert_old_pose(old_poselib, marker))
]
# Mark all Actions as assets in one go. Ideally this would be done on an # Mark all Actions as assets in one go. Ideally this would be done on an
# appropriate frame in the scene (to set up things like the background # appropriate frame in the scene (to set up things like the background
......
...@@ -19,14 +19,11 @@ from bpy.types import ( ...@@ -19,14 +19,11 @@ from bpy.types import (
class PoseLibraryPanel: class PoseLibraryPanel:
@classmethod @classmethod
def pose_library_panel_poll(cls, context: Context) -> bool: def pose_library_panel_poll(cls, context: Context) -> bool:
return bool( return bool(context.object and context.object.mode == 'POSE')
context.object
and context.object.mode == 'POSE'
)
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
return cls.pose_library_panel_poll(context); return cls.pose_library_panel_poll(context)
class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel):
...@@ -104,7 +101,6 @@ def pose_library_list_item_context_menu(self: UIList, context: Context) -> None: ...@@ -104,7 +101,6 @@ def pose_library_list_item_context_menu(self: UIList, context: Context) -> None:
if is_pose_asset_view(): if is_pose_asset_view():
layout.operator("asset.open_containing_blend_file") layout.operator("asset.open_containing_blend_file")
props.select = False props.select = False
...@@ -137,6 +133,7 @@ class ASSETBROWSER_MT_asset(Menu): ...@@ -137,6 +133,7 @@ class ASSETBROWSER_MT_asset(Menu):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
from bpy_extras.asset_utils import SpaceAssetInfo from bpy_extras.asset_utils import SpaceAssetInfo
return SpaceAssetInfo.is_asset_browser_poll(context) return SpaceAssetInfo.is_asset_browser_poll(context)
def draw(self, context: Context) -> None: def draw(self, context: Context) -> None:
...@@ -150,6 +147,7 @@ class ASSETBROWSER_MT_asset(Menu): ...@@ -150,6 +147,7 @@ class ASSETBROWSER_MT_asset(Menu):
### Messagebus subscription to monitor asset library changes. ### Messagebus subscription to monitor asset library changes.
_msgbus_owner = object() _msgbus_owner = object()
def _on_asset_library_changed() -> None: def _on_asset_library_changed() -> None:
"""Update areas when a different asset library is selected.""" """Update areas when a different asset library is selected."""
refresh_area_types = {'DOPESHEET_EDITOR', 'VIEW_3D'} refresh_area_types = {'DOPESHEET_EDITOR', 'VIEW_3D'}
...@@ -160,6 +158,7 @@ def _on_asset_library_changed() -> None: ...@@ -160,6 +158,7 @@ def _on_asset_library_changed() -> None:
area.tag_redraw() area.tag_redraw()
def register_message_bus() -> None: def register_message_bus() -> None:
bpy.msgbus.subscribe_rna( bpy.msgbus.subscribe_rna(
key=(bpy.types.FileAssetSelectParams, "asset_library_ref"), key=(bpy.types.FileAssetSelectParams, "asset_library_ref"),
...@@ -169,14 +168,17 @@ def register_message_bus() -> None: ...@@ -169,14 +168,17 @@ def register_message_bus() -> None:
options={'PERSISTENT'}, options={'PERSISTENT'},
) )
def unregister_message_bus() -> None: def unregister_message_bus() -> None:
bpy.msgbus.clear_by_owner(_msgbus_owner) bpy.msgbus.clear_by_owner(_msgbus_owner)
@bpy.app.handlers.persistent @bpy.app.handlers.persistent
def _on_blendfile_load_pre(none, other_none) -> None: def _on_blendfile_load_pre(none, other_none) -> None:
# The parameters are required, but both are None. # The parameters are required, but both are None.
unregister_message_bus() unregister_message_bus()
@bpy.app.handlers.persistent @bpy.app.handlers.persistent
def _on_blendfile_load_post(none, other_none) -> None: def _on_blendfile_load_post(none, other_none) -> None:
# The parameters are required, but both are None. # The parameters are required, but both are None.
...@@ -198,7 +200,7 @@ def register() -> None: ...@@ -198,7 +200,7 @@ def register() -> None:
WorkSpace.active_pose_asset_index = bpy.props.IntProperty( WorkSpace.active_pose_asset_index = bpy.props.IntProperty(
name="Active Pose Asset", name="Active Pose Asset",
# TODO explain which list the index belongs to, or how it can be used to get the pose. # TODO explain which list the index belongs to, or how it can be used to get the pose.
description="Per workspace index of the active pose asset" description="Per workspace index of the active pose asset",
) )
# Register for window-manager. This is a global property that shouldn't be # Register for window-manager. This is a global property that shouldn't be
# written to files. # written to files.
......
...@@ -53,7 +53,7 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator): ...@@ -53,7 +53,7 @@ class POSELIB_OT_create_pose_asset(PoseAssetCreator, Operator):
"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" "The asset will be stored in the current blend file"
) )
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
pose_name: StringProperty(name="Pose Name") # type: ignore pose_name: StringProperty(name="Pose Name") # type: ignore
activate_new_action: BoolProperty(name="Activate New Action", default=True) # type: ignore activate_new_action: BoolProperty(name="Activate New Action", default=True) # type: ignore
...@@ -143,7 +143,7 @@ class POSELIB_OT_restore_previous_action(Operator): ...@@ -143,7 +143,7 @@ class POSELIB_OT_restore_previous_action(Operator):
bl_idname = "poselib.restore_previous_action" bl_idname = "poselib.restore_previous_action"
bl_label = "Restore Previous Action" bl_label = "Restore Previous Action"
bl_description = "Switch back to the previous Action, after creating a pose asset" bl_description = "Switch back to the previous Action, after creating a pose asset"
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
...@@ -187,14 +187,11 @@ class ASSET_OT_assign_action(Operator): ...@@ -187,14 +187,11 @@ class ASSET_OT_assign_action(Operator):
bl_idname = "asset.assign_action" bl_idname = "asset.assign_action"
bl_label = "Assign Action" bl_label = "Assign Action"
bl_description = "Set this pose Action as active Action on the active Object" bl_description = "Set this pose Action as active Action on the active Object"
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
return bool( return bool(isinstance(getattr(context, "id", None), Action) and context.object)
isinstance(getattr(context, "id", None), Action)
and context.object
)
def execute(self, context: Context) -> Set[str]: def execute(self, context: Context) -> Set[str]:
context.object.animation_data_create().action = context.id context.object.animation_data_create().action = context.id
...@@ -205,14 +202,12 @@ class POSELIB_OT_copy_as_asset(PoseAssetCreator, Operator): ...@@ -205,14 +202,12 @@ class POSELIB_OT_copy_as_asset(PoseAssetCreator, Operator):
bl_idname = "poselib.copy_as_asset" bl_idname = "poselib.copy_as_asset"
bl_label = "Copy Pose as Asset" bl_label = "Copy Pose as Asset"
bl_description = "Create a new pose asset on the clipboard, to be pasted into an Asset Browser" bl_description = "Create a new pose asset on the clipboard, to be pasted into an Asset Browser"
bl_options = {"REGISTER"} bl_options = {'REGISTER'}
CLIPBOARD_ASSET_MARKER = "ASSET-BLEND=" CLIPBOARD_ASSET_MARKER = "ASSET-BLEND="
def execute(self, context: Context) -> Set[str]: def execute(self, context: Context) -> Set[str]:
asset = pose_creation.create_pose_asset_from_context( asset = pose_creation.create_pose_asset_from_context(context, new_asset_name=context.object.name)
context, new_asset_name=context.object.name
)
if asset is None: if asset is None:
self.report({"WARNING"}, "No animation data found to create asset from") self.report({"WARNING"}, "No animation data found to create asset from")
return {"CANCELLED"} return {"CANCELLED"}
...@@ -257,7 +252,7 @@ class POSELIB_OT_paste_asset(Operator): ...@@ -257,7 +252,7 @@ class POSELIB_OT_paste_asset(Operator):
bl_idname = "poselib.paste_asset" bl_idname = "poselib.paste_asset"
bl_label = "Paste as New Asset" bl_label = "Paste as New Asset"
bl_description = "Paste the Asset that was previously copied using Copy As Asset" bl_description = "Paste the Asset that was previously copied using Copy As Asset"
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
...@@ -362,7 +357,7 @@ class POSELIB_OT_pose_asset_select_bones(PoseAssetUser, Operator): ...@@ -362,7 +357,7 @@ class POSELIB_OT_pose_asset_select_bones(PoseAssetUser, Operator):
bl_idname = "poselib.pose_asset_select_bones" bl_idname = "poselib.pose_asset_select_bones"
bl_label = "Select Bones" bl_label = "Select Bones"
bl_description = "Select those bones that are used in this pose" bl_description = "Select those bones that are used in this pose"
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
select: BoolProperty(name="Select", default=True) # type: ignore select: BoolProperty(name="Select", default=True) # type: ignore
flipped: BoolProperty(name="Flipped", default=False) # type: ignore flipped: BoolProperty(name="Flipped", default=False) # type: ignore
...@@ -378,9 +373,7 @@ class POSELIB_OT_pose_asset_select_bones(PoseAssetUser, Operator): ...@@ -378,9 +373,7 @@ class POSELIB_OT_pose_asset_select_bones(PoseAssetUser, Operator):
return {"FINISHED"} return {"FINISHED"}
@classmethod @classmethod
def description( def description(cls, _context: Context, properties: 'POSELIB_OT_pose_asset_select_bones') -> str:
cls, _context: Context, properties: 'POSELIB_OT_pose_asset_select_bones'
) -> str:
if properties.select: if properties.select:
return cls.bl_description return cls.bl_description
return cls.bl_description.replace("Select", "Deselect") return cls.bl_description.replace("Select", "Deselect")
...@@ -390,7 +383,7 @@ class POSELIB_OT_convert_old_poselib(Operator): ...@@ -390,7 +383,7 @@ class POSELIB_OT_convert_old_poselib(Operator):
bl_idname = "poselib.convert_old_poselib" bl_idname = "poselib.convert_old_poselib"
bl_label = "Convert Legacy Pose Library" bl_label = "Convert Legacy Pose Library"
bl_description = "Create a pose asset for each pose marker in the current action" bl_description = "Create a pose asset for each pose marker in the current action"
bl_options = {"REGISTER", "UNDO"} bl_options = {'REGISTER', 'UNDO'}
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
...@@ -424,7 +417,7 @@ class POSELIB_OT_convert_old_object_poselib(Operator): ...@@ -424,7 +417,7 @@ class POSELIB_OT_convert_old_object_poselib(Operator):
# Mark this one as "internal", as it converts `context.object.pose_library` # Mark this one as "internal", as it converts `context.object.pose_library`
# instead of its current animation Action. # instead of its current animation Action.
bl_options = {"REGISTER", "UNDO", "INTERNAL"} bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
@classmethod @classmethod
def poll(cls, context: Context) -> bool: def poll(cls, context: Context) -> bool:
......
...@@ -139,9 +139,7 @@ class PoseActionCreator: ...@@ -139,9 +139,7 @@ class PoseActionCreator:
# A once-animated property no longer exists. # A once-animated property no longer exists.
continue continue
dst_fcurve = dst_action.fcurves.new( dst_fcurve = dst_action.fcurves.new(fcurve.data_path, index=fcurve.array_index, action_group=bone_name)
fcurve.data_path, index=fcurve.array_index, action_group=bone_name
)
dst_fcurve.keyframe_points.insert(self.params.src_frame_nr, value=value) dst_fcurve.keyframe_points.insert(self.params.src_frame_nr, value=value)
dst_fcurve.update() dst_fcurve.update()
...@@ -171,9 +169,7 @@ class PoseActionCreator: ...@@ -171,9 +169,7 @@ class PoseActionCreator:
else: else:
self._store_bone_property(dst_action, bone_name, prop_name) self._store_bone_property(dst_action, bone_name, prop_name)
def _store_bone_array( def _store_bone_array(self, dst_action: Action, bone_name: str, property_name: str, array_length: int) -> None:
self, dst_action: Action, bone_name: str, property_name: str, array_length: int
) -> None:
"""Store all elements of an array property.""" """Store all elements of an array property."""
for array_index in range(array_length): for array_index in range(array_length):
self._store_bone_property(dst_action, bone_name, property_name, array_index) self._store_bone_property(dst_action, bone_name, property_name, array_index)
...@@ -201,9 +197,7 @@ class PoseActionCreator: ...@@ -201,9 +197,7 @@ class PoseActionCreator:
fcurve.update() fcurve.update()
@classmethod @classmethod
def _current_value( def _current_value(cls, datablock: bpy.types.ID, data_path: str, array_index: int) -> FCurveValue:
cls, datablock: bpy.types.ID, data_path: str, array_index: int
) -> FCurveValue:
"""Resolve an RNA path + array index to an actual value.""" """Resolve an RNA path + array index to an actual value."""
value_or_array = cls._path_resolve(datablock, data_path) value_or_array = cls._path_resolve(datablock, data_path)
...@@ -227,9 +221,7 @@ class PoseActionCreator: ...@@ -227,9 +221,7 @@ class PoseActionCreator:
return cast(FCurveValue, value_or_array[array_index]) # type: ignore return cast(FCurveValue, value_or_array[array_index]) # type: ignore
@staticmethod @staticmethod
def _path_resolve( def _path_resolve(datablock: bpy.types.ID, data_path: str) -> Union[FCurveValue, Iterable[FCurveValue]]:
datablock: bpy.types.ID, data_path: str
) -> Union[FCurveValue, Iterable[FCurveValue]]:
"""Wrapper for datablock.path_resolve(data_path). """Wrapper for datablock.path_resolve(data_path).
Raise UnresolvablePathError when the path cannot be resolved. Raise UnresolvablePathError when the path cannot be resolved.
...@@ -338,9 +330,7 @@ def copy_fcurves( ...@@ -338,9 +330,7 @@ def copy_fcurves(
return num_fcurves_copied return num_fcurves_copied
def create_single_key_fcurve( def create_single_key_fcurve(dst_action: Action, src_fcurve: FCurve, src_keyframe: Keyframe) -> FCurve:
dst_action: Action, src_fcurve: FCurve, src_keyframe: Keyframe
) -> FCurve:
"""Create a copy of the source FCurve, but only for the given keyframe. """Create a copy of the source FCurve, but only for the given keyframe.
Returns a new FCurve with just one keyframe. Returns a new FCurve with just one keyframe.
...@@ -355,9 +345,7 @@ def copy_fcurve_without_keys(dst_action: Action, src_fcurve: FCurve) -> FCurve: ...@@ -355,9 +345,7 @@ def copy_fcurve_without_keys(dst_action: Action, src_fcurve: FCurve) -> FCurve:
"""Create a new FCurve and copy some properties.""" """Create a new FCurve and copy some properties."""
src_group_name = src_fcurve.group.name if src_fcurve.group else "" src_group_name = src_fcurve.group.name if src_fcurve.group else ""
dst_fcurve = dst_action.fcurves.new( dst_fcurve = dst_action.fcurves.new(src_fcurve.data_path, index=src_fcurve.array_index, action_group=src_group_name)
src_fcurve.data_path, index=src_fcurve.array_index, action_group=src_group_name
)
for propname in {"auto_smoothing", "color", "color_mode", "extrapolation"}: for propname in {"auto_smoothing", "color", "color_mode", "extrapolation"}:
setattr(dst_fcurve, propname, getattr(src_fcurve, propname)) setattr(dst_fcurve, propname, getattr(src_fcurve, propname))
return dst_fcurve return dst_fcurve
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment