Package glitter :: Package contexts :: Module contextmanager
[hide private]
[frames] | no frames]

Source Code for Module glitter.contexts.contextmanager

 1  """Tools for managing render contexts. 
 2   
 3  @author: Stephan Wenger 
 4  @date: 2012-03-08 
 5  """ 
6 7 -class ContextBindingProxy(object):
8 _bound_context = None 9
10 - def __get__(self, obj, cls=None):
11 return self._bound_context
12
13 - def __set__(self, obj, context=None):
14 if context is None: 15 self._bound_context = None 16 elif context != self._bound_context: 17 self._bound_context = context 18 context._bind()
19
20 - def __repr__(self):
21 return "proxy for context binding"
22
23 -class ContextManager(object):
24 current_context = ContextBindingProxy() 25 """The currently active context.""" 26
27 - def __init__(self):
28 self._stack = []
29
30 - def push(self, context):
31 self._stack.append(self.current_context) 32 self.current_context = context
33
34 - def pop(self):
35 self.current_context = self._stack.pop()
36 37 @staticmethod
39 """Create a default offscreen rendering context. 40 41 @todo: This is window system dependent; create an appropriate context 42 dynamically. 43 @todo: When no context exists, create a raw offscreen context instead of a 44 hidden GLUT window so that rendering is possible without an X connection. 45 """ 46 47 from glitter.contexts.glut import GlutWindow 48 return GlutWindow(shape=(1, 1), hide=True)
49 50 context_manager = ContextManager() 51 52 __all__ = ["context_manager"] 53