Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hammond <doughammond@hamsterfight.co.uk>2011-02-11 13:11:06 +0300
committerDoug Hammond <doughammond@hamsterfight.co.uk>2011-02-11 13:11:06 +0300
commit914ac4194f3070cc12338e533b6e29610faeb3aa (patch)
treeb4af0757398c3f81da5a13090f66c04ab2d6cac2 /modules
parentf1622cc32d508022a2252cfa11b55354366f5069 (diff)
extensions_framework: added ef_remove_properties function as a complement to ef_initialise_properties
Diffstat (limited to 'modules')
-rw-r--r--modules/extensions_framework/__init__.py56
1 files changed, 42 insertions, 14 deletions
diff --git a/modules/extensions_framework/__init__.py b/modules/extensions_framework/__init__.py
index 8e7ee390..4581046b 100644
--- a/modules/extensions_framework/__init__.py
+++ b/modules/extensions_framework/__init__.py
@@ -116,26 +116,28 @@ def init_properties(obj, props, cache=True):
continue
def ef_initialise_properties(cls):
- """This is a class decorator that should be used on
+ """This is a function that should be called 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)
+ if not cls.ef_initialised:
+ 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)
+ cls.ef_initialised = True
return cls
@@ -150,6 +152,30 @@ def ef_register_initialise_properties(cls):
ef_initialise_properties(cls)
return cls
+def ef_remove_properties(cls):
+ """This is a function that should be called on
+ sub-classes of declarative_property_group in order
+ to ensure that they are un-initialised when the addon
+ is unloaded.
+
+ """
+
+ if cls.ef_initialised:
+ for prop in cls.properties:
+ if hasattr(cls, prop['attr']):
+ delattr(cls, prop['attr'])
+ added_property_cache[cls] = []
+
+ for property_group_parent in cls.ef_attach_to:
+ if property_group_parent is not None:
+ prototype = getattr(bpy.types, property_group_parent)
+ if hasattr(prototype, cls.__name__):
+ delattr(prototype, cls.__name__)
+
+ cls.ef_initialised = False
+
+ return cls
+
class declarative_property_group(bpy.types.IDPropertyGroup):
"""A declarative_property_group describes a set of logically
related properties, using a declarative style to list each
@@ -169,6 +195,8 @@ class declarative_property_group(bpy.types.IDPropertyGroup):
"""
+ ef_initialised = False
+
"""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