8
8
import logging
9
9
import os
10
10
import time
11
- from typing import TYPE_CHECKING
11
+ from typing import TYPE_CHECKING , Sequence
12
12
13
13
import pyglet
14
14
import pyglet .gl as gl
15
15
import pyglet .window .mouse
16
16
from pyglet .display .base import Screen , ScreenMode
17
+ from pyglet .event import EVENT_HANDLE_STATE , EVENT_UNHANDLED
17
18
from pyglet .window import MouseCursor
18
19
19
20
import arcade
29
30
from arcade .camera .default import DefaultProjector
30
31
from arcade .start_finish_data import StartFinishRenderData
31
32
32
-
33
33
LOG = logging .getLogger (__name__ )
34
34
35
35
MOUSE_BUTTON_LEFT = 1
@@ -180,7 +180,7 @@ def __init__(
180
180
# Attempt to make window with antialiasing
181
181
if antialiasing :
182
182
try :
183
- config = pyglet . gl .Config (
183
+ config = gl .Config (
184
184
major_version = gl_version [0 ],
185
185
minor_version = gl_version [1 ],
186
186
opengl_api = gl_api , # type: ignore # pending: upstream fix
@@ -204,7 +204,7 @@ def __init__(
204
204
antialiasing = False
205
205
# If we still don't have a config
206
206
if not config :
207
- config = pyglet . gl .Config (
207
+ config = gl .Config (
208
208
major_version = gl_version [0 ],
209
209
minor_version = gl_version [1 ],
210
210
opengl_api = gl_api , # type: ignore # pending: upstream fix
@@ -239,7 +239,7 @@ def __init__(
239
239
if antialiasing :
240
240
try :
241
241
gl .glEnable (gl .GL_MULTISAMPLE_ARB )
242
- except pyglet . gl .GLException :
242
+ except gl .GLException :
243
243
LOG .warning ("Warning: Anti-aliasing not supported on this computer." )
244
244
245
245
_setup_clock ()
@@ -338,7 +338,7 @@ def ctx(self) -> ArcadeContext:
338
338
"""
339
339
return self ._ctx
340
340
341
- def clear (
341
+ def clear ( # type: ignore # not sure what to do here, BaseWindow.clear is static
342
342
self ,
343
343
color : RGBOrA255 | None = None ,
344
344
color_normalized : RGBANormalized | None = None ,
@@ -554,7 +554,7 @@ def set_draw_rate(self, rate: float) -> None:
554
554
pyglet .clock .unschedule (pyglet .app .event_loop ._redraw_windows )
555
555
pyglet .clock .schedule_interval (pyglet .app .event_loop ._redraw_windows , self ._draw_rate )
556
556
557
- def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> bool | None :
557
+ def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> EVENT_HANDLE_STATE :
558
558
"""
559
559
Called repeatedly while the mouse is moving in the window area.
560
560
@@ -568,7 +568,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> bool | None:
568
568
"""
569
569
pass
570
570
571
- def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
571
+ def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> EVENT_HANDLE_STATE :
572
572
"""
573
573
Called once whenever a mouse button gets pressed down.
574
574
@@ -596,7 +596,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> bool |
596
596
597
597
def on_mouse_drag (
598
598
self , x : int , y : int , dx : int , dy : int , buttons : int , modifiers : int
599
- ) -> bool | None :
599
+ ) -> EVENT_HANDLE_STATE :
600
600
"""
601
601
Called repeatedly while the mouse moves with a button down.
602
602
@@ -619,7 +619,7 @@ def on_mouse_drag(
619
619
"""
620
620
return self .on_mouse_motion (x , y , dx , dy )
621
621
622
- def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
622
+ def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> EVENT_HANDLE_STATE :
623
623
"""
624
624
Called once whenever a mouse button gets released.
625
625
@@ -642,9 +642,11 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> bool
642
642
Bitwise 'and' of all modifiers (shift, ctrl, num lock)
643
643
active during this event. See :ref:`keyboard_modifiers`.
644
644
"""
645
- return False
645
+ return EVENT_UNHANDLED
646
646
647
- def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ) -> bool | None :
647
+ def on_mouse_scroll (
648
+ self , x : int , y : int , scroll_x : float , scroll_y : float
649
+ ) -> EVENT_HANDLE_STATE :
648
650
"""
649
651
Called repeatedly while a mouse scroll wheel moves.
650
652
@@ -676,7 +678,7 @@ def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> bool
676
678
scroll_y:
677
679
Number of steps scrolled vertically since the last call of this function
678
680
"""
679
- return False
681
+ return EVENT_UNHANDLED
680
682
681
683
def set_mouse_visible (self , visible : bool = True ) -> None :
682
684
"""
@@ -724,7 +726,7 @@ def on_action(self, action_name: str, state) -> None:
724
726
"""
725
727
pass
726
728
727
- def on_key_press (self , symbol : int , modifiers : int ) -> bool | None :
729
+ def on_key_press (self , symbol : int , modifiers : int ) -> EVENT_HANDLE_STATE :
728
730
"""
729
731
Called once when a key gets pushed down.
730
732
@@ -741,9 +743,9 @@ def on_key_press(self, symbol: int, modifiers: int) -> bool | None:
741
743
Bitwise 'and' of all modifiers (shift, ctrl, num lock)
742
744
active during this event. See :ref:`keyboard_modifiers`.
743
745
"""
744
- return False
746
+ return EVENT_UNHANDLED
745
747
746
- def on_key_release (self , symbol : int , modifiers : int ) -> bool | None :
748
+ def on_key_release (self , symbol : int , modifiers : int ) -> EVENT_HANDLE_STATE :
747
749
"""
748
750
Called once when a key gets released.
749
751
@@ -763,9 +765,9 @@ def on_key_release(self, symbol: int, modifiers: int) -> bool | None:
763
765
ctrl, num lock) active during this event.
764
766
See :ref:`keyboard_modifiers`.
765
767
"""
766
- return False
768
+ return EVENT_UNHANDLED
767
769
768
- def on_draw (self ) -> bool | None :
770
+ def on_draw (self ) -> EVENT_HANDLE_STATE :
769
771
"""
770
772
Override this function to add your custom drawing code.
771
773
@@ -781,9 +783,9 @@ def on_draw(self) -> bool | None:
781
783
self ._start_finish_render_data .draw ()
782
784
return True
783
785
784
- return False
786
+ return EVENT_UNHANDLED
785
787
786
- def _on_resize (self , width : int , height : int ) -> bool | None :
788
+ def _on_resize (self , width : int , height : int ) -> EVENT_HANDLE_STATE :
787
789
"""
788
790
The internal method called when the window is resized.
789
791
@@ -799,9 +801,9 @@ def _on_resize(self, width: int, height: int) -> bool | None:
799
801
# Retain viewport
800
802
self .viewport = (0 , 0 , width , height )
801
803
802
- return False
804
+ return EVENT_UNHANDLED
803
805
804
- def on_resize (self , width : int , height : int ) -> bool | None :
806
+ def on_resize (self , width : int , height : int ) -> EVENT_HANDLE_STATE :
805
807
"""
806
808
Override this method to add custom actions when the window is resized.
807
809
@@ -855,7 +857,7 @@ def get_size(self) -> tuple[int, int]:
855
857
856
858
def get_location (self ) -> tuple [int , int ]:
857
859
"""Get the current X/Y coordinates of the window."""
858
- return super ().get_location ()
860
+ return super ().get_location () # type: ignore # Window typed at runtime
859
861
860
862
def set_visible (self , visible : bool = True ):
861
863
"""
@@ -1038,34 +1040,34 @@ def flip(self) -> None:
1038
1040
num_collected = self .ctx .gc ()
1039
1041
LOG .debug ("Garbage collected %s OpenGL resource(s)" , num_collected )
1040
1042
1041
- super ().flip ()
1043
+ super ().flip () # type: ignore # Window typed at runtime
1042
1044
1043
1045
def switch_to (self ) -> None :
1044
1046
"""Switch the this window context.
1045
1047
1046
1048
This is normally only used in multi-window applications.
1047
1049
"""
1048
- super ().switch_to ()
1050
+ super ().switch_to () # type: ignore # Window typed at runtime
1049
1051
1050
1052
def set_caption (self , caption ) -> None :
1051
1053
"""Set the caption/title of the window."""
1052
- super ().set_caption (caption )
1054
+ super ().set_caption (caption ) # type: ignore # Window typed at runtime
1053
1055
1054
1056
def set_location (self , x , y ) -> None :
1055
1057
"""Set location of the window."""
1056
- super ().set_location (x , y )
1058
+ super ().set_location (x , y ) # type: ignore # Window typed at runtime
1057
1059
1058
1060
def activate (self ) -> None :
1059
1061
"""Activate this window."""
1060
- super ().activate ()
1062
+ super ().activate () # type: ignore # Window typed at runtime
1061
1063
1062
1064
def minimize (self ) -> None :
1063
1065
"""Minimize the window."""
1064
- super ().minimize ()
1066
+ super ().minimize () # type: ignore # Window typed at runtime
1065
1067
1066
1068
def maximize (self ) -> None :
1067
1069
"""Maximize the window."""
1068
- super ().maximize ()
1070
+ super ().maximize () # type: ignore # Window typed at runtime
1069
1071
1070
1072
def set_vsync (self , vsync : bool ) -> None :
1071
1073
"""Set if we sync our draws to the monitors vertical sync rate."""
@@ -1097,9 +1099,9 @@ def get_system_mouse_cursor(self, name) -> MouseCursor:
1097
1099
1098
1100
def dispatch_events (self ) -> None :
1099
1101
"""Dispatch events"""
1100
- super ().dispatch_events ()
1102
+ super ().dispatch_events () # type: ignore # Window typed at runtime
1101
1103
1102
- def on_mouse_enter (self , x : int , y : int ) -> bool | None :
1104
+ def on_mouse_enter (self , x : int , y : int ) -> EVENT_HANDLE_STATE :
1103
1105
"""
1104
1106
Called once whenever the mouse enters the window area on screen.
1105
1107
@@ -1112,7 +1114,7 @@ def on_mouse_enter(self, x: int, y: int) -> bool | None:
1112
1114
"""
1113
1115
pass
1114
1116
1115
- def on_mouse_leave (self , x : int , y : int ) -> bool | None :
1117
+ def on_mouse_leave (self , x : int , y : int ) -> EVENT_HANDLE_STATE :
1116
1118
"""
1117
1119
Called once whenever the mouse leaves the window area on screen.
1118
1120
@@ -1183,6 +1185,15 @@ def fixed_delta_time(self) -> float:
1183
1185
"""The configured fixed update rate"""
1184
1186
return self ._fixed_rate
1185
1187
1188
+ # required because pyglet marks the method as abstract methods,
1189
+ # but resolves class during runtime
1190
+ def _create (self ) -> None :
1191
+ """Internal method to create the window."""
1192
+ super ()._create () # type: ignore
1193
+
1194
+ def _recreate (self , changes : Sequence [str ]) -> None :
1195
+ super ()._recreate (changes ) # type: ignore
1196
+
1186
1197
1187
1198
def open_window (
1188
1199
width : int ,
0 commit comments