@@ -74,22 +74,22 @@ class UnknownEvent(Event):
74
74
return UnknownEvent
75
75
76
76
77
- def event_class (ev_type : int ) -> type [EventLike ]:
78
- _check_ev_type (ev_type )
77
+ def event_class (type : int ) -> type [EventLike ]:
78
+ _check_ev_type (type )
79
79
80
- if ev_type not in _events_map :
81
- _events_map [ev_type ] = _unknown_event_factory (ev_type )
82
- return _events_map [ev_type ]
80
+ if type not in _events_map :
81
+ _events_map [type ] = _unknown_event_factory (type )
82
+ return _events_map [type ]
83
83
84
84
85
85
class _EventMeta (type ):
86
- def _create_of_type (self , type : int , * args , ** kwds ):
86
+ def _create_of_type (cls , type : int , * args , ** kwds ):
87
87
return event_class (type )(* args , ** kwds )
88
88
89
- def __call__ (self , * args : Any , ** kwds : Any ) -> Any :
90
- if self is Event :
91
- return self ._create_of_type (* args , ** kwds )
92
- return super (_EventMeta , self ).__call__ (* args , ** kwds )
89
+ def __call__ (cls , * args : Any , ** kwds : Any ) -> Any :
90
+ if cls is Event :
91
+ return cls ._create_of_type (* args , ** kwds )
92
+ return super (_EventMeta , cls ).__call__ (* args , ** kwds )
93
93
94
94
95
95
class Event (metaclass = _EventMeta ):
@@ -141,7 +141,11 @@ def __eq__(self, other: Any):
141
141
142
142
def __repr__ (self ):
143
143
if getattr (self , "_unknown" , False ):
144
- return f"<{ type (self ).__module__ } .<dynamic>.{ type (self ).__name__ } ({ self .type } { self .dict } )>"
144
+ return (
145
+ f"<{ type (self ).__module__ } .<dynamic>."
146
+ f"{ type (self ).__name__ } ({ self .type } { self .dict } )>"
147
+ )
148
+
145
149
return f"<{ type (self ).__module__ } .{ type (self ).__qualname__ } ({ self .dict } )>"
146
150
147
151
@property
@@ -163,9 +167,10 @@ def __getattribute__(self, name: str):
163
167
def __setattr__ (self , name : str , value : Any ):
164
168
if name == "type" :
165
169
raise AttributeError (
166
- f "attribute 'type' of 'Event' or its subclass object is protected"
170
+ "attribute 'type' of 'Event' or its subclass object is protected"
167
171
)
168
- elif name in ("_dict" , "dict" ):
172
+
173
+ if name in ("_dict" , "dict" ):
169
174
super ().__setattr__ (name , value )
170
175
else :
171
176
self ._dict [name ] = value
@@ -446,136 +451,141 @@ def _create_class(type: int, name: str, note: str | None):
446
451
447
452
# for cls in _events_map.values():
448
453
# if cls.__name__ == "UserEvent": continue
449
- # print(f"{cls.__name__} = _create_class(pg.{const_find(cls.type, cls.__name__)}, {cls.__qualname__!r}, {cls.__doc__!r})")
454
+ # print(
455
+ # f"{cls.__name__} = _create_class(pg.{const_find(cls.type, cls.__name__)}, " \
456
+ # f"{cls.__qualname__!r}, {cls.__doc__!r})"
457
+ # )
450
458
451
459
452
- ActiveEvent = _create_class (pg .ACTIVEEVENT , ' ActiveEvent' , None )
453
- AppTerminating = _create_class (pg .APP_TERMINATING , ' AppTerminating' , None )
454
- AppLowMemory = _create_class (pg .APP_LOWMEMORY , ' AppLowMemory' , None )
460
+ ActiveEvent = _create_class (pg .ACTIVEEVENT , " ActiveEvent" , None )
461
+ AppTerminating = _create_class (pg .APP_TERMINATING , " AppTerminating" , None )
462
+ AppLowMemory = _create_class (pg .APP_LOWMEMORY , " AppLowMemory" , None )
455
463
AppWillEnterBackground = _create_class (
456
- pg .APP_WILLENTERBACKGROUND , ' AppWillEnterBackground' , None
464
+ pg .APP_WILLENTERBACKGROUND , " AppWillEnterBackground" , None
457
465
)
458
466
AppDidEnterBackground = _create_class (
459
- pg .APP_DIDENTERBACKGROUND , ' AppDidEnterBackground' , None
467
+ pg .APP_DIDENTERBACKGROUND , " AppDidEnterBackground" , None
460
468
)
461
469
AppWillEnterForeground = _create_class (
462
- pg .APP_WILLENTERFOREGROUND , ' AppWillEnterForeground' , None
470
+ pg .APP_WILLENTERFOREGROUND , " AppWillEnterForeground" , None
463
471
)
464
472
AppDidEnterForeground = _create_class (
465
- pg .APP_DIDENTERFOREGROUND , ' AppDidEnterForeground' , None
473
+ pg .APP_DIDENTERFOREGROUND , " AppDidEnterForeground" , None
466
474
)
467
- ClipboardUpdate = _create_class (pg .CLIPBOARDUPDATE , ' ClipboardUpdate' , None )
468
- KeyDown = _create_class (pg .KEYDOWN , ' KeyDown' , None )
469
- KeyUp = _create_class (pg .KEYUP , ' KeyUp' , None )
470
- KeyMapChanged = _create_class (pg .KEYMAPCHANGED , ' KeyMapChanged' , None )
471
- LocaleChanged = _create_class (pg .LOCALECHANGED , ' LocaleChanged' , ' Only for SDL 2.0.14+' )
472
- MouseMotion = _create_class (pg .MOUSEMOTION , ' MouseMotion' , None )
473
- MouseButtonDown = _create_class (pg .MOUSEBUTTONDOWN , ' MouseButtonDown' , None )
474
- MouseButtonUp = _create_class (pg .MOUSEBUTTONUP , ' MouseButtonUp' , None )
475
+ ClipboardUpdate = _create_class (pg .CLIPBOARDUPDATE , " ClipboardUpdate" , None )
476
+ KeyDown = _create_class (pg .KEYDOWN , " KeyDown" , None )
477
+ KeyUp = _create_class (pg .KEYUP , " KeyUp" , None )
478
+ KeyMapChanged = _create_class (pg .KEYMAPCHANGED , " KeyMapChanged" , None )
479
+ LocaleChanged = _create_class (pg .LOCALECHANGED , " LocaleChanged" , " Only for SDL 2.0.14+" )
480
+ MouseMotion = _create_class (pg .MOUSEMOTION , " MouseMotion" , None )
481
+ MouseButtonDown = _create_class (pg .MOUSEBUTTONDOWN , " MouseButtonDown" , None )
482
+ MouseButtonUp = _create_class (pg .MOUSEBUTTONUP , " MouseButtonUp" , None )
475
483
JoyAxisMotion = _create_class (
476
484
pg .JOYAXISMOTION ,
477
- ' JoyAxisMotion' ,
485
+ " JoyAxisMotion" ,
478
486
'Attribute "joy" is depracated, use "instance_id".' ,
479
487
)
480
488
JoyBallMotion = _create_class (
481
489
pg .JOYBALLMOTION ,
482
- ' JoyBallMotion' ,
490
+ " JoyBallMotion" ,
483
491
'Attribute "joy" is depracated, use "instance_id".' ,
484
492
)
485
493
JoyHatMotion = _create_class (
486
- pg .JOYHATMOTION , ' JoyHatMotion' , 'Attribute "joy" is depracated, use "instance_id".'
494
+ pg .JOYHATMOTION , " JoyHatMotion" , 'Attribute "joy" is depracated, use "instance_id".'
487
495
)
488
496
JoyButtonUp = _create_class (
489
- pg .JOYBUTTONUP , ' JoyButtonUp' , 'Attribute "joy" is depracated, use "instance_id".'
497
+ pg .JOYBUTTONUP , " JoyButtonUp" , 'Attribute "joy" is depracated, use "instance_id".'
490
498
)
491
499
JoyButtonDown = _create_class (
492
500
pg .JOYBUTTONDOWN ,
493
- ' JoyButtonDown' ,
501
+ " JoyButtonDown" ,
494
502
'Attribute "joy" is depracated, use "instance_id".' ,
495
503
)
496
- Quit = _create_class (pg .QUIT , ' Quit' , None )
504
+ Quit = _create_class (pg .QUIT , " Quit" , None )
497
505
SysWMEvent = _create_class (
498
506
pg .SYSWMEVENT ,
499
- 'SysWMEvent' ,
500
- "\n Attributes are OS-depended:\n hwnd, msg, wparam, lparam - Windows.\n event - Unix / OpenBSD\n For other OSes and in some cases for Unix / OpenBSD\n this event won't have any attributes.\n " ,
507
+ "SysWMEvent" ,
508
+ "\n Attributes are OS-depended:\n hwnd, msg, wparam, lparam - Windows.\n "
509
+ " event - Unix / OpenBSD\n For other OSes and in some cases for Unix / OpenBSD\n "
510
+ " this event won't have any attributes.\n " ,
501
511
)
502
- VideoResize = _create_class (pg .VIDEORESIZE , ' VideoResize' , None )
503
- VideoExpose = _create_class (pg .VIDEOEXPOSE , ' VideoExpose' , None )
504
- MidiIn = _create_class (pg .MIDIIN , ' MidiIn' , None )
505
- MidiOut = _create_class (pg .MIDIOUT , ' MidiOut' , None )
506
- NoEvent = _create_class (pg .NOEVENT , ' NoEvent' , None )
512
+ VideoResize = _create_class (pg .VIDEORESIZE , " VideoResize" , None )
513
+ VideoExpose = _create_class (pg .VIDEOEXPOSE , " VideoExpose" , None )
514
+ MidiIn = _create_class (pg .MIDIIN , " MidiIn" , None )
515
+ MidiOut = _create_class (pg .MIDIOUT , " MidiOut" , None )
516
+ NoEvent = _create_class (pg .NOEVENT , " NoEvent" , None )
507
517
FingerMotion = _create_class (
508
- pg .FINGERMOTION , ' FingerMotion' , 'Attribute "window" avalible only for SDL 2.0.14+'
518
+ pg .FINGERMOTION , " FingerMotion" , 'Attribute "window" avalible only for SDL 2.0.14+'
509
519
)
510
520
FingerDown = _create_class (
511
- pg .FINGERDOWN , ' FingerDown' , 'Attribute "window" avalible only for SDL 2.0.14+'
521
+ pg .FINGERDOWN , " FingerDown" , 'Attribute "window" avalible only for SDL 2.0.14+'
512
522
)
513
523
FingerUp = _create_class (
514
- pg .FINGERUP , ' FingerUp' , 'Attribute "window" avalible only for SDL 2.0.14+'
524
+ pg .FINGERUP , " FingerUp" , 'Attribute "window" avalible only for SDL 2.0.14+'
515
525
)
516
- MultiGesture = _create_class (pg .MULTIGESTURE , ' MultiGesture' , None )
517
- MouseWheel = _create_class (pg .MOUSEWHEEL , ' MouseWheel' , None )
518
- TextInput = _create_class (pg .TEXTINPUT , ' TextInput' , None )
519
- TextEditing = _create_class (pg .TEXTEDITING , ' TextEditing' , None )
520
- DropFile = _create_class (pg .DROPFILE , ' DropFile' , None )
521
- DropText = _create_class (pg .DROPTEXT , ' DropText' , None )
522
- DropBegin = _create_class (pg .DROPBEGIN , ' DropBegin' , None )
523
- DropComplete = _create_class (pg .DROPCOMPLETE , ' DropComplete' , None )
526
+ MultiGesture = _create_class (pg .MULTIGESTURE , " MultiGesture" , None )
527
+ MouseWheel = _create_class (pg .MOUSEWHEEL , " MouseWheel" , None )
528
+ TextInput = _create_class (pg .TEXTINPUT , " TextInput" , None )
529
+ TextEditing = _create_class (pg .TEXTEDITING , " TextEditing" , None )
530
+ DropFile = _create_class (pg .DROPFILE , " DropFile" , None )
531
+ DropText = _create_class (pg .DROPTEXT , " DropText" , None )
532
+ DropBegin = _create_class (pg .DROPBEGIN , " DropBegin" , None )
533
+ DropComplete = _create_class (pg .DROPCOMPLETE , " DropComplete" , None )
524
534
ControllerAxisMotion = _create_class (
525
- pg .CONTROLLERAXISMOTION , ' ControllerAxisMotion' , None
535
+ pg .CONTROLLERAXISMOTION , " ControllerAxisMotion" , None
526
536
)
527
537
ControllerButtonDown = _create_class (
528
- pg .CONTROLLERBUTTONDOWN , ' ControllerButtonDown' , None
538
+ pg .CONTROLLERBUTTONDOWN , " ControllerButtonDown" , None
529
539
)
530
- ControllerButtonUp = _create_class (pg .CONTROLLERBUTTONUP , ' ControllerButtonUp' , None )
540
+ ControllerButtonUp = _create_class (pg .CONTROLLERBUTTONUP , " ControllerButtonUp" , None )
531
541
ControllerDeviceAdded = _create_class (
532
- pg .CONTROLLERDEVICEADDED , ' ControllerDeviceAdded' , None
542
+ pg .CONTROLLERDEVICEADDED , " ControllerDeviceAdded" , None
533
543
)
534
544
ControllerDeviceRemoved = _create_class (
535
- pg .CONTROLLERDEVICEREMOVED , ' ControllerDeviceRemoved' , None
545
+ pg .CONTROLLERDEVICEREMOVED , " ControllerDeviceRemoved" , None
536
546
)
537
547
ControllerDeviceMapped = _create_class (
538
- pg .CONTROLLERDEVICEREMAPPED , ' ControllerDeviceMapped' , None
548
+ pg .CONTROLLERDEVICEREMAPPED , " ControllerDeviceMapped" , None
539
549
)
540
- JoyDeviceAdded = _create_class (pg .JOYDEVICEADDED , ' JoyDeviceAdded' , None )
541
- JoyDeviceRemoved = _create_class (pg .JOYDEVICEREMOVED , ' JoyDeviceRemoved' , None )
550
+ JoyDeviceAdded = _create_class (pg .JOYDEVICEADDED , " JoyDeviceAdded" , None )
551
+ JoyDeviceRemoved = _create_class (pg .JOYDEVICEREMOVED , " JoyDeviceRemoved" , None )
542
552
ControllerTouchpadDown = _create_class (
543
- pg .CONTROLLERTOUCHPADDOWN , ' ControllerTouchpadDown' , ' Only for SDL 2.0.14+'
553
+ pg .CONTROLLERTOUCHPADDOWN , " ControllerTouchpadDown" , " Only for SDL 2.0.14+"
544
554
)
545
555
ControllerTouchpadMotion = _create_class (
546
- pg .CONTROLLERTOUCHPADMOTION , ' ControllerTouchpadMotion' , ' Only for SDL 2.0.14+'
556
+ pg .CONTROLLERTOUCHPADMOTION , " ControllerTouchpadMotion" , " Only for SDL 2.0.14+"
547
557
)
548
558
ControllerTouchpadUp = _create_class (
549
- pg .CONTROLLERTOUCHPADUP , ' ControllerTouchpadUp' , ' Only for SDL 2.0.14+'
559
+ pg .CONTROLLERTOUCHPADUP , " ControllerTouchpadUp" , " Only for SDL 2.0.14+"
550
560
)
551
561
ControllerSensorUpdate = _create_class (
552
- pg .CONTROLLERSENSORUPDATE , ' ControllerSensorUpdate' , ' Only for SDL 2.0.14+'
562
+ pg .CONTROLLERSENSORUPDATE , " ControllerSensorUpdate" , " Only for SDL 2.0.14+"
553
563
)
554
- AudioDeviceAdded = _create_class (pg .AUDIODEVICEADDED , ' AudioDeviceAdded' , None )
555
- AudioDeviceRemoved = _create_class (pg .AUDIODEVICEREMOVED , ' AudioDeviceRemoved' , None )
556
- RenderTargetsReset = _create_class (pg .RENDER_TARGETS_RESET , ' RenderTargetsReset' , None )
557
- RenderDeviceReset = _create_class (pg .RENDER_DEVICE_RESET , ' RenderDeviceReset' , None )
558
- WindowShown = _create_class (pg .WINDOWSHOWN , ' WindowShown' , None )
559
- WindowHidden = _create_class (pg .WINDOWHIDDEN , ' WindowHidden' , None )
560
- WindowExposed = _create_class (pg .WINDOWEXPOSED , ' WindowExposed' , None )
561
- WindowMoved = _create_class (pg .WINDOWMOVED , ' WindowMoved' , None )
562
- WindowResized = _create_class (pg .WINDOWRESIZED , ' WindowResized' , None )
563
- WindowSizeChanged = _create_class (pg .WINDOWSIZECHANGED , ' WindowSizeChanged' , None )
564
- WindowMinimized = _create_class (pg .WINDOWMINIMIZED , ' WindowMinimized' , None )
565
- WindowMaximized = _create_class (pg .WINDOWMAXIMIZED , ' WindowMaximized' , None )
566
- WindowRestored = _create_class (pg .WINDOWRESTORED , ' WindowRestored' , None )
567
- WindowEnter = _create_class (pg .WINDOWENTER , ' WindowEnter' , None )
568
- WindowLeave = _create_class (pg .WINDOWLEAVE , ' WindowLeave' , None )
569
- WindowFocusGained = _create_class (pg .WINDOWFOCUSGAINED , ' WindowFocusGained' , None )
570
- WindowFocusLost = _create_class (pg .WINDOWFOCUSLOST , ' WindowFocusLost' , None )
571
- WindowClose = _create_class (pg .WINDOWCLOSE , ' WindowClose' , None )
572
- WindowTakeFocus = _create_class (pg .WINDOWTAKEFOCUS , ' WindowTakeFocus' , None )
573
- WindowHitTest = _create_class (pg .WINDOWHITTEST , ' WindowHitTest' , None )
564
+ AudioDeviceAdded = _create_class (pg .AUDIODEVICEADDED , " AudioDeviceAdded" , None )
565
+ AudioDeviceRemoved = _create_class (pg .AUDIODEVICEREMOVED , " AudioDeviceRemoved" , None )
566
+ RenderTargetsReset = _create_class (pg .RENDER_TARGETS_RESET , " RenderTargetsReset" , None )
567
+ RenderDeviceReset = _create_class (pg .RENDER_DEVICE_RESET , " RenderDeviceReset" , None )
568
+ WindowShown = _create_class (pg .WINDOWSHOWN , " WindowShown" , None )
569
+ WindowHidden = _create_class (pg .WINDOWHIDDEN , " WindowHidden" , None )
570
+ WindowExposed = _create_class (pg .WINDOWEXPOSED , " WindowExposed" , None )
571
+ WindowMoved = _create_class (pg .WINDOWMOVED , " WindowMoved" , None )
572
+ WindowResized = _create_class (pg .WINDOWRESIZED , " WindowResized" , None )
573
+ WindowSizeChanged = _create_class (pg .WINDOWSIZECHANGED , " WindowSizeChanged" , None )
574
+ WindowMinimized = _create_class (pg .WINDOWMINIMIZED , " WindowMinimized" , None )
575
+ WindowMaximized = _create_class (pg .WINDOWMAXIMIZED , " WindowMaximized" , None )
576
+ WindowRestored = _create_class (pg .WINDOWRESTORED , " WindowRestored" , None )
577
+ WindowEnter = _create_class (pg .WINDOWENTER , " WindowEnter" , None )
578
+ WindowLeave = _create_class (pg .WINDOWLEAVE , " WindowLeave" , None )
579
+ WindowFocusGained = _create_class (pg .WINDOWFOCUSGAINED , " WindowFocusGained" , None )
580
+ WindowFocusLost = _create_class (pg .WINDOWFOCUSLOST , " WindowFocusLost" , None )
581
+ WindowClose = _create_class (pg .WINDOWCLOSE , " WindowClose" , None )
582
+ WindowTakeFocus = _create_class (pg .WINDOWTAKEFOCUS , " WindowTakeFocus" , None )
583
+ WindowHitTest = _create_class (pg .WINDOWHITTEST , " WindowHitTest" , None )
574
584
WindowICCProfChanged = _create_class (
575
- pg .WINDOWICCPROFCHANGED , ' WindowICCProfChanged' , None
585
+ pg .WINDOWICCPROFCHANGED , " WindowICCProfChanged" , None
576
586
)
577
587
WindowDisplayChanged = _create_class (
578
- pg .WINDOWDISPLAYCHANGED , ' WindowDisplayChanged' , None
588
+ pg .WINDOWDISPLAYCHANGED , " WindowDisplayChanged" , None
579
589
)
580
590
581
591
0 commit comments