[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1567] trunk/py/scripts/addons/modules/ extensions_framework: extensions_framework: added ef_initialise_properties class decorator to initialise declarative_property_groups at declaration time instead of requiring a potentially huge class list in the addon __init__ file
Doug Hammond
doughammond at hamsterfight.co.uk
Fri Feb 11 00:13:59 CET 2011
Revision: 1567
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1567
Author: dougal2
Date: 2011-02-10 23:13:59 +0000 (Thu, 10 Feb 2011)
Log Message:
-----------
extensions_framework: added ef_initialise_properties class decorator to initialise declarative_property_groups at declaration time instead of requiring a potentially huge class list in the addon __init__ file
Modified Paths:
--------------
trunk/py/scripts/addons/modules/extensions_framework/__init__.py
trunk/py/scripts/addons/modules/extensions_framework/plugin.py
Modified: trunk/py/scripts/addons/modules/extensions_framework/__init__.py
===================================================================
--- trunk/py/scripts/addons/modules/extensions_framework/__init__.py 2011-02-10 00:10:20 UTC (rev 1566)
+++ trunk/py/scripts/addons/modules/extensions_framework/__init__.py 2011-02-10 23:13:59 UTC (rev 1567)
@@ -115,6 +115,30 @@
# Silently skip invalid entries in props
continue
+def ef_initialise_properties(cls):
+ """This is mostly copied from plugin.plugin.install
+ This is a class decorator that should be used on
+ sub-classes of declarative_property_group in order
+ to ensure that they are initialised when the addon
+ is loaded.
+
+ """
+
+ for property_group_parent in cls.ef_attach_to:
+ if property_group_parent is not None:
+ prototype = getattr(bpy.types, property_group_parent)
+ if not hasattr(prototype, cls.__name__):
+ init_properties(prototype, [{
+ 'type': 'pointer',
+ 'attr': cls.__name__,
+ 'ptype': cls,
+ 'name': cls.__name__,
+ 'description': cls.__name__
+ }])
+
+ init_properties(cls, cls.properties)
+
+ return cls
class declarative_property_group(bpy.types.IDPropertyGroup):
"""A declarative_property_group describes a set of logically
@@ -135,6 +159,15 @@
"""
+ """This property tells extensions_framework which bpy.type(s)
+ to attach this IDPropertyGroup to. If left as an empty list,
+ it will not be attached to any type, but its properties will
+ still be initialised. The type(s) given in the list should be
+ a string, such as 'Scene'.
+
+ """
+ ef_attach_to = []
+
"""This list controls the order of property layout when rendered
by a property_group_renderer. This can be a nested list, where each
list becomes a row in the panel layout. Nesting may be to any depth.
Modified: trunk/py/scripts/addons/modules/extensions_framework/plugin.py
===================================================================
--- trunk/py/scripts/addons/modules/extensions_framework/plugin.py 2011-02-10 00:10:20 UTC (rev 1566)
+++ trunk/py/scripts/addons/modules/extensions_framework/plugin.py 2011-02-10 23:13:59 UTC (rev 1567)
@@ -82,7 +82,7 @@
if call_init:
init_properties(property_group, property_group.properties)
- log('Extension "%s" initialised' % r_class.bl_label)
+ log('Extension "%s" initialised' % r_class.__name__)
@classmethod
def uninstall(r_class):
More information about the Bf-extensions-cvs
mailing list