Commit: 507156d68d0fbb26170e679daf6236a587dea281 Author: Campbell Barton Date: Wed Mar 22 11:46:07 2017 +1100 Branches: app-templates https://developer.blender.org/rB507156d68d0fbb26170e679daf6236a587dea281
Move AppOverrideState into a helpers submodule =================================================================== M release/datafiles/app_templates/101/template/__init__.py R063 release/scripts/modules/bl_app_override.py release/scripts/modules/bl_app_override/__init__.py =================================================================== diff --git a/release/datafiles/app_templates/101/template/__init__.py b/release/datafiles/app_templates/101/template/__init__.py index 8d511809ed..489255aded 100644 --- a/release/datafiles/app_templates/101/template/__init__.py +++ b/release/datafiles/app_templates/101/template/__init__.py @@ -21,8 +21,10 @@ import bpy import bl_app_override +from bl_app_override.helpers import AppOverrideState -class AppStateStore(bl_app_override.AppOverrideState): + +class AppStateStore(AppOverrideState): # Just provides data & callbacks for AppOverrideState __slots__ = () diff --git a/release/scripts/modules/bl_app_override.py b/release/scripts/modules/bl_app_override/__init__.py similarity index 63% rename from release/scripts/modules/bl_app_override.py rename to release/scripts/modules/bl_app_override/__init__.py index 8c274478f6..50c3bfbd79 100644 --- a/release/scripts/modules/bl_app_override.py +++ b/release/scripts/modules/bl_app_override/__init__.py @@ -200,146 +200,3 @@ def ui_draw_filter_register( def ui_draw_filter_unregister(ui_ignore_store): for (obj, attr, value) in ui_ignore_store: setattr(obj, attr, value) - - -# ----------------------------------------------------------------------------- -# AppOverrideState - -class AppOverrideState: - """ - Base class for creating a state which can be removed, for overriding. - - To instate the overrides call ``setup``, to reverse this call ``teardown``. - - - ``class_ignore()`` a function that returns classes from ``bpy.types`` that are to be unregistered. - - Return True to ignore. - - - ``ui_ignore_operator(id)`` - - ``ui_ignore_property(class_id, prop_id)`` - - ``ui_ignore_menu(id)`` - - ``ui_ignore_label(text)`` - - - ``addon_paths()`` return a sequence of paths which contain addons. - - ``addons()`` return a sequence of addon id's to enable. - """ - # Utility class to encapsulate application state, backup and restore. - __slots__ = ( - # setup_classes - "_class_store", - # setup_ui_ignore - "_ui_ignore_store", - # setup_addons - "_addon_store", - ) - - # setup/teardown classes - class_ignore = None - - # setup/teardown ui_ignore - ui_ignore_operator = None - ui_ignore_property = None - ui_ignore_menu = None - ui_ignore_label = None - - addon_paths = None - addons = None - - def __init__(self): - self._class_store = None - self._addon_store = None - self._ui_ignore_store = None - - def _setup_classes(self): - import bpy - assert(self._class_store is None) - self._class_store = self.class_ignore() - from bpy.utils import unregister_class - for cls in self._class_store: - unregister_class(cls) - - def _teardown_classes(self): - assert(len(self._class_store) != 0) - - from bpy.utils import register_class - for cls in self._class_store: - register_class(cls) - self._class_store = None - - def _setup_ui_ignore(self): - import bl_app_override - - self._ui_ignore_store = bl_app_override.ui_draw_filter_register( - ui_ignore_operator=self.ui_ignore_operator, - ui_ignore_property=self.ui_ignore_property, - ui_ignore_menu=self.ui_ignore_menu, - ui_ignore_label=self.ui_ignore_label, - ) - - def _teardown_ui_ignore(self): - import bl_app_override - bl_app_override.ui_draw_filter_unregister( - self._ui_ignore_store - ) - self._ui_ignore_store = None - - - def _setup_addons(self): - import sys - import os - - sys_path = [] - if self.addon_paths is not None: - for path in self.addon_paths(): - if path not in sys.path: - sys.path.append(path) - - import addon_utils - addons = [] - if self.addons is not None: - addons.extend(self.addons()) - for addon in addons: - addon_utils.enable(addon) - - self._addon_store = { - "sys_path": sys_path, - "addons": addons, - } - - def _teardown_addons(self): - import sys - - sys_path = self._addon_store["sys_path"] - for path in sys_path: - # should always succeed, but if not its no problem - try: - sys.path.remove(path) - except: - pass - - addons = self._addon_store["addons"] - import addon_utils - for addon in addons: - addon_utils.disable(addon) - - self._addon_store.clear() - self._addon_store = None - - def setup(self): - if self.class_ignore is not None: - self._setup_classes() - - self._setup_addons() - - if any((self.ui_ignore_operator, self.ui_ignore_property, self.ui_ignore_menu, self.ui_ignore_label)): - self._setup_ui_ignore() - - def teardown(self): - if self._class_store is not None: - self._teardown_classes() - - if self._addon_store is not None: - self._teardown_addons() - - if self._ui_ignore_store is not None: - self._teardown_ui_ignore() _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs