diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-11 02:48:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-11 02:48:22 +0300 |
commit | 4612034cf45f2534b01bb038f80b7795e8b8e20d (patch) | |
tree | ba47ff0cb8d4916faa8fb2ff06dbf08883fae9b3 /release/scripts/modules/bpy_types.py | |
parent | 46bb5643b7660033bc0d15c5fcc752324a1b519f (diff) |
patch [#25809] Auto-Registration as utility function.
This removes auto-registration, committed by Martin r30961.
Realize this is a contentious topic but Brecht and myself both would rather opt-in registration.
TODO:
- addons need updating.
- class list will be modified to use weakrefs (should have been done for existing system too).
- will move bpy.types.(un)register functions into bpy.utils.(un)register_class, currently including these functions in a type list is internally ugly, scripts which loop over types also need to check for these.
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 74 |
1 files changed, 11 insertions, 63 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 1cb30765bf0..43bd3f4ff26 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -550,85 +550,33 @@ class Text(bpy_types.ID): import bpy return tuple(obj for obj in bpy.data.objects if self in [cont.text for cont in obj.game.controllers if cont.type == 'PYTHON']) -import collections - +# values are module: [(cls, path, line), ...] TypeMap = {} -# Properties (IDPropertyGroup) are different from types because they need to be registered -# before adding sub properties to them, so they are registered on definition -# and unregistered on unload -PropertiesMap = {} - -# Using our own loading function we set this to false -# so when running a script directly in the text editor -# registers moduals instantly. -_register_immediate = True - - -def _unregister_module(module, free=True): - for t in TypeMap.get(module, ()): - try: - bpy_types.unregister(t) - except: - import traceback - print("bpy.utils._unregister_module(): Module '%s' failed to unregister class '%s.%s'" % (module, t.__module__, t.__name__)) - traceback.print_exc() - - if free == True and module in TypeMap: - del TypeMap[module] - - for t in PropertiesMap.get(module, ()): - try: - bpy_types.unregister(t) - except: - import traceback - print("bpy.utils._unload_module(): Module '%s' failed to unregister class '%s.%s'" % (module, t.__module__, t.__name__)) - traceback.print_exc() - - if free == True and module in PropertiesMap: - del PropertiesMap[module] - - -def _register_module(module): - for t in TypeMap.get(module, ()): - try: - bpy_types.register(t) - except: - import traceback - import sys - print("bpy.utils._register_module(): '%s' failed to register class '%s.%s'" % (sys.modules[module].__file__, t.__module__, t.__name__)) - traceback.print_exc() class RNAMeta(type): - @classmethod - def _register_immediate(cls): - return _register_immediate - def __new__(cls, name, bases, classdict, **args): + import traceback result = type.__new__(cls, name, bases, classdict) if bases and bases[0] != StructRNA: module = result.__module__ - ClassMap = TypeMap - - # Register right away if needed - if cls._register_immediate(): - bpy_types.register(result) - ClassMap = PropertiesMap - # first part of packages only if "." in module: module = module[:module.index(".")] - ClassMap.setdefault(module, []).append(result) + sf = traceback.extract_stack(limit=2)[0] + + TypeMap.setdefault(module, []).append((result, sf[0], sf[1])) return result -class RNAMetaRegister(RNAMeta, StructMetaIDProp): - @classmethod - def _register_immediate(cls): - return True +import collections + + +class RNAMetaIDProp(RNAMeta, StructMetaIDProp): + pass class OrderedMeta(RNAMeta): @@ -685,7 +633,7 @@ class Macro(StructRNA, metaclass=OrderedMeta): return ops.macro_define(self, opname) -class IDPropertyGroup(StructRNA, metaclass=RNAMetaRegister): +class IDPropertyGroup(StructRNA, metaclass=RNAMetaIDProp): __slots__ = () |