diff options
author | Bastien Montagne <bastien@blender.org> | 2020-05-05 19:04:22 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-05-05 19:08:40 +0300 |
commit | c9ff8b5cd68079d2ea2fa0faf51dd1dd53ab6200 (patch) | |
tree | 6d133bf4bc82d281bb44a684b8d94fb53cb839dd /release/scripts/modules/bl_i18n_utils/settings.py | |
parent | 527c81c6f841c24c11c4d61fe2f36a0e6a01bbe0 (diff) |
Various fixes, cleanup and improvements to i18n module.
* Remove multi-processing in messages class update, was no giving much
speedup if any at all.
* Remove some debug prints.
* Make messages class pickleable.
* Filter better actual setting values from Settings class.
* Make settings pickleable.
All this will allow to use multi-processing in the i18n addon itself.
Diffstat (limited to 'release/scripts/modules/bl_i18n_utils/settings.py')
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/settings.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py index c233681dc41..e522ec3fcf9 100644 --- a/release/scripts/modules/bl_i18n_utils/settings.py +++ b/release/scripts/modules/bl_i18n_utils/settings.py @@ -28,6 +28,7 @@ import json import os import sys +import types import bpy @@ -556,6 +557,10 @@ def _gen_get_set_path(ref, name): return _get, _set +def _check_valid_data(uid, val): + return not uid.startswith("_") and type(val) not in tuple(types.__dict__.values()) + (type,) + + class I18nSettings: """ Class allowing persistence of our settings! @@ -567,20 +572,32 @@ class I18nSettings: # Addon preferences are singleton by definition, so is this class! if not I18nSettings._settings: cls._settings = super(I18nSettings, cls).__new__(cls) - cls._settings.__dict__ = {uid: data for uid, data in globals().items() if not uid.startswith("_")} + cls._settings.__dict__ = {uid: val for uid, val in globals().items() if _check_valid_data(uid, val)} return I18nSettings._settings - def from_json(self, string): - data = dict(json.loads(string)) + def __getstate__(self): + return self.to_dict() + + def __setstate__(self, mapping): + return self.from_dict(mapping) + + def from_dict(self, mapping): # Special case... :/ - if "INTERN_PY_SYS_PATHS" in data: - self.PY_SYS_PATHS = data["INTERN_PY_SYS_PATHS"] - self.__dict__.update(data) + if "INTERN_PY_SYS_PATHS" in mapping: + self.PY_SYS_PATHS = mapping["INTERN_PY_SYS_PATHS"] + self.__dict__.update(mapping) + + def to_dict(self): + glob = globals() + return {uid: val for uid, val in self.__dict__.items() if _check_valid_data(uid, val) and uid in glob} + + def from_json(self, string): + self.from_dict(dict(json.loads(string))) def to_json(self): # Only save the diff from default i18n_settings! glob = globals() - export_dict = {uid: val for uid, val in self.__dict__.items() if glob.get(uid) != val} + export_dict = {uid: val for uid, val in self.__dict__.items() if _check_valid_data(uid, val) and glob.get(uid) != val} return json.dumps(export_dict) def load(self, fname, reset=False): |