From 4a278c282fe6d85f0ceea3f3b94592e595b0b189 Mon Sep 17 00:00:00 2001 From: Julian Eisel <julian@blender.org> Date: Mon, 20 Sep 2021 21:49:56 +0200 Subject: [PATCH] Hide Pose Library panels unless in Pose Mode Otherwise, there will be a useless tab in the sidebar, and panels in the Asset Browser and Dopesheet that do nothing. So far the Asset Browser hides these panels unless the Animation category is selected, but this won't work once asset catalogs replace the categories. Differential Revision: https://developer.blender.org/D12576 --- pose_library/gui.py | 53 ++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/pose_library/gui.py b/pose_library/gui.py index a2f04a227..2082dff7d 100644 --- a/pose_library/gui.py +++ b/pose_library/gui.py @@ -33,21 +33,25 @@ from bpy.types import ( from bpy_extras import asset_utils -class VIEW3D_PT_pose_library(Panel): +class PoseLibraryPanel: + @classmethod + def pose_library_panel_poll(cls, context: Context) -> bool: + return bool( + context.object + and context.object.mode == 'POSE' + ) + + @classmethod + def poll(cls, context: Context) -> bool: + return cls.pose_library_panel_poll(context); + + +class VIEW3D_PT_pose_library(PoseLibraryPanel, Panel): bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "Animation" bl_label = "Pose Library" - @classmethod - def poll(cls, context: Context) -> bool: - exp_prefs = context.preferences.experimental - try: - return exp_prefs.use_asset_browser - except AttributeError: - # The 'use_asset_browser' experimental option was removed from Blender. - return True - def draw(self, context: Context) -> None: layout = self.layout @@ -124,11 +128,18 @@ def pose_library_list_item_context_menu(self: UIList, context: Context) -> None: layout.operator("asset.open_containing_blend_file") -class ASSETBROWSER_PT_pose_library_usage(asset_utils.AssetBrowserSpecificCategoryPanel, Panel): +class ASSETBROWSER_PT_pose_library_usage(PoseLibraryPanel, asset_utils.AssetBrowserSpecificCategoryPanel, Panel): bl_region_type = "TOOLS" bl_label = "Pose Library" asset_categories = {'ANIMATIONS'} + @classmethod + def poll(cls, context: Context) -> bool: + return ( + cls.pose_library_panel_poll(context) + and cls.asset_category_poll(context) + ) + def draw(self, context: Context) -> None: layout = self.layout wm = context.window_manager @@ -149,11 +160,18 @@ class ASSETBROWSER_PT_pose_library_usage(asset_utils.AssetBrowserSpecificCategor props.select = False -class ASSETBROWSER_PT_pose_library_editing(asset_utils.AssetBrowserSpecificCategoryPanel, Panel): +class ASSETBROWSER_PT_pose_library_editing(PoseLibraryPanel, asset_utils.AssetBrowserSpecificCategoryPanel, Panel): bl_region_type = "TOOL_PROPS" bl_label = "Pose Library" asset_categories = {'ANIMATIONS'} + @classmethod + def poll(cls, context: Context) -> bool: + return ( + cls.pose_library_panel_poll(context) + and cls.asset_category_poll(context) + ) + def draw(self, context: Context) -> None: layout = self.layout @@ -169,21 +187,12 @@ class ASSETBROWSER_PT_pose_library_editing(asset_utils.AssetBrowserSpecificCateg col.operator("poselib.paste_asset", icon="PASTEDOWN") -class DOPESHEET_PT_asset_panel(Panel): +class DOPESHEET_PT_asset_panel(PoseLibraryPanel, Panel): bl_space_type = "DOPESHEET_EDITOR" bl_region_type = "UI" bl_label = "Create Pose Asset" bl_category = "Pose Library" - @classmethod - def poll(cls, context: Context) -> bool: - exp_prefs = context.preferences.experimental - try: - return exp_prefs.use_asset_browser - except AttributeError: - # The 'use_asset_browser' experimental option was removed from Blender. - return True - def draw(self, context: Context) -> None: layout = self.layout col = layout.column(align=True) -- GitLab