Skip to content
Snippets Groups Projects
Commit 6b5ccf85 authored by Doug Hammond's avatar Doug Hammond
Browse files

extensions_framework: added ef_initialise_properties class decorator to...

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
parent 4d24ac5c
No related branches found
No related tags found
No related merge requests found
...@@ -115,6 +115,30 @@ def init_properties(obj, props, cache=True): ...@@ -115,6 +115,30 @@ def init_properties(obj, props, cache=True):
# Silently skip invalid entries in props # Silently skip invalid entries in props
continue 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): class declarative_property_group(bpy.types.IDPropertyGroup):
"""A declarative_property_group describes a set of logically """A declarative_property_group describes a set of logically
...@@ -135,6 +159,15 @@ class declarative_property_group(bpy.types.IDPropertyGroup): ...@@ -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 """This list controls the order of property layout when rendered
by a property_group_renderer. This can be a nested list, where each 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. list becomes a row in the panel layout. Nesting may be to any depth.
......
...@@ -82,7 +82,7 @@ class plugin(object): ...@@ -82,7 +82,7 @@ class plugin(object):
if call_init: if call_init:
init_properties(property_group, property_group.properties) init_properties(property_group, property_group.properties)
log('Extension "%s" initialised' % r_class.bl_label) log('Extension "%s" initialised' % r_class.__name__)
@classmethod @classmethod
def uninstall(r_class): def uninstall(r_class):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment