2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2009-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2012-12-20 03:56:22 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
This module contains RestrictBlend context manager.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
"RestrictBlend",
|
2016-07-29 21:22:27 +10:00
|
|
|
)
|
2012-12-20 03:56:22 +00:00
|
|
|
|
|
|
|
import bpy as _bpy
|
|
|
|
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2015-01-29 15:35:06 +11:00
|
|
|
class _RestrictContext:
|
2012-12-20 03:56:22 +00:00
|
|
|
__slots__ = ()
|
|
|
|
_real_data = _bpy.data
|
2013-01-15 17:20:52 +00:00
|
|
|
# safe, the pointer never changes
|
2018-12-21 12:47:44 +11:00
|
|
|
_real_pref = _bpy.context.preferences
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2012-12-20 03:56:22 +00:00
|
|
|
@property
|
|
|
|
def window_manager(self):
|
|
|
|
return self._real_data.window_managers[0]
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2013-01-15 17:20:52 +00:00
|
|
|
@property
|
2018-12-21 12:47:44 +11:00
|
|
|
def preferences(self):
|
2013-01-15 17:20:52 +00:00
|
|
|
return self._real_pref
|
2012-12-20 03:56:22 +00:00
|
|
|
|
|
|
|
|
2015-01-29 15:35:06 +11:00
|
|
|
class _RestrictData:
|
2012-12-20 03:56:22 +00:00
|
|
|
__slots__ = ()
|
|
|
|
|
|
|
|
|
|
|
|
_context_restrict = _RestrictContext()
|
|
|
|
_data_restrict = _RestrictData()
|
|
|
|
|
|
|
|
|
2015-01-29 15:35:06 +11:00
|
|
|
class RestrictBlend:
|
2012-12-20 03:56:22 +00:00
|
|
|
__slots__ = ("context", "data")
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2012-12-20 03:56:22 +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):
|
2012-12-20 03:56:22 +00:00
|
|
|
_bpy.data = self.data
|
|
|
|
_bpy.context = self.context
|