Skip to content

Commit 6e8259d

Browse files
pushfooeinarf
andauthored
Pyglet2.1dev$VERSION updates (#2226)
* Bump to pyglet == 2.1dev3 * Remove del trick for getting future vec behavior * Update to options object * Switch arcade/__init__.py to use OOP options object * Convert applications.py to OOP pyglet options * Convert doc on headless to use options object * Fix a comment in arcade/__init__.py * Update tests/__init__.py * Fix formatting * Type compatibility fix in controller db loading * Use pyglet.media.Source instead of a Union type * Fix color typing in arcade.Text * Ignore over-strict pyright Literal opinion * Attempt to patch up the font loader * Use new-style | None in application.Window.__init__ * Update some typing for set_fullscreen * Use new-style | None * Add casting and TODO on resolving screen coord issues upstream * Mention rounding issue in set_fullscreen * Add temporary type ignore for font_size * Update type + doc for arcade.text bold support * Update top-level docstring * Update bold setter & getter * Update bold return types * Temporarily use pyglet development branch directly * Use development pyglet in rolling release mode + comment it * Add commented-out future pyglet == 2.1dev4 release we can swap to it later * Formatting * Use newly released pyglet==2.1dev4 * Projection funcs: remove inner tuple for Mat4 init * add dot to pyproject.toml (no idea why pip resolves that) * Use Vec3 for now in perspective example * Centralize headless + add some type: ignore * Centralize headless * Add some type: ignore since pyglet did vague .pyi * type: ignore in sound.py * Whoops, forgot what file I'm in * Replace todo with # type: ignore # pending syntax * Awful temp fix for Text.font_name * Formatting for sound * Abomination of a test fix * Import sorting for arcade/__init__.py * Revert "Abomination of a test fix" (Test not actually fixed) This reverts commit c59d674. * Maybe fix the import test? * Temp fix for pyglet typing all things as float for some reason * Fix another instance of pyglet making everything a float * Out of patience for pyglet import / metaclass / method resolution * Fix rebase issue in casting * Type ignore window issues * Tweak pyproject.toml * Ignore pyglet Window type The class is dynamically assigned at runtime so pyright can't handle it. * Wrong typing for screen * format issue * Bump pyright * Temp ignore EventDispatcher issue --------- Co-authored-by: Einar Forselv <[email protected]>
1 parent e15946b commit 6e8259d

File tree

18 files changed

+140
-98
lines changed

18 files changed

+140
-98
lines changed

arcade/__init__.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Error out if we import Arcade with an incompatible version of Python.
1111
import sys
1212
import os
13-
from typing import Optional
13+
from typing import Final, Optional
1414

1515
from pathlib import Path
1616

@@ -58,29 +58,21 @@ def configure_logging(level: Optional[int] = None):
5858
# noinspection PyPep8
5959
import pyglet
6060

61-
# TODO: Remove ASAP after pyglet >= 2.1dev2 is out
62-
if pyglet.version == "2.1.dev2":
63-
# Temporary monkeypatch via deletion since dev2 still includes
64-
# overly-specific __eq__ behavior. Later pyglet commits restore
65-
# equality with same-valued tuples by deleting the __eq__ methods.
66-
from pyglet import math as _pyglet_math
67-
68-
del _pyglet_math.Vec2.__eq__
69-
del _pyglet_math.Vec3.__eq__
70-
del _pyglet_math.Vec4.__eq__
7161

7262
# Env variable shortcut for headless mode
73-
if os.environ.get("ARCADE_HEADLESS"):
74-
pyglet.options["headless"] = True
63+
headless: Final[bool] = bool(os.environ.get("ARCADE_HEADLESS"))
64+
if headless:
65+
pyglet.options.headless = headless # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164
66+
7567

7668
from arcade import utils
7769

7870
# Disable shadow window on macs and in headless mode.
7971
if sys.platform == "darwin" or os.environ.get("ARCADE_HEADLESS") or utils.is_raspberry_pi():
80-
pyglet.options["shadow_window"] = False
72+
pyglet.options.shadow_window = False # type: ignore # pending https://github.com/pyglet/pyglet/issues/1164
8173

8274
# Use the old gdi fonts on windows until directwrite is fast/stable
83-
# pyglet.options['win32_gdi_font'] = True
75+
# pyglet.options.win32_gdi_font = True
8476

8577
# Imports from modules that don't do anything circular
8678

@@ -152,7 +144,7 @@ def configure_logging(level: Optional[int] = None):
152144
from .screenshot import get_pixel
153145

154146
# We don't have joysticks game controllers in headless mode
155-
if not pyglet.options["headless"]:
147+
if not headless: # type: ignore
156148
from .joysticks import get_game_controllers
157149
from .joysticks import get_joysticks
158150
from .controller import ControllerManager
@@ -407,11 +399,12 @@ def configure_logging(level: Optional[int] = None):
407399
# Piggyback on pyglet's doc run detection
408400
if not getattr(sys, "is_pyglet_doc_run", False):
409401
# Load additional game controller mappings to Pyglet
410-
if not pyglet.options["headless"]:
402+
if not headless:
411403
try:
412404
import pyglet.input.controller
413405

414406
mappings_file = resources.resolve(":system:gamecontrollerdb.txt")
415-
pyglet.input.controller.add_mappings_from_file(mappings_file)
407+
# TODO: remove string conversion once fixed upstream
408+
pyglet.input.controller.add_mappings_from_file(str(mappings_file))
416409
except AssertionError:
417410
pass

arcade/application.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ def __init__(
132132
self,
133133
width: int = 1280,
134134
height: int = 720,
135-
title: Optional[str] = "Arcade Window",
135+
title: str | None = "Arcade Window",
136136
fullscreen: bool = False,
137137
resizable: bool = False,
138138
update_rate: float = 1 / 60,
139139
antialiasing: bool = True,
140140
gl_version: tuple[int, int] = (3, 3),
141-
screen: Optional[pyglet.display.Screen] = None,
142-
style: Optional[str] = pyglet.window.Window.WINDOW_STYLE_DEFAULT,
141+
screen: pyglet.display.Screen | None = None,
142+
style: str | None = pyglet.window.Window.WINDOW_STYLE_DEFAULT,
143143
visible: bool = True,
144144
vsync: bool = False,
145145
gc_mode: str = "context_gc",
@@ -149,7 +149,7 @@ def __init__(
149149
gl_api: str = "gl",
150150
draw_rate: float = 1 / 60,
151151
fixed_rate: float = 1.0 / 60.0,
152-
fixed_frame_cap: Optional[int] = None,
152+
fixed_frame_cap: int | None = None,
153153
) -> None:
154154
# In certain environments we can't have antialiasing/MSAA enabled.
155155
# Detect replit environment
@@ -161,7 +161,7 @@ def __init__(
161161
gl_version = 3, 1
162162
gl_api = "gles"
163163

164-
self.headless: bool = pyglet.options.get("headless") is True
164+
self.headless: bool = arcade.headless
165165
"""If True, the window is running in headless mode."""
166166

167167
config = None
@@ -171,7 +171,7 @@ def __init__(
171171
config = pyglet.gl.Config(
172172
major_version=gl_version[0],
173173
minor_version=gl_version[1],
174-
opengl_api=gl_api,
174+
opengl_api=gl_api, # type: ignore # pending: upstream fix
175175
double_buffer=True,
176176
sample_buffers=1,
177177
samples=samples,
@@ -183,7 +183,7 @@ def __init__(
183183
alpha_size=8,
184184
)
185185
display = pyglet.display.get_display()
186-
screen = display.get_default_screen()
186+
screen = display.get_default_screen() # type: ignore # pending: resolve upstream type tricks
187187
if screen:
188188
config = screen.get_best_config(config)
189189
except pyglet.window.NoSuchConfigException:
@@ -195,7 +195,7 @@ def __init__(
195195
config = pyglet.gl.Config(
196196
major_version=gl_version[0],
197197
minor_version=gl_version[1],
198-
opengl_api=gl_api,
198+
opengl_api=gl_api, # type: ignore # pending: upstream fix
199199
double_buffer=True,
200200
depth_size=24,
201201
stencil_size=8,
@@ -215,9 +215,10 @@ def __init__(
215215
visible=visible,
216216
style=style,
217217
)
218-
self.register_event_type("on_update")
219-
self.register_event_type("on_action")
220-
self.register_event_type("on_fixed_update")
218+
# pending: weird import tricks resolved
219+
self.register_event_type("on_update") # type: ignore
220+
self.register_event_type("on_action") # type: ignore
221+
self.register_event_type("on_fixed_update") # type: ignore
221222
except pyglet.window.NoSuchConfigException:
222223
raise NoOpenGLException(
223224
"Unable to create an OpenGL 3.3+ context. "
@@ -291,7 +292,7 @@ def __init__(
291292
if enable_polling:
292293
self.keyboard = pyglet.window.key.KeyStateHandler()
293294

294-
if pyglet.options["headless"]:
295+
if arcade.headless:
295296
self.push_handlers(self.keyboard)
296297

297298
else:
@@ -412,10 +413,10 @@ def close(self) -> None:
412413
def set_fullscreen(
413414
self,
414415
fullscreen: bool = True,
415-
screen: Optional["Window"] = None,
416-
mode: Optional[ScreenMode] = None,
417-
width: Optional[int] = None,
418-
height: Optional[int] = None,
416+
screen=None,
417+
mode: ScreenMode | None = None,
418+
width: float | None = None,
419+
height: float | None = None,
419420
) -> None:
420421
"""
421422
Change the fullscreen status of the window.
@@ -438,10 +439,18 @@ def set_fullscreen(
438439
have been obtained by enumerating `Screen.get_modes`. If
439440
None, an appropriate mode will be selected from the given
440441
`width` and `height`.
441-
width (int, optional): Override the width of the window
442-
height (int, optional): Override the height of the window
443-
"""
444-
super().set_fullscreen(fullscreen, screen, mode, width, height)
442+
width: Override the width of the window. Will be rounded to
443+
:py:attr:`int`.
444+
height: Override the height of the window. Will be rounded to
445+
:py:attr:`int`.
446+
"""
447+
# fmt: off
448+
super().set_fullscreen(
449+
fullscreen, screen, mode,
450+
# TODO: resolve the upstream int / float screen coord issue
451+
None if width is None else int(width),
452+
None if height is None else int(height))
453+
# fmt: on
445454

446455
def center_window(self) -> None:
447456
"""Center the window on your desktop."""

arcade/camera/projection_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def generate_view_matrix(camera_data: CameraData) -> Mat4:
2727
po = Vec3(*camera_data.position)
2828

2929
# fmt: off
30-
return Mat4((
30+
return Mat4(
3131
ri.x, up.x, -fo.x, 0.0,
3232
ri.y, up.y, -fo.y, 0.0,
3333
ri.z, up.z, -fo.z, 0.0,
3434
-ri.dot(po), -up.dot(po), fo.dot(po), 1.0
35-
))
35+
)
3636
# fmt: on
3737

3838

@@ -69,12 +69,12 @@ def generate_orthographic_matrix(
6969
tz = -(z_far + z_near) / depth
7070

7171
# fmt: off
72-
return Mat4((
72+
return Mat4(
7373
sx, 0.0, 0.0, 0.0,
7474
0.0, sy, 0.0, 0.0,
7575
0.0, 0.0, sz, 0.0,
7676
tx, ty, tz, 1.0
77-
))
77+
)
7878
# fmt: on
7979

8080

@@ -110,12 +110,12 @@ def generate_perspective_matrix(
110110
h = 2 * z_near / height
111111

112112
# fmt: off
113-
return Mat4((
113+
return Mat4(
114114
w, 0, 0, 0,
115115
0, h, 0, 0,
116116
0, 0, q, -1,
117117
0, 0, qn, 0
118-
))
118+
)
119119
# fmt: on
120120

121121

arcade/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ class ArcadeContext(Context):
4848
atlas_size: tuple[int, int] = 512, 512
4949

5050
def __init__(
51-
self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl"
51+
self,
52+
window: pyglet.window.Window, # type: ignore
53+
gc_mode: str = "context_gc",
54+
gl_api: str = "gl",
5255
) -> None:
5356
super().__init__(window, gc_mode=gc_mode, gl_api=gl_api)
5457

arcade/examples/perspective.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from array import array
1919

2020
import arcade
21-
from pyglet.math import Mat4
21+
from pyglet.math import Mat4, Vec3
2222
from arcade.gl import BufferDescription
2323

2424

@@ -121,8 +121,8 @@ def on_draw(self):
121121
self.fbo.color_attachments[0].use(unit=0)
122122

123123
# Move the plane into camera view and rotate it
124-
translate = Mat4.from_translation((0, 0, -2))
125-
rotate = Mat4.from_rotation(self.time / 2, (1, 0, 0))
124+
translate = Mat4.from_translation(Vec3(0, 0, -2))
125+
rotate = Mat4.from_rotation(self.time / 2, Vec3(1, 0, 0))
126126
self.program["model"] = translate @ rotate
127127

128128
# Scroll the texture coordinates

arcade/gl/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ class Context:
183183
_valid_apis = ("gl", "gles")
184184

185185
def __init__(
186-
self, window: pyglet.window.Window, gc_mode: str = "context_gc", gl_api: str = "gl"
186+
self,
187+
window: pyglet.window.Window, # type: ignore
188+
gc_mode: str = "context_gc",
189+
gl_api: str = "gl",
187190
):
188191
self._window_ref = weakref.ref(window)
189192
if gl_api not in self._valid_apis:

arcade/gui/constructs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
raise ValueError("At least a single value has to be available for `buttons`")
4747

4848
super().__init__(size_hint=(1, 1))
49-
self.register_event_type("on_action")
49+
self.register_event_type("on_action") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
5050

5151
space = 20
5252

@@ -136,7 +136,7 @@ def __init__(
136136
space_between=space_between,
137137
style=style,
138138
)
139-
self.register_event_type("on_action")
139+
self.register_event_type("on_action") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
140140

141141
self.button_factory = button_factory
142142

arcade/gui/ui_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(self, window: Optional[arcade.Window] = None):
9999
self._render_to_surface_camera = arcade.Camera2D()
100100
# this camera is used for rendering the UI and should not be changed by the user
101101

102-
self.register_event_type("on_event")
102+
self.register_event_type("on_event") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
103103

104104
def add(self, widget: W, *, index=None, layer=0) -> W:
105105
"""

arcade/gui/widgets/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def __init__(
9999
self.size_hint_min = size_hint_min
100100
self.size_hint_max = size_hint_max
101101

102-
self.register_event_type("on_event")
103-
self.register_event_type("on_update")
102+
self.register_event_type("on_event") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
103+
self.register_event_type("on_update") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
104104

105105
for child in children:
106106
self.add(child)
@@ -516,7 +516,7 @@ def __init__(
516516
size_hint_max=size_hint_max,
517517
**kwargs,
518518
)
519-
self.register_event_type("on_click")
519+
self.register_event_type("on_click") # type: ignore
520520

521521
self.interaction_buttons = interaction_buttons
522522

arcade/gui/widgets/dropdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(
100100
# add children after super class setup
101101
self.add(self._default_button)
102102

103-
self.register_event_type("on_change")
103+
self.register_event_type("on_change") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
104104

105105
self.with_border(color=arcade.color.RED)
106106

0 commit comments

Comments
 (0)