8
8
import logging
9
9
import os
10
10
import time
11
- from typing import TYPE_CHECKING , Optional
11
+ from typing import TYPE_CHECKING
12
12
13
13
import pyglet
14
14
import pyglet .gl as gl
@@ -260,13 +260,13 @@ def __init__(
260
260
self ._ctx : ArcadeContext = ArcadeContext (self , gc_mode = gc_mode , gl_api = gl_api )
261
261
self ._background_color : Color = TRANSPARENT_BLACK
262
262
263
- self ._current_view : Optional [ View ] = None
263
+ self ._current_view : View | None = None
264
264
265
265
# See if we should center the window
266
266
if center_window :
267
267
self .center_window ()
268
268
269
- self .keyboard : Optional [ pyglet .window .key .KeyStateHandler ] = None
269
+ self .keyboard : pyglet .window .key .KeyStateHandler | None = None
270
270
"""
271
271
A pyglet KeyStateHandler that can be used to poll the state of the keyboard.
272
272
@@ -275,7 +275,7 @@ def __init__(
275
275
if self.window.keyboard[key.SPACE]:
276
276
print("The space key is currently being held down.")
277
277
"""
278
- self .mouse : Optional [ pyglet .window .mouse .MouseStateHandler ] = None
278
+ self .mouse : pyglet .window .mouse .MouseStateHandler | None = None
279
279
"""
280
280
A pyglet MouseStateHandler that can be used to poll the state of the mouse.
281
281
@@ -306,10 +306,10 @@ def __init__(
306
306
# These are typically functions just at module level wrapped in
307
307
# start_render and finish_render calls. The framebuffer is repeatedly
308
308
# rendered to the window when the event loop starts.
309
- self ._start_finish_render_data : Optional [ StartFinishRenderData ] = None
309
+ self ._start_finish_render_data : StartFinishRenderData | None = None
310
310
311
311
@property
312
- def current_view (self ) -> Optional [ " View" ] :
312
+ def current_view (self ) -> View | None :
313
313
"""
314
314
The currently active view.
315
315
@@ -330,9 +330,9 @@ def ctx(self) -> ArcadeContext:
330
330
331
331
def clear (
332
332
self ,
333
- color : Optional [ RGBOrA255 ] = None ,
334
- color_normalized : Optional [ RGBANormalized ] = None ,
335
- viewport : Optional [ tuple [int , int , int , int ]] = None ,
333
+ color : RGBOrA255 | None = None ,
334
+ color_normalized : RGBANormalized | None = None ,
335
+ viewport : tuple [int , int , int , int ] | None = None ,
336
336
) -> None :
337
337
"""
338
338
Clears the window with the configured background color
@@ -461,7 +461,7 @@ def center_window(self) -> None:
461
461
# Center the window
462
462
self .set_location ((screen_width - window_width ) // 2 , (screen_height - window_height ) // 2 )
463
463
464
- def on_update (self , delta_time : float ) -> Optional [ bool ] :
464
+ def on_update (self , delta_time : float ) -> bool | None :
465
465
"""
466
466
This method can be implemented and is reserved for game logic.
467
467
Move sprites. Perform collision checks and other game logic.
@@ -535,7 +535,7 @@ def set_draw_rate(self, rate: float) -> None:
535
535
pyglet .clock .unschedule (pyglet .app .event_loop ._redraw_windows )
536
536
pyglet .clock .schedule_interval (pyglet .app .event_loop ._redraw_windows , self ._draw_rate )
537
537
538
- def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> Optional [ bool ] :
538
+ def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> bool | None :
539
539
"""
540
540
Called repeatedly while the mouse is moving in the window area.
541
541
@@ -549,7 +549,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> Optional[bool]:
549
549
"""
550
550
pass
551
551
552
- def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> Optional [ bool ] :
552
+ def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
553
553
"""
554
554
Called once whenever a mouse button gets pressed down.
555
555
@@ -574,7 +574,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> Optiona
574
574
575
575
def on_mouse_drag (
576
576
self , x : int , y : int , dx : int , dy : int , buttons : int , modifiers : int
577
- ) -> Optional [ bool ] :
577
+ ) -> bool | None :
578
578
"""
579
579
Called repeatedly while the mouse moves with a button down.
580
580
@@ -591,7 +591,7 @@ def on_mouse_drag(
591
591
"""
592
592
return self .on_mouse_motion (x , y , dx , dy )
593
593
594
- def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> Optional [ bool ] :
594
+ def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
595
595
"""
596
596
Called once whenever a mouse button gets released.
597
597
@@ -613,7 +613,7 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> Optio
613
613
"""
614
614
return False
615
615
616
- def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ) -> Optional [ bool ] :
616
+ def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ) -> bool | None :
617
617
"""
618
618
Called repeatedly while a mouse scroll wheel moves.
619
619
@@ -689,7 +689,7 @@ def on_action(self, action_name: str, state) -> None:
689
689
"""
690
690
pass
691
691
692
- def on_key_press (self , symbol : int , modifiers : int ) -> Optional [ bool ] :
692
+ def on_key_press (self , symbol : int , modifiers : int ) -> bool | None :
693
693
"""
694
694
Called once when a key gets pushed down.
695
695
@@ -707,7 +707,7 @@ def on_key_press(self, symbol: int, modifiers: int) -> Optional[bool]:
707
707
"""
708
708
return False
709
709
710
- def on_key_release (self , symbol : int , modifiers : int ) -> Optional [ bool ] :
710
+ def on_key_release (self , symbol : int , modifiers : int ) -> bool | None :
711
711
"""
712
712
Called once when a key gets released.
713
713
@@ -729,7 +729,7 @@ def on_key_release(self, symbol: int, modifiers: int) -> Optional[bool]:
729
729
"""
730
730
return False
731
731
732
- def on_draw (self ) -> Optional [ bool ] :
732
+ def on_draw (self ) -> bool | None :
733
733
"""
734
734
Override this function to add your custom drawing code.
735
735
@@ -747,7 +747,7 @@ def on_draw(self) -> Optional[bool]:
747
747
748
748
return False
749
749
750
- def _on_resize (self , width : int , height : int ) -> Optional [ bool ] :
750
+ def _on_resize (self , width : int , height : int ) -> bool | None :
751
751
"""
752
752
The internal method called when the window is resized.
753
753
@@ -765,7 +765,7 @@ def _on_resize(self, width: int, height: int) -> Optional[bool]:
765
765
766
766
return False
767
767
768
- def on_resize (self , width : int , height : int ) -> Optional [ bool ] :
768
+ def on_resize (self , width : int , height : int ) -> bool | None :
769
769
"""
770
770
Override this method to add custom actions when the window is resized.
771
771
@@ -1087,7 +1087,7 @@ def dispatch_events(self) -> None:
1087
1087
"""Dispatch events"""
1088
1088
super ().dispatch_events ()
1089
1089
1090
- def on_mouse_enter (self , x : int , y : int ) -> Optional [ bool ] :
1090
+ def on_mouse_enter (self , x : int , y : int ) -> bool | None :
1091
1091
"""
1092
1092
Called once whenever the mouse enters the window area on screen.
1093
1093
@@ -1100,7 +1100,7 @@ def on_mouse_enter(self, x: int, y: int) -> Optional[bool]:
1100
1100
"""
1101
1101
pass
1102
1102
1103
- def on_mouse_leave (self , x : int , y : int ) -> Optional [ bool ] :
1103
+ def on_mouse_leave (self , x : int , y : int ) -> bool | None :
1104
1104
"""
1105
1105
Called once whenever the mouse leaves the window area on screen.
1106
1106
@@ -1175,7 +1175,7 @@ def fixed_delta_time(self) -> float:
1175
1175
def open_window (
1176
1176
width : int ,
1177
1177
height : int ,
1178
- window_title : Optional [ str ] = None ,
1178
+ window_title : str | None = None ,
1179
1179
resizable : bool = False ,
1180
1180
antialiasing : bool = True ,
1181
1181
) -> Window :
@@ -1214,10 +1214,10 @@ class View:
1214
1214
the current window is used. (Normally you don't need to provide this).
1215
1215
"""
1216
1216
1217
- def __init__ (self , window : Optional [ Window ] = None ) -> None :
1217
+ def __init__ (self , window : Window | None = None ) -> None :
1218
1218
self .window = arcade .get_window () if window is None else window
1219
- self .key : Optional [ int ] = None
1220
- self ._section_manager : Optional [ SectionManager ] = None
1219
+ self .key : int | None = None
1220
+ self ._section_manager : SectionManager | None = None
1221
1221
1222
1222
@property
1223
1223
def section_manager (self ) -> SectionManager :
@@ -1240,8 +1240,8 @@ def has_sections(self) -> bool:
1240
1240
def add_section (
1241
1241
self ,
1242
1242
section : arcade .Section ,
1243
- at_index : Optional [ int ] = None ,
1244
- at_draw_order : Optional [ int ] = None ,
1243
+ at_index : int | None = None ,
1244
+ at_draw_order : int | None = None ,
1245
1245
) -> None :
1246
1246
"""
1247
1247
Adds a section to the view Section Manager.
@@ -1257,9 +1257,9 @@ def add_section(
1257
1257
1258
1258
def clear (
1259
1259
self ,
1260
- color : Optional [ RGBOrA255 ] = None ,
1261
- color_normalized : Optional [ RGBANormalized ] = None ,
1262
- viewport : Optional [ tuple [int , int , int , int ]] = None ,
1260
+ color : RGBOrA255 | None = None ,
1261
+ color_normalized : RGBANormalized | None = None ,
1262
+ viewport : tuple [int , int , int , int ] | None = None ,
1263
1263
) -> None :
1264
1264
"""
1265
1265
Clears the window with the configured background color
@@ -1279,7 +1279,7 @@ def clear(
1279
1279
"""
1280
1280
self .window .clear (color = color , color_normalized = color_normalized , viewport = viewport )
1281
1281
1282
- def on_update (self , delta_time : float ) -> Optional [ bool ] :
1282
+ def on_update (self , delta_time : float ) -> bool | None :
1283
1283
"""
1284
1284
This method can be implemented and is reserved for game logic.
1285
1285
Move sprites. Perform collision checks and other game logic.
@@ -1305,7 +1305,7 @@ def on_fixed_update(self, delta_time: float):
1305
1305
"""
1306
1306
pass
1307
1307
1308
- def on_draw (self ) -> Optional [ bool ] :
1308
+ def on_draw (self ) -> bool | None :
1309
1309
"""
1310
1310
Override this function to add your custom drawing code.
1311
1311
@@ -1329,7 +1329,7 @@ def on_hide_view(self) -> None:
1329
1329
"""Called once when this view is hidden."""
1330
1330
pass
1331
1331
1332
- def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> Optional [ bool ] :
1332
+ def on_mouse_motion (self , x : int , y : int , dx : int , dy : int ) -> bool | None :
1333
1333
"""
1334
1334
Called repeatedly while the mouse is moving in the window area.
1335
1335
@@ -1343,7 +1343,7 @@ def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> Optional[bool]:
1343
1343
"""
1344
1344
pass
1345
1345
1346
- def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> Optional [ bool ] :
1346
+ def on_mouse_press (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
1347
1347
"""
1348
1348
Called once whenever a mouse button gets pressed down.
1349
1349
@@ -1368,7 +1368,7 @@ def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> Optiona
1368
1368
1369
1369
def on_mouse_drag (
1370
1370
self , x : int , y : int , dx : int , dy : int , _buttons : int , _modifiers : int
1371
- ) -> Optional [ bool ] :
1371
+ ) -> bool | None :
1372
1372
"""
1373
1373
Called repeatedly while the mouse moves with a button down.
1374
1374
@@ -1386,7 +1386,7 @@ def on_mouse_drag(
1386
1386
self .on_mouse_motion (x , y , dx , dy )
1387
1387
return False
1388
1388
1389
- def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> Optional [ bool ] :
1389
+ def on_mouse_release (self , x : int , y : int , button : int , modifiers : int ) -> bool | None :
1390
1390
"""
1391
1391
Called once whenever a mouse button gets released.
1392
1392
@@ -1408,7 +1408,7 @@ def on_mouse_release(self, x: int, y: int, button: int, modifiers: int) -> Optio
1408
1408
"""
1409
1409
pass
1410
1410
1411
- def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ) -> Optional [ bool ] :
1411
+ def on_mouse_scroll (self , x : int , y : int , scroll_x : int , scroll_y : int ) -> bool | None :
1412
1412
"""
1413
1413
Called repeatedly while a mouse scroll wheel moves.
1414
1414
@@ -1440,7 +1440,7 @@ def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int) -> Optio
1440
1440
"""
1441
1441
pass
1442
1442
1443
- def on_key_press (self , symbol : int , modifiers : int ) -> Optional [ bool ] :
1443
+ def on_key_press (self , symbol : int , modifiers : int ) -> bool | None :
1444
1444
"""
1445
1445
Called once when a key gets pushed down.
1446
1446
@@ -1458,7 +1458,7 @@ def on_key_press(self, symbol: int, modifiers: int) -> Optional[bool]:
1458
1458
"""
1459
1459
return False
1460
1460
1461
- def on_key_release (self , _symbol : int , _modifiers : int ) -> Optional [ bool ] :
1461
+ def on_key_release (self , _symbol : int , _modifiers : int ) -> bool | None :
1462
1462
"""
1463
1463
Called once when a key gets released.
1464
1464
@@ -1480,7 +1480,7 @@ def on_key_release(self, _symbol: int, _modifiers: int) -> Optional[bool]:
1480
1480
"""
1481
1481
return False
1482
1482
1483
- def on_resize (self , width : int , height : int ) -> Optional [ bool ] :
1483
+ def on_resize (self , width : int , height : int ) -> bool | None :
1484
1484
"""
1485
1485
Override this method to add custom actions when the window is resized.
1486
1486
@@ -1494,7 +1494,7 @@ def on_resize(self, width: int, height: int) -> Optional[bool]:
1494
1494
"""
1495
1495
pass
1496
1496
1497
- def on_mouse_enter (self , x : int , y : int ) -> Optional [ bool ] :
1497
+ def on_mouse_enter (self , x : int , y : int ) -> bool | None :
1498
1498
"""
1499
1499
Called once whenever the mouse enters the window area on screen.
1500
1500
@@ -1507,7 +1507,7 @@ def on_mouse_enter(self, x: int, y: int) -> Optional[bool]:
1507
1507
"""
1508
1508
pass
1509
1509
1510
- def on_mouse_leave (self , x : int , y : int ) -> Optional [ bool ] :
1510
+ def on_mouse_leave (self , x : int , y : int ) -> bool | None :
1511
1511
"""
1512
1512
Called once whenever the mouse leaves the window area on screen.
1513
1513
0 commit comments