Skip to content

Commit 5d0ca3a

Browse files
pushfoopvcravenPaul Craveneruvanoseinarf
authored
Upgrade to pyglet==2.1.0 (#2487)
* Update Pyglet version * Work on updating to rc3 * Fix up text 'bold' for rc3 * Fix for pyright * Swap to pyglet 2.1 * Make linter happy * fix type issues (#2490) * fix tests * fix formating * re-enable HiDPI support * Inconsistent typing * Optimization: Don't use scale property in initializer * Use pyglet.options.audio directly --------- Co-authored-by: Paul Craven <paul@cravenfamily.com> Co-authored-by: Paul Craven <paul.craven@optimizely.com> Co-authored-by: Maic Siemering <maic@siemering.tech> Co-authored-by: Einar Forselv <eforselv@gmail.com>
1 parent 5e800f7 commit 5d0ca3a

22 files changed

+136
-98
lines changed

arcade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def configure_logging(level: int | None = None):
5959

6060
import pyglet
6161

62-
# Enable HiDPI support
62+
# Enable HiDPI support using stretch mode
6363
if os.environ.get("ARCADE_TEST"):
6464
pyglet.options.dpi_scaling = "real"
6565
else:

arcade/application.py

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import logging
99
import os
1010
import time
11-
from typing import TYPE_CHECKING
11+
from typing import TYPE_CHECKING, Sequence
1212

1313
import pyglet
1414
import pyglet.gl as gl
1515
import pyglet.window.mouse
1616
from pyglet.display.base import Screen, ScreenMode
17+
from pyglet.event import EVENT_HANDLE_STATE, EVENT_UNHANDLED
1718
from pyglet.window import MouseCursor
1819

1920
import arcade
@@ -29,7 +30,6 @@
2930
from arcade.camera.default import DefaultProjector
3031
from arcade.start_finish_data import StartFinishRenderData
3132

32-
3333
LOG = logging.getLogger(__name__)
3434

3535
MOUSE_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

11871198
def open_window(
11881199
width: int,

arcade/camera/camera_2d.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,12 @@ def position(self) -> Vec2:
544544
"""The 2D world position of the camera along the X and Y axes."""
545545
return Vec2(self._camera_data.position[0], self._camera_data.position[1])
546546

547+
# Setter with different signature will cause mypy issues
548+
# https://github.com/python/mypy/issues/3004
547549
@position.setter
548550
def position(self, _pos: Point) -> None:
549-
x, y, *z = _pos
550-
z = self._camera_data.position[2] if not z else z[0]
551+
x, y, *_z = _pos
552+
z = self._camera_data.position[2] if not _z else _z[0]
551553
self._camera_data.position = (x, y, z)
552554

553555
@property
@@ -900,7 +902,7 @@ def top_left(self, new_corner: Point2):
900902
left = self.left
901903

902904
x, y = new_corner
903-
self.position = (x - ux * top - rx * left, y - uy * top - ry * left)
905+
self.position = (x - ux * top - rx * left, y - uy * top - ry * left) # type: ignore
904906

905907
# top_center
906908
@property
@@ -918,7 +920,7 @@ def top_center(self, new_top: Point2):
918920
top = self.top
919921

920922
x, y = new_top
921-
self.position = x - ux * top, y - uy * top
923+
self.position = x - ux * top, y - uy * top # type: ignore
922924

923925
# top_right
924926
@property
@@ -942,7 +944,7 @@ def top_right(self, new_corner: Point2):
942944
right = self.right
943945

944946
x, y = new_corner
945-
self.position = (x - ux * top - rx * right, y - uy * top - ry * right)
947+
self.position = (x - ux * top - rx * right, y - uy * top - ry * right) # type: ignore
946948

947949
# center_right
948950
@property
@@ -959,7 +961,7 @@ def center_right(self, new_right: Point2):
959961
right = self.right
960962

961963
x, y = new_right
962-
self.position = x - uy * right, y + ux * right
964+
self.position = x - uy * right, y + ux * right # type: ignore
963965

964966
# bottom_right
965967
@property
@@ -985,7 +987,7 @@ def bottom_right(self, new_corner: Point2):
985987
self.position = (
986988
x - ux * bottom - rx * right,
987989
y - uy * bottom - ry * right,
988-
)
990+
) # type: ignore
989991

990992
# bottom_center
991993
@property
@@ -1003,7 +1005,7 @@ def bottom_center(self, new_bottom: Point2):
10031005
bottom = self.bottom
10041006

10051007
x, y = new_bottom
1006-
self.position = x - ux * bottom, y - uy * bottom
1008+
self.position = x - ux * bottom, y - uy * bottom # type: ignore
10071009

10081010
# bottom_left
10091011
@property
@@ -1027,7 +1029,7 @@ def bottom_left(self, new_corner: Point2):
10271029
left = self.left
10281030

10291031
x, y = new_corner
1030-
self.position = (x - ux * bottom - rx * left, y - uy * bottom - ry * left)
1032+
self.position = x - ux * bottom - rx * left, y - uy * bottom - ry * left # type: ignore
10311033

10321034
# center_left
10331035
@property
@@ -1044,4 +1046,4 @@ def center_left(self, new_left: Point2):
10441046
left = self.left
10451047

10461048
x, y = new_left
1047-
self.position = x - uy * left, y + ux * left
1049+
self.position = Vec2(x - uy * left, y + ux * left)

arcade/camera/default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def unproject(self, screen_coordinate: Point) -> Vec3:
9292
9393
Due to the nature of viewport projector this does not do anything.
9494
"""
95-
x, y, *z = screen_coordinate
96-
z = 0.0 if not z else z[0]
95+
x, y, *_z = screen_coordinate
96+
z = 0.0 if not _z else _z[0]
9797

9898
return Vec3(x, y, z)
9999

0 commit comments

Comments
 (0)