blender/scripts/modules/bpy_restrict_state.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
996 B
Python
Raw Normal View History

# SPDX-FileCopyrightText: 2009-2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""
This module contains RestrictBlend context manager.
"""
__all__ = (
"RestrictBlend",
2016-07-29 21:22:27 +10:00
)
import bpy as _bpy
2013-01-15 23:15:32 +00:00
class _RestrictContext:
__slots__ = ()
_real_data = _bpy.data
# safe, the pointer never changes
_real_pref = _bpy.context.preferences
2013-01-15 23:15:32 +00:00
@property
def window_manager(self):
return self._real_data.window_managers[0]
2013-01-15 23:15:32 +00:00
@property
def preferences(self):
return self._real_pref
class _RestrictData:
__slots__ = ()
_context_restrict = _RestrictContext()
_data_restrict = _RestrictData()
class RestrictBlend:
__slots__ = ("context", "data")
2013-01-15 23:15:32 +00:00
def __enter__(self):
self.data = _bpy.data
self.context = _bpy.context
_bpy.data = _data_restrict
_bpy.context = _context_restrict
2024-12-11 11:26:24 +11:00
def __exit__(self, _type, _value, _traceback):
_bpy.data = self.data
_bpy.context = self.context