Skip to content

Commit e9d250d

Browse files
committed
Stubs finished.
1 parent 51fd400 commit e9d250d

File tree

1 file changed

+175
-4
lines changed

1 file changed

+175
-4
lines changed

buildconfig/stubs/pygame/event.pyi

Lines changed: 175 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ from typing import (
22
Any,
33
Dict,
44
List,
5+
Tuple,
56
Optional,
67
Union,
78
Literal,
89
overload,
910
Type,
1011
)
1112

12-
from ._common import Sequence
13+
from pygame._common import Sequence
14+
from pygame.window import Window
1315

1416
class _EventMeta(type): ...
1517

@@ -24,17 +26,17 @@ class Event(metaclass=_EventMeta):
2426
) -> None: ...
2527
@overload
2628
def __init__(
27-
self, type: int, dict: Dict[str, Any] = ..., /, **kwargs: Any
29+
self, dict: Dict[str, Any] = ..., /, **kwargs: Any
2830
) -> None: ...
2931
def __getattribute__(self, name: str) -> Any: ...
3032
def __setattr__(self, name: str, value: Any) -> None: ...
3133
def __delattr__(self, name: str) -> None: ...
3234
def __bool__(self) -> bool: ...
3335

34-
# TODO: fill with arguments.
35-
3636
class ActiveEvent(Event):
3737
type: Literal[32768] = 32768
38+
gain: int
39+
state: int
3840

3941
class AppTerminating(Event):
4042
type: Literal[257] = 257
@@ -59,9 +61,19 @@ class ClipboardUpdate(Event):
5961

6062
class KeyDown(Event):
6163
type: Literal[768] = 768
64+
unicode: str
65+
key: int
66+
mod: int
67+
scancode: int
68+
window: Optional[Window]
6269

6370
class KeyUp(Event):
6471
type: Literal[769] = 769
72+
unicode: str
73+
key: int
74+
mod: int
75+
scancode: int
76+
window: Optional[Window]
6577

6678
class KeyMapChanged(Event):
6779
type: Literal[772] = 772
@@ -72,36 +84,82 @@ class LocaleChanged(Event):
7284

7385
class MouseMotion(Event):
7486
type: Literal[1024] = 1024
87+
pos: Tuple[int, int]
88+
rel: Tuple[int, int]
89+
buttons: tuple[int, int, int]
90+
touch: bool
91+
window: Optional[Window]
7592

7693
class MouseButtonDown(Event):
7794
type: Literal[1025] = 1025
95+
pos: Tuple[int, int]
96+
button: int
97+
touch: bool
98+
window: Optional[Window]
7899

79100
class MouseButtonUp(Event):
80101
type: Literal[1026] = 1026
102+
pos: Tuple[int, int]
103+
button: int
104+
touch: bool
105+
window: Optional[Window]
81106

82107
class JoyAxisMotion(Event):
83108
type: Literal[1536] = 1536
109+
joy: int
110+
instance_id: int
111+
axis: int
112+
value: float
84113

85114
class JoyBallMotion(Event):
86115
type: Literal[1537] = 1537
116+
joy: int
117+
instance_id: int
118+
ball: int
119+
rel: Tuple[int, int]
87120

88121
class JoyHatMotion(Event):
89122
type: Literal[1538] = 1538
123+
joy: int
124+
instance_id: int
125+
hat: int
126+
value: Tuple[int, int]
90127

91128
class JoyButtonUp(Event):
92129
type: Literal[1540] = 1540
130+
joy: int
131+
instance_id: int
132+
button: int
93133

94134
class JoyButtonDown(Event):
95135
type: Literal[1539] = 1539
136+
joy: int
137+
instance_id: int
138+
button: int
96139

97140
class Quit(Event):
98141
type: Literal[256] = 256
99142

100143
class SysWMEvent(Event):
144+
"""
145+
Attributes are OS-depended:
146+
hwnd, msg, wparam, lparam - Windows.
147+
event - Unix / OpenBSD
148+
For other OSes and in some cases for Unix / OpenBSD
149+
this event won't have any attributes.
150+
"""
101151
type: Literal[513] = 513
152+
hwnd: int
153+
msg: int
154+
wparam: int
155+
lparam: int
156+
event: bytes
102157

103158
class VideoResize(Event):
104159
type: Literal[32769] = 32769
160+
size: Tuple[int, int]
161+
w: int
162+
h: int
105163

106164
class VideoExpose(Event):
107165
type: Literal[32770] = 32770
@@ -116,83 +174,171 @@ class NoEvent(Event):
116174
type: Literal[0] = 0
117175

118176
class FingerMotion(Event):
177+
"""Attribute "window" avalible only for SDL 2.0.14+"""
119178
type: Literal[1794] = 1794
179+
touch_id: int
180+
finger_id: int
181+
x: float
182+
y: float
183+
dx: float
184+
dy: float
185+
pressure: float
186+
window: Optional[Window]
120187

121188
class FingerDown(Event):
189+
"""Attribute "window" avalible only for SDL 2.0.14+"""
122190
type: Literal[1792] = 1792
191+
touch_id: int
192+
finger_id: int
193+
x: float
194+
y: float
195+
dx: float
196+
dy: float
197+
pressure: float
198+
window: Optional[Window]
123199

124200
class FingerUp(Event):
201+
"""Attribute "window" avalible only for SDL 2.0.14+"""
125202
type: Literal[1793] = 1793
203+
touch_id: int
204+
finger_id: int
205+
x: float
206+
y: float
207+
dx: float
208+
dy: float
209+
pressure: float
210+
window: Optional[Window]
126211

127212
class MultiGesture(Event):
128213
type: Literal[2050] = 2050
214+
touch_id: int
215+
x: float
216+
y: float
217+
rotated: float
218+
pinched: float
219+
num_fingers: int
129220

130221
class MouseWheel(Event):
131222
type: Literal[1027] = 1027
223+
flipped: bool
224+
x: int
225+
y: int
226+
precise_x: float
227+
precise_y: float
228+
touch: bool
229+
window: Optional[Window]
132230

133231
class TextInput(Event):
134232
type: Literal[771] = 771
233+
text: str
234+
window: Optional[Window]
135235

136236
class TextEditing(Event):
137237
type: Literal[770] = 770
238+
text: str
239+
start: int
240+
length: int
241+
window: Optional[Window]
138242

139243
class DropFile(Event):
140244
type: Literal[4096] = 4096
245+
file: str
246+
window: Optional[Window]
141247

142248
class DropText(Event):
143249
type: Literal[4097] = 4097
250+
text: str
251+
window: Optional[Window]
144252

145253
class DropBegin(Event):
146254
type: Literal[4098] = 4098
255+
window: Optional[Window]
147256

148257
class DropComplete(Event):
149258
type: Literal[4099] = 4099
259+
window: Optional[Window]
150260

151261
class ControllerAxisMotion(Event):
152262
type: Literal[1616] = 1616
263+
instance_id: int
264+
axis: int
265+
value: int
153266

154267
class ControllerButtonDown(Event):
155268
type: Literal[1617] = 1617
269+
instance_id: int
270+
button: int
156271

157272
class ControllerButtonUp(Event):
158273
type: Literal[1618] = 1618
274+
instance_id: int
275+
button: int
159276

160277
class ControllerDeviceAdded(Event):
161278
type: Literal[1619] = 1619
279+
device_index: int
280+
guid: str
162281

163282
class ControllerDeviceRemoved(Event):
164283
type: Literal[1620] = 1620
284+
instance_id: int
165285

166286
class ControllerDeviceMapped(Event):
167287
type: Literal[1621] = 1621
288+
instance_id: int
168289

169290
class JoyDeviceAdded(Event):
170291
type: Literal[1541] = 1541
292+
device_index: int
293+
guid: str
171294

172295
class JoyDeviceRemoved(Event):
173296
type: Literal[1542] = 1542
297+
instance_id: int
174298

175299
class ControllerTouchpadDown(Event):
176300
"""Only for SDL 2.0.14+"""
177301
type: Literal[1622] = 1622
302+
instance_id: int
303+
touch_id: int
304+
finger_id: int
305+
x: float
306+
y: float
307+
pressure: float
178308

179309
class ControllerTouchpadMotion(Event):
180310
"""Only for SDL 2.0.14+"""
181311
type: Literal[1623] = 1623
312+
instance_id: int
313+
touch_id: int
314+
finger_id: int
315+
x: float
316+
y: float
317+
pressure: float
182318

183319
class ControllerTouchpadUp(Event):
184320
"""Only for SDL 2.0.14+"""
185321
type: Literal[1624] = 1624
322+
instance_id: int
323+
touch_id: int
324+
finger_id: int
325+
x: float
326+
y: float
327+
pressure: float
186328

187329
class ControllerSensorUpdate(Event):
188330
"""Only for SDL 2.0.14+"""
189331
type: Literal[1625] = 1625
190332

191333
class AudioDeviceAdded(Event):
192334
type: Literal[4352] = 4352
335+
which: int
336+
iscapture: int
193337

194338
class AudioDeviceRemoved(Event):
195339
type: Literal[4353] = 4353
340+
which: int
341+
iscapture: int
196342

197343
class RenderTargetsReset(Event):
198344
type: Literal[8192] = 8192
@@ -202,57 +348,82 @@ class RenderDeviceReset(Event):
202348

203349
class WindowShown(Event):
204350
type: Literal[32774] = 32774
351+
window: Optional[Window]
205352

206353
class WindowHidden(Event):
207354
type: Literal[32775] = 32775
355+
window: Optional[Window]
208356

209357
class WindowExposed(Event):
210358
type: Literal[32776] = 32776
359+
window: Optional[Window]
211360

212361
class WindowMoved(Event):
213362
type: Literal[32777] = 32777
363+
x: int
364+
y: int
365+
window: Optional[Window]
214366

215367
class WindowResized(Event):
216368
type: Literal[32778] = 32778
369+
x: int
370+
y: int
371+
window: Optional[Window]
217372

218373
class WindowSizeChanged(Event):
219374
type: Literal[32779] = 32779
375+
x: int
376+
y: int
377+
window: Optional[Window]
220378

221379
class WindowMinimized(Event):
222380
type: Literal[32780] = 32780
381+
window: Optional[Window]
223382

224383
class WindowMaximized(Event):
225384
type: Literal[32781] = 32781
385+
window: Optional[Window]
226386

227387
class WindowRestored(Event):
228388
type: Literal[32782] = 32782
389+
window: Optional[Window]
229390

230391
class WindowEnter(Event):
231392
type: Literal[32783] = 32783
393+
window: Optional[Window]
232394

233395
class WindowLeave(Event):
234396
type: Literal[32784] = 32784
397+
window: Optional[Window]
235398

236399
class WindowFocusGained(Event):
237400
type: Literal[32785] = 32785
401+
window: Optional[Window]
238402

239403
class WindowFocusLost(Event):
240404
type: Literal[32786] = 32786
405+
window: Optional[Window]
241406

242407
class WindowClose(Event):
243408
type: Literal[32787] = 32787
409+
window: Optional[Window]
244410

245411
class WindowTakeFocus(Event):
246412
type: Literal[32788] = 32788
413+
window: Optional[Window]
247414

248415
class WindowHitTest(Event):
249416
type: Literal[32789] = 32789
417+
window: Optional[Window]
250418

251419
class WindowICCProfChanged(Event):
252420
type: Literal[32790] = 32790
421+
window: Optional[Window]
253422

254423
class WindowDisplayChanged(Event):
255424
type: Literal[32791] = 32791
425+
display_index: int
426+
window: Optional[Window]
256427

257428
_EventTypes = Union[int, Sequence[int]]
258429

0 commit comments

Comments
 (0)