Skip to content

Commit 630216d

Browse files
committed
Docs: Pyglet window
1 parent 2107aa2 commit 630216d

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

demosys/context/pyglet/keys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
class Keys(BaseKeys):
8-
"""Namespace translating pyglet keys"""
8+
"""
9+
Namespace mapping pyglet specific key constants
10+
"""
911
ESCAPE = key.ESCAPE
1012
SPACE = key.SPACE
1113
ENTER = key.ENTER

demosys/context/pyglet/window.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import platform
2+
import os
23

34
import moderngl
45
import pyglet
@@ -8,7 +9,7 @@
89

910
from .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"
@@ -17,9 +18,19 @@
1718

1819

1920
class 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

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Mock(MagicMock):
3535
def __getattr__(cls, name):
3636
return MagicMock()
3737

38-
MOCK_MODULES = ['glfw',]
38+
MOCK_MODULES = ['glfw', 'pyglet', 'pyglet.window']
3939
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
4040

4141
# Define a settings module
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
.. py:module:: demosys.context.pyglet
3+
.. py:currentmodule:: demosys.context.pyglet
4+
5+
demosys.context.pyglet.Window
6+
=============================
7+
8+
.. autodata:: Window
9+
10+
.. autodata:: Keys
11+
12+
Methods
13+
-------
14+
15+
.. automethod:: Window.__init__
16+
.. automethod:: Window.on_key_press
17+
.. automethod:: Window.on_key_release
18+
.. automethod:: Window.on_mouse_motion
19+
.. automethod:: Window.on_resize
20+
.. automethod:: Window.use
21+
.. automethod:: Window.swap_buffers
22+
.. automethod:: Window.should_close
23+
.. automethod:: Window.close
24+
.. automethod:: Window.terminate
25+
26+
Attributes
27+
----------

docs/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Reference
1818
demosys.context.base
1919
demosys.context.glfw
2020
demosys.context.headless
21+
demosys.context.pyglet

0 commit comments

Comments
 (0)