11import platform
2+ import os
23
34import moderngl
45import pyglet
89
910from .keys import Keys
1011
11- if platform .system () == "Darwin" :
12+ if platform .system () == "Darwin" and not os . environ . get ( 'DOCS_BUILDING' ) :
1213 raise RuntimeError ((
1314 "Pyglet do not support OpenGL core contexts "
1415 "and will only be able to support version 2.1 on OS X.\n "
1718
1819
1920class Window (BaseWindow ):
21+ """
22+ Window based on pyglet.
23+
24+ Note that pylget is unable to make core 3.3+ contexts
25+ and will not work for certain drivers and enviroments such as on OS X.
26+ """
2027 keys = Keys
2128
2229 def __init__ (self ):
30+ """
31+ Opens a window using pyglet, registers input callbacks
32+ and creates a moderngl context.
33+ """
2334 super ().__init__ ()
2435 # Disable all error checking
2536 pyglet .options ['debug_gl' ] = False
@@ -55,16 +66,31 @@ def __init__(self):
5566 self .set_default_viewport ()
5667
5768 def on_key_press (self , symbol , modifiers ):
69+ """
70+ Pyglet specific key press callback.
71+ Forwards and translates the events to :py:func:`keyboard_event`
72+ """
5873 self .keyboard_event (symbol , self .keys .ACTION_PRESS , modifiers )
5974
6075 def on_key_release (self , symbol , modifiers ):
76+ """
77+ Pyglet specific key release callback.
78+ Forwards and translates the events to :py:func:`keyboard_event`
79+ """
6180 self .keyboard_event (symbol , self .keys .ACTION_RELEASE , modifiers )
6281
6382 def on_mouse_motion (self , x , y , dx , dy ):
83+ """
84+ Pyglet specific mouse motion callback.
85+ Forwards and traslates the event to :py:func:`cursor_event`
86+ """
6487 # screen coordinates relative to the lower-left corner
6588 self .cursor_event (x , self .buffer_height - y , dx , dy )
6689
6790 def on_resize (self , width , height ):
91+ """
92+ Pyglet specific callback for window resize events.
93+ """
6894 self .width , self .height = width , height
6995 self .buffer_width , self .buffer_height = width , height
7096 self .resize (width , height )
@@ -74,21 +100,32 @@ def use(self):
74100 self .fbo .use ()
75101
76102 def swap_buffers (self ):
77- # Ensure the context is present
103+ """
104+ Swap buffers, increment frame counter and pull events
105+ """
78106 if not self .window .context :
79107 return
80108
81109 self .frames += 1
82110 self .window .flip ()
83111 self .window .dispatch_events ()
84112
85- def should_close (self ):
113+ def should_close (self ) -> bool :
114+ """
115+ returns the ``has_exit`` state in the pyglet window
116+ """
86117 return self .window .has_exit
87118
88119 def close (self ):
120+ """
121+ Sets the close state in the pyglet window
122+ """
89123 self .window .close ()
90124
91125 def terminate (self ):
126+ """
127+ No cleanup is really needed. Empty method
128+ """
92129 pass
93130
94131
0 commit comments