[Bf-extensions-cvs] [4a278c28] master: Hide Pose Library panels unless in Pose Mode

Julian Eisel noreply at git.blender.org
Wed Sep 29 17:17:31 CEST 2021


Commit: 4a278c282fe6d85f0ceea3f3b94592e595b0b189
Author: Julian Eisel
Date:   Mon Sep 20 21:49:56 2021 +0200
Branches: master
https://developer.blender.org/rBA4a278c282fe6d85f0ceea3f3b94592e595b0b189

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

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

M	pose_library/gui.py

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

diff --git a/pose_library/gui.py b/pose_library/gui.py
index a2f04a22..2082dff7 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)



More information about the Bf-extensions-cvs mailing list