Skip to content

Commit b015b72

Browse files
committed
Docs: PyQt5 window
1 parent 630216d commit b015b72

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

demosys/context/pyqt/keys.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
class Keys(BaseKeys):
8-
"""Namespace translating pyqt keys"""
8+
"""
9+
Namespace creating pyqt specific key constants
10+
"""
911
ESCAPE = Qt.Key_Escape
1012
SPACE = Qt.Key_Space
1113
ENTER = Qt.Key_Enter

demosys/context/pyqt/window.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@
88

99

1010
class Window(BaseWindow):
11+
"""
12+
Window using PyQt5.
13+
14+
This is the recommended window if you want your project to work
15+
on most platforms out of the box without any binary dependecies.
16+
"""
1117
keys = Keys
1218

1319
def __init__(self):
20+
"""
21+
Creates a pyqt application and window overriding the
22+
built in event loop. Sets up keyboard and mouse events
23+
and creates a ``monderngl.Context``.
24+
"""
1425
super().__init__()
1526
self._closed = False
1627

@@ -73,31 +84,62 @@ def __init__(self):
7384
self.set_default_viewport()
7485

7586
def keyPressEvent(self, event):
87+
"""
88+
Pyqt specific key press callback function.
89+
Translates and forwards events to :py:func:`keyboard_event`.
90+
"""
7691
self.keyboard_event(event.key(), self.keys.ACTION_PRESS, 0)
7792

7893
def keyReleaseEvent(self, event):
94+
"""
95+
Pyqt specific key release callback function.
96+
Translates and forwards events to :py:func:`keyboard_event`.
97+
"""
7998
self.keyboard_event(event.key(), self.keys.ACTION_RELEASE, 0)
8099

81100
def mouseMoveEvent(self, event):
101+
"""
102+
Pyqt specific mouse event callback
103+
Translates and forwards events to :py:func:`cursor_event`.
104+
"""
82105
self.cursor_event(event.x(), event.y(), 0, 0)
83106

84107
def resizeGL(self, width, height):
108+
"""
109+
Pyqt specific resize callback.
110+
The window currently do not support resizing.
111+
"""
85112
print("Resize", width, height)
86113

87114
def swap_buffers(self):
115+
"""
116+
Swaps buffers, increments the frame counter and pulls events
117+
"""
88118
self.frames += 1
89119
self.widget.swapBuffers()
90120
# We don't use standard event loop having to manually process events
91121
self.app.processEvents()
92122

93123
def use(self):
124+
"""
125+
Make the window's framebuffer the current render target
126+
"""
94127
self.fbo.use()
95128

96-
def should_close(self):
129+
def should_close(self) -> bool:
130+
"""
131+
Checks if the internal close state is set
132+
"""
97133
return self._closed
98134

99135
def close(self):
136+
"""
137+
Set the internal close state
138+
"""
100139
self._closed = True
101140

102141
def terminate(self):
142+
"""
143+
Quits the running qt application
144+
"""
103145
QtCore.QCoreApplication.instance().quit()
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
.. py:module:: demosys.context.pyqt
3+
.. py:currentmodule:: demosys.context.pyqt
4+
5+
demosys.context.pyqt.Window
6+
===========================
7+
8+
.. autodata:: Window
9+
10+
.. autodata:: Keys
11+
12+
Methods
13+
-------
14+
15+
.. automethod:: Window.__init__
16+
.. automethod:: Window.keyPressEvent
17+
.. automethod:: Window.keyReleaseEvent
18+
.. automethod:: Window.mouseMoveEvent
19+
.. automethod:: Window.resizeGL
20+
.. automethod:: Window.swap_buffers
21+
.. automethod:: Window.use
22+
.. automethod:: Window.should_close
23+
.. automethod:: Window.close
24+
.. automethod:: Window.terminate
25+
26+
Attributes
27+
----------

docs/reference/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Reference
1616
demosys.timers.rocketmusic
1717
demosys.timers.vlc
1818
demosys.context.base
19+
demosys.context.pyqt
1920
demosys.context.glfw
2021
demosys.context.headless
2122
demosys.context.pyglet

0 commit comments

Comments
 (0)