88import logging
99import os
1010import time
11- from typing import TYPE_CHECKING
11+ from typing import TYPE_CHECKING , Sequence
1212
1313import pyglet
1414import pyglet .gl as gl
1515import pyglet .window .mouse
1616from pyglet .display .base import Screen , ScreenMode
17+ from pyglet .event import EVENT_HANDLE_STATE , EVENT_UNHANDLED
1718from pyglet .window import MouseCursor
1819
1920import arcade
2930 from arcade .camera .default import DefaultProjector
3031 from arcade .start_finish_data import StartFinishRenderData
3132
32-
3333LOG = logging .getLogger (__name__ )
3434
3535MOUSE_BUTTON_LEFT = 1
@@ -180,7 +180,7 @@ def __init__(
180180 # Attempt to make window with antialiasing
181181 if antialiasing :
182182 try :
183- config = pyglet . gl .Config (
183+ config = gl .Config (
184184 major_version = gl_version [0 ],
185185 minor_version = gl_version [1 ],
186186 opengl_api = gl_api , # type: ignore # pending: upstream fix
@@ -204,7 +204,7 @@ def __init__(
204204 antialiasing = False
205205 # If we still don't have a config
206206 if not config :
207- config = pyglet . gl .Config (
207+ config = gl .Config (
208208 major_version = gl_version [0 ],
209209 minor_version = gl_version [1 ],
210210 opengl_api = gl_api , # type: ignore # pending: upstream fix
@@ -239,7 +239,7 @@ def __init__(
239239 if antialiasing :
240240 try :
241241 gl .glEnable (gl .GL_MULTISAMPLE_ARB )
242- except pyglet . gl .GLException :
242+ except gl .GLException :
243243 LOG .warning ("Warning: Anti-aliasing not supported on this computer." )
244244
245245 _setup_clock ()
@@ -338,7 +338,7 @@ def ctx(self) -> ArcadeContext:
338338 """
339339 return self ._ctx
340340
341- def clear (
341+ def clear ( # type: ignore # not sure what to do here, BaseWindow.clear is static
342342 self ,
343343 color : RGBOrA255 | None = None ,
344344 color_normalized : RGBANormalized | None = None ,
@@ -554,7 +554,7 @@ def set_draw_rate(self, rate: float) -> None:
554554 pyglet .clock .unschedule (pyglet .app .event_loop ._redraw_windows )
555555 pyglet .clock .schedule_interval (pyglet .app .event_loop ._redraw_windows , self ._draw_rate )
556556
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 :
558558 """
559559 Called repeatedly while the mouse is moving in the window area.
560560
@@ -568,7 +568,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> bool | None:
568568 """
569569 pass
570570
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 :
572572 """
573573 Called once whenever a mouse button gets pressed down.
574574
@@ -596,7 +596,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> bool |
596596
597597 def on_mouse_drag (
598598 self , x : int , y : int , dx : int , dy : int , buttons : int , modifiers : int
599- ) -> bool | None :
599+ ) -> EVENT_HANDLE_STATE :
600600 """
601601 Called repeatedly while the mouse moves with a button down.
602602
@@ -619,7 +619,7 @@ def on_mouse_drag(
619619 """
620620 return self .on_mouse_motion (x , y , dx , dy )
621621
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 :
623623 """
624624 Called once whenever a mouse button gets released.
625625
@@ -642,9 +642,11 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> bool
642642 Bitwise 'and' of all modifiers (shift, ctrl, num lock)
643643 active during this event. See :ref:`keyboard_modifiers`.
644644 """
645- return False
645+ return EVENT_UNHANDLED
646646
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 :
648650 """
649651 Called repeatedly while a mouse scroll wheel moves.
650652
@@ -676,7 +678,7 @@ def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> bool
676678 scroll_y:
677679 Number of steps scrolled vertically since the last call of this function
678680 """
679- return False
681+ return EVENT_UNHANDLED
680682
681683 def set_mouse_visible (self , visible : bool = True ) -> None :
682684 """
@@ -724,7 +726,7 @@ def on_action(self, action_name: str, state) -> None:
724726 """
725727 pass
726728
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 :
728730 """
729731 Called once when a key gets pushed down.
730732
@@ -741,9 +743,9 @@ def on_key_press(self, symbol: int, modifiers: int) -> bool | None:
741743 Bitwise 'and' of all modifiers (shift, ctrl, num lock)
742744 active during this event. See :ref:`keyboard_modifiers`.
743745 """
744- return False
746+ return EVENT_UNHANDLED
745747
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 :
747749 """
748750 Called once when a key gets released.
749751
@@ -763,9 +765,9 @@ def on_key_release(self, symbol: int, modifiers: int) -> bool | None:
763765 ctrl, num lock) active during this event.
764766 See :ref:`keyboard_modifiers`.
765767 """
766- return False
768+ return EVENT_UNHANDLED
767769
768- def on_draw (self ) -> bool | None :
770+ def on_draw (self ) -> EVENT_HANDLE_STATE :
769771 """
770772 Override this function to add your custom drawing code.
771773
@@ -781,9 +783,9 @@ def on_draw(self) -> bool | None:
781783 self ._start_finish_render_data .draw ()
782784 return True
783785
784- return False
786+ return EVENT_UNHANDLED
785787
786- def _on_resize (self , width : int , height : int ) -> bool | None :
788+ def _on_resize (self , width : int , height : int ) -> EVENT_HANDLE_STATE :
787789 """
788790 The internal method called when the window is resized.
789791
@@ -799,9 +801,9 @@ def _on_resize(self, width: int, height: int) -> bool | None:
799801 # Retain viewport
800802 self .viewport = (0 , 0 , width , height )
801803
802- return False
804+ return EVENT_UNHANDLED
803805
804- def on_resize (self , width : int , height : int ) -> bool | None :
806+ def on_resize (self , width : int , height : int ) -> EVENT_HANDLE_STATE :
805807 """
806808 Override this method to add custom actions when the window is resized.
807809
@@ -855,7 +857,7 @@ def get_size(self) -> tuple[int, int]:
855857
856858 def get_location (self ) -> tuple [int , int ]:
857859 """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
859861
860862 def set_visible (self , visible : bool = True ):
861863 """
@@ -1038,34 +1040,34 @@ def flip(self) -> None:
10381040 num_collected = self .ctx .gc ()
10391041 LOG .debug ("Garbage collected %s OpenGL resource(s)" , num_collected )
10401042
1041- super ().flip ()
1043+ super ().flip () # type: ignore # Window typed at runtime
10421044
10431045 def switch_to (self ) -> None :
10441046 """Switch the this window context.
10451047
10461048 This is normally only used in multi-window applications.
10471049 """
1048- super ().switch_to ()
1050+ super ().switch_to () # type: ignore # Window typed at runtime
10491051
10501052 def set_caption (self , caption ) -> None :
10511053 """Set the caption/title of the window."""
1052- super ().set_caption (caption )
1054+ super ().set_caption (caption ) # type: ignore # Window typed at runtime
10531055
10541056 def set_location (self , x , y ) -> None :
10551057 """Set location of the window."""
1056- super ().set_location (x , y )
1058+ super ().set_location (x , y ) # type: ignore # Window typed at runtime
10571059
10581060 def activate (self ) -> None :
10591061 """Activate this window."""
1060- super ().activate ()
1062+ super ().activate () # type: ignore # Window typed at runtime
10611063
10621064 def minimize (self ) -> None :
10631065 """Minimize the window."""
1064- super ().minimize ()
1066+ super ().minimize () # type: ignore # Window typed at runtime
10651067
10661068 def maximize (self ) -> None :
10671069 """Maximize the window."""
1068- super ().maximize ()
1070+ super ().maximize () # type: ignore # Window typed at runtime
10691071
10701072 def set_vsync (self , vsync : bool ) -> None :
10711073 """Set if we sync our draws to the monitors vertical sync rate."""
@@ -1097,9 +1099,9 @@ def get_system_mouse_cursor(self, name) -> MouseCursor:
10971099
10981100 def dispatch_events (self ) -> None :
10991101 """Dispatch events"""
1100- super ().dispatch_events ()
1102+ super ().dispatch_events () # type: ignore # Window typed at runtime
11011103
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 :
11031105 """
11041106 Called once whenever the mouse enters the window area on screen.
11051107
@@ -1112,7 +1114,7 @@ def on_mouse_enter(self, x: int, y: int) -> bool | None:
11121114 """
11131115 pass
11141116
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 :
11161118 """
11171119 Called once whenever the mouse leaves the window area on screen.
11181120
@@ -1183,6 +1185,15 @@ def fixed_delta_time(self) -> float:
11831185 """The configured fixed update rate"""
11841186 return self ._fixed_rate
11851187
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+
11861197
11871198def open_window (
11881199 width : int ,
0 commit comments