[Bf-blender-cvs] [5aa40144cb] app-templates: Example of selectively removing parts of the interface

Campbell Barton noreply at git.blender.org
Thu Mar 16 01:50:08 CET 2017


Commit: 5aa40144cb34e50ae02fec9c966912a40fac5e59
Author: Campbell Barton
Date:   Thu Mar 16 11:54:49 2017 +1100
Branches: app-templates
https://developer.blender.org/rB5aa40144cb34e50ae02fec9c966912a40fac5e59

Example of selectively removing parts of the interface

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

M	release/app_templates/101/template/__init__.py
M	release/scripts/modules/bl_app_override.py

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

diff --git a/release/app_templates/101/template/__init__.py b/release/app_templates/101/template/__init__.py
index fd606832ac..4cc4fed172 100644
--- a/release/app_templates/101/template/__init__.py
+++ b/release/app_templates/101/template/__init__.py
@@ -28,7 +28,13 @@ def register():
 
     class_store.clear()
 
-    class_store.extend(bl_app_override.class_match.panel())
+    class_store.extend(
+        bl_app_override.class_filter(
+            bpy.types.Panel,
+            bl_region_type={'TOOLS', 'WINDOW'},
+            bl_space_type={'VIEW_3D', 'PROPERTIES'}
+        ),
+    )
     unregister = bpy.utils.unregister_class
     for cls in class_store:
         unregister(cls)
diff --git a/release/scripts/modules/bl_app_override.py b/release/scripts/modules/bl_app_override.py
index 837f3542e6..aa1ad9e50d 100644
--- a/release/scripts/modules/bl_app_override.py
+++ b/release/scripts/modules/bl_app_override.py
@@ -25,24 +25,12 @@ Module to manage overriding various parts of Blender.
 Intended for use with 'app_templates', though it can be used from anywhere.
 """
 
-class class_match:
-    # TODO, how to check these aren't from add-ons,
-    # templates might need to un-register while filtering.
 
-    @staticmethod
-    def _rna_subclasses(cls_parent):
-        for cls in cls_parent.__subclasses__():
+# TODO, how to check these aren't from add-ons.
+# templates might need to un-register while filtering.
+def class_filter(cls_parent, **kw):
+    kw_items = tuple(kw.items())
+    for cls in cls_parent.__subclasses__():
+        if all((getattr(cls, attr) in expect) for attr, expect in kw_items):
             yield cls
 
-    @staticmethod
-    def panel(*, bl_category=None, bl_space_type=None, bl_region_type=None):
-        # None or set
-        import bpy
-        for cls in class_match._rna_subclasses(bpy.types.Panel):
-            if bl_category is not None and cls.bl_category not in bl_category:
-                continue
-            if bl_space_type is not None and cls.bl_space_type not in bl_space_type:
-                continue
-            if bl_region_type is not None and cls.bl_region_type not in bl_region_type:
-                continue
-            yield cls




More information about the Bf-blender-cvs mailing list