From a2d6e822841819cc937eb57c1fb0049ec0c9b04b Mon Sep 17 00:00:00 2001 From: Luca Bonavita Date: Tue, 4 Jan 2011 18:38:03 +0000 Subject: == Blender 2.56a tags == Tagging for 2.56a in tags/ and in branches/ [[Split portion of a mixed commit.]] --- modules/extensions_framework/plugin.py | 94 ++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 modules/extensions_framework/plugin.py (limited to 'modules/extensions_framework/plugin.py') diff --git a/modules/extensions_framework/plugin.py b/modules/extensions_framework/plugin.py new file mode 100644 index 00000000..76f41930 --- /dev/null +++ b/modules/extensions_framework/plugin.py @@ -0,0 +1,94 @@ +# -*- coding: utf8 -*- +# +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# -------------------------------------------------------------------------- +# Blender 2.5 Extensions Framework +# -------------------------------------------------------------------------- +# +# Authors: +# Doug Hammond +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# ***** END GPL LICENCE BLOCK ***** +# +import bpy + +from extensions_framework import init_properties +from extensions_framework import log + +class plugin(object): + """Base class for plugins which wish to make use of utilities + provided in extensions_framework. Using the property_groups + attribute and the install() and uninstall() methods, a large number + of custom scene properties can be easily defined, displayed and + managed. + + TODO: Rename, 'extension' would be more appropriate than 'plugin' + + """ + + """The property_groups defines a list of declarative_property_group + types to create in specified types during the initialisation of the + plugin. + Item format: + ('bpy.type prototype to attach to', ) + + Example item: + ('Scene', myaddon_property_group) + In this example, a new property group will be attached to + bpy.types.Scene and all of the properties described in that group + will be added to it. + See extensions_framework.declarative_property_group. + + """ + property_groups = [] + + @classmethod + def install(r_class): + """Initialise this plugin. So far, all this does is to create + custom property groups specified in the property_groups + attribute. + + """ + for property_group_parent, property_group in r_class.property_groups: + call_init = False + if property_group_parent is not None: + prototype = getattr(bpy.types, property_group_parent) + if not hasattr(prototype, property_group.__name__): + init_properties(prototype, [{ + 'type': 'pointer', + 'attr': property_group.__name__, + 'ptype': property_group, + 'name': property_group.__name__, + 'description': property_group.__name__ + }]) + call_init = True + else: + call_init = True + + if call_init: + init_properties(property_group, property_group.properties) + + log('Extension "%s" initialised' % r_class.bl_label) + + @classmethod + def uninstall(r_class): + """Unregister property groups in reverse order""" + reverse_property_groups = [p for p in r_class.property_groups] + reverse_property_groups.reverse() + for property_group_parent, property_group in reverse_property_groups: + prototype = getattr(bpy.types, property_group_parent) + prototype.RemoveProperty(property_group.__name__) -- cgit v1.2.3