From 6b5ccf85a107fbce7b63b1875fb645d3d6ed32f5 Mon Sep 17 00:00:00 2001 From: Doug Hammond <doughammond@hamsterfight.co.uk> Date: Thu, 10 Feb 2011 23:13:59 +0000 Subject: [PATCH] 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 --- modules/extensions_framework/__init__.py | 33 ++++++++++++++++++++++++ modules/extensions_framework/plugin.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/extensions_framework/__init__.py b/modules/extensions_framework/__init__.py index 08bd57e7e..f842f5aef 100644 --- a/modules/extensions_framework/__init__.py +++ b/modules/extensions_framework/__init__.py @@ -115,6 +115,30 @@ def init_properties(obj, props, cache=True): # 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 @@ class declarative_property_group(bpy.types.IDPropertyGroup): """ + """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. diff --git a/modules/extensions_framework/plugin.py b/modules/extensions_framework/plugin.py index 27b458717..a548a84fc 100644 --- a/modules/extensions_framework/plugin.py +++ b/modules/extensions_framework/plugin.py @@ -82,7 +82,7 @@ class plugin(object): 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): -- GitLab