3
3
from dataclasses import dataclass
4
4
from typing import Any
5
5
6
+ from pyglet .math import Vec2
7
+
6
8
7
9
@dataclass
8
10
class UIEvent :
9
- """
10
- An event created by the GUI system. Can be passed using widget.dispatch("on_event", event).
11
- An event always has a source, which is the UIManager for general input events,
12
- but will be the specific widget in case of events like on_click events.
11
+ """An event created by the GUI system.
12
+
13
+ Can be passed as follows:
14
+
15
+ .. code-block:: python
16
+
17
+ widget.dispatch("on_event", event)
18
+
19
+ An event always has a source. This is the UIManager for general input
20
+ events, but will be the specific widget in case of events like click
21
+ events.
22
+
23
+ Args:
24
+ source: The source of the event.
13
25
"""
14
26
15
27
source : Any
16
28
17
29
18
30
@dataclass
19
31
class UIMouseEvent (UIEvent ):
20
- """
21
- Covers all mouse event
32
+ """Base class for all UI mouse events.
33
+
34
+ Args:
35
+ x: The x coordinate of the mouse.
36
+ y: The y coordinate of the mouse.
22
37
"""
23
38
24
39
x : int
25
40
y : int
26
41
27
42
@property
28
- def pos (self ):
29
- return self .x , self .y
43
+ def pos (self ) -> Vec2 :
44
+ """Return the position as tuple (x, y)"""
45
+ return Vec2 (self .x , self .y )
30
46
31
47
32
48
@dataclass
33
49
class UIMouseMovementEvent (UIMouseEvent ):
34
- """Triggered when the mouse is moved."""
50
+ """Triggered when the mouse is moved.
51
+
52
+ Args:
53
+ dx: The change in x coordinate.
54
+ dy: The change in y coordinate.
55
+ """
35
56
36
57
dx : int
37
58
dy : int
38
59
39
60
40
61
@dataclass
41
62
class UIMousePressEvent (UIMouseEvent ):
42
- """Triggered when a mouse button(left, right, middle) is pressed."""
63
+ """Triggered when a mouse button(left, right, middle) is pressed.
64
+
65
+ Args:
66
+ button: The button pressed.
67
+ modifiers: The modifiers pressed.
68
+ """
43
69
44
70
button : int
45
71
modifiers : int
46
72
47
73
48
74
@dataclass
49
75
class UIMouseDragEvent (UIMouseEvent ):
50
- """Triggered when the mouse moves while one of its buttons being pressed."""
76
+ """Triggered when the mouse moves while one of its buttons being pressed.
77
+
78
+ Args:
79
+ dx: The change in x coordinate.
80
+ dy: The change in y coordinate.
81
+ buttons: The buttons pressed.
82
+ modifiers: The modifiers pressed.
83
+ """
51
84
52
85
dx : int
53
86
dy : int
@@ -57,23 +90,38 @@ class UIMouseDragEvent(UIMouseEvent):
57
90
58
91
@dataclass
59
92
class UIMouseReleaseEvent (UIMouseEvent ):
60
- """Triggered when a mouse button is released."""
93
+ """Triggered when a mouse button is released.
94
+
95
+ Args:
96
+ button: The button released.
97
+ modifiers: The modifiers pressed
98
+ """
61
99
62
100
button : int
63
101
modifiers : int
64
102
65
103
66
104
@dataclass
67
105
class UIMouseScrollEvent (UIMouseEvent ):
68
- """Triggered by rotating the scroll wheel on the mouse."""
106
+ """Triggered by rotating the scroll wheel on the mouse.
107
+
108
+ Args:
109
+ scroll_x: The horizontal scroll amount.
110
+ scroll_y: The vertical scroll
111
+ """
69
112
70
113
scroll_x : int
71
114
scroll_y : int
72
115
73
116
74
117
@dataclass
75
118
class UIKeyEvent (UIEvent ):
76
- """Covers all keyboard event."""
119
+ """Base class for all keyboard-centric UI events.
120
+
121
+ Args:
122
+ symbol: The key pressed.
123
+ modifiers: The modifiers pressed.
124
+ """
77
125
78
126
symbol : int
79
127
modifiers : int
@@ -114,46 +162,67 @@ class UITextInputEvent(UITextEvent):
114
162
* a platform-specific input method, such as pen input on a tablet PC
115
163
116
164
To learn more, see pyglet's `relevant documentation <https://pyglet.readthedocs.io/en/development/modules/window.html#pyglet.window.Window.on_text>`_.
165
+
166
+ Args:
167
+ text: The text inputted. Often a single character.
117
168
"""
118
169
119
170
text : str
120
171
121
172
122
173
@dataclass
123
174
class UITextMotionEvent (UITextEvent ):
124
- """Triggered when text cursor moves."""
175
+ """Triggered when text cursor moves.
176
+
177
+ Args:
178
+ motion: The motion of the cursor
179
+ """
125
180
126
181
motion : Any
127
182
128
183
129
184
@dataclass
130
185
class UITextMotionSelectEvent (UITextEvent ):
131
- """Triggered when the text cursor moves selecting the text with it."""
186
+ """Triggered when the text cursor moves selecting the text with it.
187
+
188
+ Args:
189
+ selection: The selection of the cursor
190
+ """
132
191
133
192
selection : Any
134
193
135
194
136
195
@dataclass
137
196
class UIOnClickEvent (UIMouseEvent ):
138
- """Triggered when a widget is clicked."""
197
+ """Triggered when a widget is clicked.
198
+
199
+ Args:
200
+ button: The button clicked.
201
+ modifiers: The modifiers pressed.
202
+ """
139
203
140
204
button : int
141
205
modifiers : int
142
206
143
207
144
208
@dataclass
145
209
class UIOnUpdateEvent (UIEvent ):
146
- """
147
- Arcade on_update callback passed as :class:`UIEvent`
210
+ """Arcade on_update callback passed as :class:`UIEvent`.
211
+
212
+ Args:
213
+ dt: Time since last update
148
214
"""
149
215
150
216
dt : int
151
217
152
218
153
219
@dataclass
154
220
class UIOnChangeEvent (UIEvent ):
155
- """
156
- Value of a widget changed
221
+ """Value of a widget changed.
222
+
223
+ Args:
224
+ old_value: The old value.
225
+ new_value: The new value.
157
226
"""
158
227
159
228
old_value : Any
@@ -162,10 +231,10 @@ class UIOnChangeEvent(UIEvent):
162
231
163
232
@dataclass
164
233
class UIOnActionEvent (UIEvent ):
165
- """
166
- Notification about an action
234
+ """Notification about an action.
167
235
168
- :param action: Value describing the action, mostly a string
236
+ Args:
237
+ action: Value describing the action, mostly a string
169
238
"""
170
239
171
240
action : Any
0 commit comments