[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1580] trunk/py/scripts/addons/modules/ extensions_framework/__init__.py: extensions_framework: added ef_remove_properties function as a complement to ef_initialise_properties
Doug Hammond
doughammond at hamsterfight.co.uk
Fri Feb 11 11:11:07 CET 2011
Revision: 1580
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1580
Author: dougal2
Date: 2011-02-11 10:11:06 +0000 (Fri, 11 Feb 2011)
Log Message:
-----------
extensions_framework: added ef_remove_properties function as a complement to ef_initialise_properties
Modified Paths:
--------------
trunk/py/scripts/addons/modules/extensions_framework/__init__.py
Modified: trunk/py/scripts/addons/modules/extensions_framework/__init__.py
===================================================================
--- trunk/py/scripts/addons/modules/extensions_framework/__init__.py 2011-02-11 09:29:54 UTC (rev 1579)
+++ trunk/py/scripts/addons/modules/extensions_framework/__init__.py 2011-02-11 10:11:06 UTC (rev 1580)
@@ -116,27 +116,29 @@
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__
- }])
+ 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
- init_properties(cls, cls.properties)
-
return cls
def ef_register_initialise_properties(cls):
@@ -150,6 +152,30 @@
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 @@
"""
+ 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
More information about the Bf-extensions-cvs
mailing list