diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-02 08:20:41 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-02 08:20:41 +0400 |
commit | 55e64f0ba4f43535a163090ddf6a1715de0a6fa4 (patch) | |
tree | f278c6f30429c9cd41ed554ca11ead5dc0ccc86c /release/scripts | |
parent | 3d81ee3e4aaa5f146c5fb36cef8ad3ec5a81100f (diff) |
minor changes to Martni's commit 30961
- removed the immediate option from C/api and now store in python only, when python loads modules it sets it to False.
- unloading a module would clear the entire TypeMap for all modules, only remove the module types that is being unloaded.
- added some checks for bad class registering, report errors rather then crashing.
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 5 | ||||
-rw-r--r-- | release/scripts/modules/bpy_types.py | 42 |
2 files changed, 27 insertions, 20 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index f09c5872ab1..afdaf0fcdf8 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -102,6 +102,9 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): import traceback import time + # must be set back to True on exits + _bpy_types._register_immediate = False + t_main = time.time() loaded_modules = set() @@ -217,6 +220,8 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): if _bpy.app.debug: print("Python Script Load Time %.4f" % (time.time() - t_main)) + + _bpy_types._register_immediate = True def expandpath(path): diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 7e7b7f128ab..a5161768bea 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -546,20 +546,24 @@ TypeMap = {} # 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 UnloadModule(module): - global TypeMap, PropertiesMap - for t in TypeMap.get(module, []): + for t in TypeMap.setdefault(module, ()): bpy_types.unregister(t) - TypeMap = {} + del TypeMap[module] - for t in PropertiesMap.get(module, []): + for t in PropertiesMap.setdefault(module, ()): bpy_types.unregister(t) - PropertiesMap = {} - + del PropertiesMap[module] + def LoadModule(module, force=False): - for t in TypeMap.get(module, []): + for t in TypeMap.get(module, ()): bpy_types.register(t) _bpy.LoadModule = LoadModule @@ -567,35 +571,33 @@ _bpy.UnloadModule = UnloadModule class RNAMeta(type): @classmethod - def _immediate(cls): - return bpy_types.immediate(); - + def _register_immediate(cls): + return _register_immediate + def __new__(cls, name, bases, classdict, **args): 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._immediate(): + if cls._register_immediate(): bpy_types.register(result) ClassMap = PropertiesMap # first part of packages only if "." in module: module = module[:module.index(".")] - - if not module in ClassMap: - ClassMap[module] = [] - - ClassMap[module].append(result) + + ClassMap.setdefault(module, []).append(result) + return result class RNAMetaRegister(RNAMeta): @classmethod - def _immediate(cls): - return True; + def _register_immediate(cls): + return True class OrderedMeta(RNAMeta): |