~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/modules/bpy_restrict_state.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ##### BEGIN GPL LICENSE BLOCK #####
 
2
#
 
3
#  This program is free software; you can redistribute it and/or
 
4
#  modify it under the terms of the GNU General Public License
 
5
#  as published by the Free Software Foundation; either version 2
 
6
#  of the License, or (at your option) any later version.
 
7
#
 
8
#  This program is distributed in the hope that it will be useful,
 
9
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
#  GNU General Public License for more details.
 
12
#
 
13
#  You should have received a copy of the GNU General Public License
 
14
#  along with this program; if not, write to the Free Software Foundation,
 
15
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
16
#
 
17
# ##### END GPL LICENSE BLOCK #####
 
18
 
 
19
# <pep8-80 compliant>
 
20
 
 
21
"""
 
22
This module contains RestrictBlend context manager.
 
23
"""
 
24
 
 
25
__all__ = (
 
26
    "RestrictBlend",
 
27
    )
 
28
 
 
29
import bpy as _bpy
 
30
 
 
31
 
 
32
class _RestrictContext():
 
33
    __slots__ = ()
 
34
    _real_data = _bpy.data
 
35
    # safe, the pointer never changes
 
36
    _real_pref = _bpy.context.user_preferences
 
37
 
 
38
    @property
 
39
    def window_manager(self):
 
40
        return self._real_data.window_managers[0]
 
41
 
 
42
    @property
 
43
    def user_preferences(self):
 
44
        return self._real_pref
 
45
 
 
46
 
 
47
class _RestrictData():
 
48
    __slots__ = ()
 
49
 
 
50
 
 
51
_context_restrict = _RestrictContext()
 
52
_data_restrict = _RestrictData()
 
53
 
 
54
 
 
55
class RestrictBlend():
 
56
    __slots__ = ("context", "data")
 
57
 
 
58
    def __enter__(self):
 
59
        self.data = _bpy.data
 
60
        self.context = _bpy.context
 
61
        _bpy.data = _data_restrict
 
62
        _bpy.context = _context_restrict
 
63
 
 
64
    def __exit__(self, type, value, traceback):
 
65
        _bpy.data = self.data
 
66
        _bpy.context = self.context