pyglet 2.1.8__py3-none-any.whl → 2.1.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ from ctypes import (
7
7
  POINTER,
8
8
  Array,
9
9
  Structure,
10
+ _Pointer,
10
11
  addressof,
11
12
  byref,
12
13
  c_char_p,
@@ -18,20 +19,20 @@ from ctypes import (
18
19
  memmove,
19
20
  )
20
21
  from dataclasses import dataclass
21
- from typing import BinaryIO, TYPE_CHECKING, Iterator, Sequence
22
-
23
- from _ctypes import _Pointer
22
+ from typing import TYPE_CHECKING, BinaryIO, Iterator, Sequence
24
23
 
25
24
  import pyglet
26
25
  import pyglet.lib
27
26
  from pyglet import image
27
+ from pyglet.media.exceptions import MediaFormatException
28
28
  from pyglet.util import asbytes, asstr
29
+
29
30
  from . import MediaDecoder
30
31
  from .base import AudioData, AudioFormat, SourceInfo, StaticSource, StreamingSource, VideoFormat
31
32
  from .ffmpeg_lib import (
32
33
  AV_CODEC_ID_VP8,
33
34
  AV_CODEC_ID_VP9,
34
- FF_INPUT_BUFFER_PADDING_SIZE,
35
+ AV_INPUT_BUFFER_PADDING_SIZE,
35
36
  SWS_FAST_BILINEAR,
36
37
  AVPacket,
37
38
  SwrContext,
@@ -63,7 +64,6 @@ from .ffmpeg_lib.libavutil import (
63
64
  avutil,
64
65
  )
65
66
  from .ffmpeg_lib.libswresample import swresample, swresample_version
66
- from ..exceptions import MediaFormatException
67
67
 
68
68
  if TYPE_CHECKING:
69
69
  from .ffmpeg_lib.libavformat import AVStream
@@ -128,7 +128,7 @@ def ffmpeg_get_audio_buffer_size(audio_format):
128
128
 
129
129
  Buffer size can accommodate 1 sec of audio data.
130
130
  """
131
- return audio_format.bytes_per_second + FF_INPUT_BUFFER_PADDING_SIZE
131
+ return audio_format.bytes_per_second + AV_INPUT_BUFFER_PADDING_SIZE
132
132
 
133
133
 
134
134
  def ffmpeg_init():
@@ -489,10 +489,7 @@ def ffmpeg_get_packet_pts(file: FFmpegFile, packet: _Pointer[AVPacket]) -> float
489
489
 
490
490
  def ffmpeg_get_frame_ts(stream: FFmpegStream) -> float:
491
491
  ts = stream.frame.contents.best_effort_timestamp
492
- timestamp = avutil.av_rescale_q(ts,
493
- stream.time_base,
494
- AV_TIME_BASE_Q)
495
- return timestamp
492
+ return avutil.av_rescale_q(ts, stream.time_base, AV_TIME_BASE_Q)
496
493
 
497
494
 
498
495
  def ffmpeg_init_packet() -> _Pointer[AVPacket]:
@@ -847,7 +844,7 @@ class FFmpegSource(StreamingSource):
847
844
  # more packets are in stream.
848
845
  return ffmpeg_read(self._file, self._packet)
849
846
 
850
- def _process_packet(self) -> AudioPacket | VideoPacket:
847
+ def _process_packet(self) -> AudioPacket | VideoPacket | None:
851
848
  """Process the packet that has been just read.
852
849
 
853
850
  Determines whether it's a video or audio packet and queue it in the
@@ -859,18 +856,18 @@ class FFmpegSource(StreamingSource):
859
856
 
860
857
  if self._packet.contents.stream_index == self._video_stream_index:
861
858
  video_packet = VideoPacket(self._packet, timestamp)
862
-
863
859
  if _debug:
864
860
  print('Created and queued packet %d (%f)' % (video_packet.id, video_packet.timestamp))
865
861
 
866
862
  self.videoq.append(video_packet)
867
863
  return video_packet
868
864
 
869
- elif self.audio_format and self._packet.contents.stream_index == self._audio_stream_index:
865
+ if self.audio_format and self._packet.contents.stream_index == self._audio_stream_index:
870
866
  audio_packet = AudioPacket(self._packet, timestamp)
871
867
 
872
868
  self.audioq.append(audio_packet)
873
869
  return audio_packet
870
+ return None
874
871
 
875
872
  def get_audio_data(self, num_bytes: int, compensation_time: float=0.0) -> AudioData | None:
876
873
  data = b''
@@ -1040,9 +1037,8 @@ class FFmpegSource(StreamingSource):
1040
1037
  width = self.video_format.width
1041
1038
  height = self.video_format.height
1042
1039
  pitch = width * 4
1043
- # https://ffmpeg.org/doxygen/3.3/group__lavc__decoding.html#ga8f5b632a03ce83ac8e025894b1fc307a
1044
- nbytes = (pitch * height + FF_INPUT_BUFFER_PADDING_SIZE)
1045
- buffer = (c_uint8 * nbytes)()
1040
+ buf_size = avutil.av_image_get_buffer_size(AV_PIX_FMT_RGBA, width, height, 1)
1041
+ buffer = (c_uint8 * buf_size)()
1046
1042
  try:
1047
1043
  result = self._ffmpeg_decode_video(video_packet.packet, buffer)
1048
1044
  except FFmpegException:
@@ -1070,11 +1066,8 @@ class FFmpegSource(StreamingSource):
1070
1066
  stream = self._video_stream
1071
1067
  rgba_ptrs = (POINTER(c_uint8) * 4)()
1072
1068
  rgba_stride = (c_int * 4)()
1073
- width = stream.codec_context.contents.width
1074
- height = stream.codec_context.contents.height
1075
1069
  if stream.type != AVMEDIA_TYPE_VIDEO:
1076
1070
  raise FFmpegException('Trying to decode video on a non-video stream.')
1077
-
1078
1071
  sent_result = avcodec.avcodec_send_packet(
1079
1072
  stream.codec_context,
1080
1073
  packet,
@@ -1097,6 +1090,9 @@ class FFmpegSource(StreamingSource):
1097
1090
  descr = buf.value
1098
1091
  raise FFmpegException(f'Video: Error occurred receiving frame. {descr.decode()}')
1099
1092
 
1093
+ width = stream.frame.contents.width
1094
+ height = stream.frame.contents.height
1095
+
1100
1096
  avutil.av_image_fill_arrays(rgba_ptrs, rgba_stride, data_out,
1101
1097
  AV_PIX_FMT_RGBA, width, height, 1)
1102
1098
 
@@ -1141,7 +1137,7 @@ class FFmpegSource(StreamingSource):
1141
1137
  ts = None
1142
1138
 
1143
1139
  if _debug:
1144
- print('Next video timestamp is', ts)
1140
+ print(f'Next video packet timestamp is: {ts}')
1145
1141
  return ts
1146
1142
 
1147
1143
  def get_next_video_frame(self, skip_empty_frame: bool=True) -> int | None:
@@ -18,6 +18,7 @@ release_versions = {
18
18
  5: {'avcodec': 59, 'avformat': 59, 'avutil': 57, 'swresample': 4, 'swscale': 6}, # 5.x
19
19
  6: {'avcodec': 60, 'avformat': 60, 'avutil': 58, 'swresample': 4, 'swscale': 7}, # 6.x
20
20
  7: {'avcodec': 61, 'avformat': 61, 'avutil': 59, 'swresample': 5, 'swscale': 8}, # 7.x
21
+ 8: {'avcodec': 62, 'avformat': 62, 'avutil': 60, 'swresample': 6, 'swscale': 9}, # 8.x
21
22
  }
22
23
 
23
24
  # Removals done per library and version.
@@ -1,7 +1,7 @@
1
1
  """Wrapper for include/libavcodec/avcodec.h
2
2
  """
3
3
 
4
- from ctypes import c_int, c_uint16, c_int64, c_uint32, c_uint64, c_size_t
4
+ from ctypes import c_int, c_uint16, c_int64, c_uint32, c_uint64, c_size_t, c_char
5
5
  from ctypes import c_uint8, c_uint, c_float, c_char_p
6
6
  from ctypes import c_void_p, POINTER, CFUNCTYPE, Structure
7
7
 
@@ -15,8 +15,8 @@ _debug = debug_print('debug_media')
15
15
 
16
16
  avcodec = pyglet.lib.load_library(
17
17
  'avcodec',
18
- win32=('avcodec-61', 'avcodec-60', 'avcodec-59', 'avcodec-58'),
19
- darwin=('avcodec.61', 'avcodec.60', 'avcodec.59', 'avcodec.58')
18
+ win32=('avcodec-62', 'avcodec-61', 'avcodec-60', 'avcodec-59', 'avcodec-58'),
19
+ darwin=('avcodec.62', 'avcodec.61', 'avcodec.60', 'avcodec.59', 'avcodec.58')
20
20
  )
21
21
 
22
22
  avcodec.avcodec_version.restype = c_int
@@ -25,8 +25,8 @@ avcodec_version = avcodec.avcodec_version() >> 16
25
25
 
26
26
  compat.set_version('avcodec', avcodec_version)
27
27
 
28
-
29
- FF_INPUT_BUFFER_PADDING_SIZE = 32
28
+ # Since version 4.0 this is 64
29
+ AV_INPUT_BUFFER_PADDING_SIZE = 64
30
30
 
31
31
 
32
32
  class AVPacketSideData(Structure):
@@ -67,7 +67,7 @@ AVPacket_Fields = [
67
67
  compat.add_version_changes('avcodec', 58, AVPacket, AVPacket_Fields,
68
68
  removals=('opaque', 'opaque_ref', 'time_base'))
69
69
 
70
- for compat_ver in (59, 60, 61):
70
+ for compat_ver in (59, 60, 61, 62):
71
71
  compat.add_version_changes('avcodec', compat_ver, AVPacket, AVPacket_Fields,
72
72
  removals=('convergence_duration',))
73
73
 
@@ -118,8 +118,9 @@ for compat_ver in (58, 59, 60):
118
118
  compat.add_version_changes('avcodec', compat_ver, AVCodecParameters, AVCodecParameters_Fields,
119
119
  removals=('coded_side_data', 'nb_coded_side_data', 'ch_layout', 'framerate'))
120
120
 
121
- compat.add_version_changes('avcodec', 61, AVCodecParameters, AVCodecParameters_Fields,
122
- removals=('channel_layout', 'channels'))
121
+ for compat_ver in (61, 62):
122
+ compat.add_version_changes('avcodec', compat_ver, AVCodecParameters, AVCodecParameters_Fields,
123
+ removals=('channel_layout', 'channels'))
123
124
 
124
125
 
125
126
  class AVProfile(Structure):
@@ -188,7 +189,7 @@ AVClass = libavutil.AVClass
188
189
  AVFrame = libavutil.AVFrame
189
190
  AV_NUM_DATA_POINTERS = libavutil.AV_NUM_DATA_POINTERS
190
191
 
191
- # Significant deprecation and re-ordering of the entire structure makes it unmanagable to
192
+ # Significant deprecation and re-ordering of the entire structure makes it unmanageable to
192
193
  # track of all the changes via compat module. Re-define the structure and compat the new one going forward.
193
194
  if avcodec_version >= 61:
194
195
  AVCodecContext_Fields = [
@@ -217,7 +218,7 @@ if avcodec_version >= 61:
217
218
  ("framerate", AVRational),
218
219
 
219
220
  # Video fields
220
- ("ticks_per_frame", c_int), # Deprecated in 61.
221
+ ("ticks_per_frame", c_int), # Deprecated in 61. (removed in 62)
221
222
  ("delay", c_int),
222
223
  ("width", c_int),
223
224
  ("height", c_int),
@@ -334,7 +335,7 @@ if avcodec_version >= 61:
334
335
  POINTER(c_int), c_int)),
335
336
  ("profile", c_int),
336
337
  ("level", c_int),
337
- ("properties", c_uint),
338
+ ("properties", c_uint), # deprecated in 62
338
339
  ("skip_loop_filter", c_int), # enum AVDiscard
339
340
  ("skip_idct", c_int), # enum AVDiscard
340
341
  ("skip_frame", c_int), # enum AVDiscard
@@ -364,8 +365,11 @@ if avcodec_version >= 61:
364
365
  ("nb_decoded_side_data", c_int),
365
366
  ]
366
367
 
367
- compat.add_version_changes('avcodec', 61, AVCodecContext, AVCodecContext_Fields, removals=None)
368
+ compat.add_version_changes('avcodec', 61, AVCodecContext, AVCodecContext_Fields,
369
+ removals=None)
368
370
 
371
+ compat.add_version_changes('avcodec', 62, AVCodecContext, AVCodecContext_Fields,
372
+ removals=("ticks_per_frame",))
369
373
  else:
370
374
  AVCodecContext_Fields = [
371
375
  ('av_class', POINTER(AVClass)),
@@ -621,10 +625,10 @@ avcodec.avcodec_find_decoder_by_name.restype = POINTER(AVCodec)
621
625
  avcodec.avcodec_find_decoder_by_name.argtypes = [c_char_p]
622
626
 
623
627
  __all__ = [
624
- 'avcodec',
625
- 'FF_INPUT_BUFFER_PADDING_SIZE',
626
- 'AVPacket',
627
- 'AVCodecContext',
628
628
  'AV_CODEC_ID_VP8',
629
629
  'AV_CODEC_ID_VP9',
630
+ 'AV_INPUT_BUFFER_PADDING_SIZE',
631
+ 'AVCodecContext',
632
+ 'AVPacket',
633
+ 'avcodec',
630
634
  ]
@@ -14,8 +14,8 @@ _debug = debug_print('debug_media')
14
14
 
15
15
  avformat = pyglet.lib.load_library(
16
16
  'avformat',
17
- win32=('avformat-61', 'avformat-60', 'avformat-59', 'avformat-58'),
18
- darwin=('avformat.61', 'avformat.60', 'avformat.59', 'avformat.58')
17
+ win32=('avformat-62', 'avformat-61', 'avformat-60', 'avformat-59', 'avformat-58'),
18
+ darwin=('avformat.62', 'avformat.61', 'avformat.60', 'avformat.59', 'avformat.58')
19
19
  )
20
20
 
21
21
  avformat.avformat_version.restype = c_int
@@ -147,7 +147,7 @@ compat.add_version_changes('avformat', 58, AVStream, AVStream_Fields, removals=(
147
147
  compat.add_version_changes('avformat', 59, AVStream, AVStream_Fields,
148
148
  removals=('av_class', 'codec', 'recommended_encoder_configuration', 'info'))
149
149
 
150
- for compat_ver in (60, 61):
150
+ for compat_ver in (60, 61, 62):
151
151
  compat.add_version_changes('avformat', compat_ver, AVStream, AVStream_Fields,
152
152
  removals=('codec', 'recommended_encoder_configuration', 'info'),
153
153
  repositions=(compat.Reposition("codecpar", "id"),))
@@ -318,8 +318,8 @@ if avformat_version >= 61:
318
318
  ('io_close2', CFUNCTYPE(c_int, POINTER(AVFormatContext), POINTER(AVIOContext))) # Added in 59.
319
319
  ]
320
320
 
321
- compat.add_version_changes('avformat', 61, AVFormatContext, AVFormatContext_Fields, removals=None)
322
-
321
+ for compat_ver in (61, 62):
322
+ compat.add_version_changes('avformat', compat_ver, AVFormatContext, AVFormatContext_Fields, removals=None)
323
323
 
324
324
  else:
325
325
  AVFormatContext_Fields = [
@@ -410,7 +410,7 @@ else:
410
410
  compat.add_version_changes('avformat', 58, AVFormatContext, AVFormatContext_Fields,
411
411
  removals=('skip_estimate_duration_from_pts', 'max_probe_packets', 'io_close2'))
412
412
 
413
- for compat_ver in (59, 60):
413
+ for compat_ver in (59, 60, 61, 62):
414
414
  compat.add_version_changes('avformat', compat_ver, AVFormatContext, AVFormatContext_Fields,
415
415
  removals=('filename', 'internal'))
416
416
 
@@ -12,8 +12,8 @@ _debug = debug_print('debug_media')
12
12
 
13
13
  avutil = pyglet.lib.load_library(
14
14
  'avutil',
15
- win32=('avutil-59', 'avutil-58', 'avutil-57', 'avutil-56'),
16
- darwin=('avutil.59', 'avutil.58', 'avutil.57', 'avutil.56')
15
+ win32=('avutil-60', 'avutil-59', 'avutil-58', 'avutil-57', 'avutil-56'),
16
+ darwin=('avutil.60', 'avutil.59', 'avutil.58', 'avutil.57', 'avutil.56')
17
17
  )
18
18
 
19
19
  avutil.avutil_version.restype = c_int
@@ -148,9 +148,9 @@ AVFrame_Fields = [
148
148
  ('opaque', c_void_p),
149
149
  ('error', c_uint64 * AV_NUM_DATA_POINTERS), # Deprecated. Removed in 57.
150
150
  ('repeat_pict', c_int),
151
- ('interlaced_frame', c_int), # deprecated in 59. Targeted for removal. Use AV_FRAME_FLAG_INTERLACED
152
- ('top_field_first', c_int), # deprecated in 59. Targeted for removal. Use AV_FRAME_FLAG_TOP_FIELD_FIRST
153
- ('palette_has_changed', c_int), # deprecated in 59. Targeted for removal.
151
+ ('interlaced_frame', c_int), # deprecated in 59. Targeted for removal. Use AV_FRAME_FLAG_INTERLACED (removed in 60)
152
+ ('top_field_first', c_int), # deprecated in 59. Targeted for removal. Use AV_FRAME_FLAG_TOP_FIELD_FIRST (removed in 60)
153
+ ('palette_has_changed', c_int), # deprecated in 59. Targeted for removal. (removed in 60)
154
154
  ('reordered_opaque', c_int64), # removed in 59.
155
155
  ('sample_rate', c_int),
156
156
  ('channel_layout', c_uint64), # removed in 59.
@@ -170,7 +170,7 @@ AVFrame_Fields = [
170
170
  ('pkt_duration', c_int64), # removed in 59?
171
171
  ('metadata', POINTER(AVDictionary)),
172
172
  ('decode_error_flags', c_int),
173
- ('channels', c_int),
173
+ ('channels', c_int), # removed in 59.
174
174
  ('pkt_size', c_int), # deprecated in 59. use AV_CODEC_FLAG_COPY_OPAQUE to pass through arbitrary user data from packets to frames
175
175
  ('qscale_table', POINTER(c_int8)), # Deprecated. Removed in 57.
176
176
  ('qstride', c_int), # Deprecated. Removed in 57.
@@ -198,9 +198,18 @@ for compat_ver in (57, 58):
198
198
  compat.add_version_changes('avutil', 59, AVFrame, AVFrame_Fields,
199
199
  removals=('pkt_pts', 'error', 'qscale_table', 'qstride', 'qscale_type', 'qp_table_buf',
200
200
  'channels', 'channel_layout',
201
- 'coded_picture_number', 'display_picture_number', 'reordered_opaque', 'pkt_duration'
201
+ 'coded_picture_number', 'display_picture_number', 'reordered_opaque',
202
+ 'pkt_duration',
202
203
  ))
203
204
 
205
+ compat.add_version_changes('avutil', 60, AVFrame, AVFrame_Fields,
206
+ removals=('pkt_pts', 'error', 'qscale_table', 'qstride', 'qscale_type', 'qp_table_buf',
207
+ 'channels', 'channel_layout',
208
+ 'coded_picture_number', 'display_picture_number', 'reordered_opaque',
209
+ 'pkt_duration',
210
+ 'interlaced_frame', 'top_field_first', 'palette_has_changed', 'pkt_pos',
211
+ 'pkt_size',
212
+ ))
204
213
 
205
214
  AV_NOPTS_VALUE = -0x8000000000000000
206
215
  AV_TIME_BASE = 1000000
@@ -250,6 +259,12 @@ avutil.av_get_bytes_per_sample.argtypes = [c_int]
250
259
  avutil.av_strerror.restype = c_int
251
260
  avutil.av_strerror.argtypes = [c_int, c_char_p, c_size_t]
252
261
 
262
+ avutil.av_get_pix_fmt_name.restype = c_char_p
263
+ avutil.av_get_pix_fmt_name.argtypes = [c_int]
264
+
265
+ avutil.av_image_get_buffer_size.restype = c_int
266
+ avutil.av_image_get_buffer_size.argtypes = [c_int, c_int, c_int, c_int]
267
+
253
268
  avutil.av_image_fill_arrays.restype = c_int
254
269
  avutil.av_image_fill_arrays.argtypes = [POINTER(c_uint8) * 4, c_int * 4,
255
270
  POINTER(c_uint8), c_int, c_int, c_int, c_int]
@@ -13,8 +13,8 @@ _debug = debug_print('debug_media')
13
13
 
14
14
  swresample = pyglet.lib.load_library(
15
15
  'swresample',
16
- win32=('swresample-5', 'swresample-4', 'swresample-3'),
17
- darwin=('swresample.5', 'swresample.4', 'swresample.3')
16
+ win32=('swresample-6', 'swresample-5', 'swresample-4', 'swresample-3'),
17
+ darwin=('swresample.6', 'swresample.5', 'swresample.4', 'swresample.3')
18
18
  )
19
19
 
20
20
  swresample.swresample_version.restype = c_int
@@ -13,8 +13,8 @@ _debug = debug_print('debug_media')
13
13
 
14
14
  swscale = pyglet.lib.load_library(
15
15
  'swscale',
16
- win32=('swscale-8', 'swscale-7', 'swscale-6', 'swscale-5'),
17
- darwin=('swscale.8', 'swscale.7', 'swscale.6', 'swscale.5')
16
+ win32=('swscale-9', 'swscale-8', 'swscale-7', 'swscale-6', 'swscale-5'),
17
+ darwin=('swscale.9', 'swscale.8', 'swscale.7', 'swscale.6', 'swscale.5')
18
18
  )
19
19
 
20
20
  swscale.swscale_version.restype = c_int
pyglet/text/__init__.py CHANGED
@@ -49,7 +49,7 @@ from pyglet.text import caret, document, layout # noqa: F401
49
49
 
50
50
 
51
51
  if TYPE_CHECKING:
52
- from pyglet.customtypes import AnchorX, AnchorY, ContentVAlign
52
+ from pyglet.customtypes import AnchorX, AnchorY, HorizontalAlign
53
53
  from pyglet.graphics import Batch, Group
54
54
  from pyglet.graphics.shader import ShaderProgram
55
55
  from pyglet.resource import Location
@@ -401,7 +401,7 @@ class Label(DocumentLabel):
401
401
  font_name: str | None = None, font_size: float | None = None,
402
402
  weight: str = "normal", italic: bool | str = False, stretch: bool | str = False,
403
403
  color: tuple[int, int, int, int] | tuple[int, int, int] = (255, 255, 255, 255),
404
- align: ContentVAlign = "left",
404
+ align: HorizontalAlign = "left",
405
405
  batch: Batch | None = None, group: Group | None = None,
406
406
  program: ShaderProgram | None = None,
407
407
  ) -> None:
pyglet/text/document.py CHANGED
@@ -678,13 +678,13 @@ class _FontStyleRunsRangeIterator(runlist.RunIterator):
678
678
  from pyglet import font
679
679
  for start_, end_, styles in self.zip_iter.ranges(start, end):
680
680
  font_name, font_size, weight, italic, stretch = styles
681
- ft = font.load(font_name, font_size, weight=weight, italic=bool(italic), stretch=stretch, dpi=self.dpi)
681
+ ft = font.load(font_name, font_size, weight=weight or "normal", italic=bool(italic), stretch=stretch or False, dpi=self.dpi)
682
682
  yield start_, end_, ft
683
683
 
684
684
  def __getitem__(self, index: int) -> Font:
685
685
  from pyglet import font
686
686
  font_name, font_size, weight, italic, stretch = self.zip_iter[index]
687
- return font.load(font_name, font_size, weight=weight, italic=bool(italic), stretch=stretch, dpi=self.dpi)
687
+ return font.load(font_name, font_size, weight=weight or "normal", italic=bool(italic), stretch=stretch or False, dpi=self.dpi)
688
688
 
689
689
 
690
690
  class _NoStyleRangeIterator(runlist.RunIterator):
@@ -603,7 +603,7 @@ class _GlyphBox(_AbstractBox):
603
603
  def update_rotation(self, rotation: float) -> None:
604
604
  rot = (rotation,)
605
605
  for _vertex_list in self.vertex_lists:
606
- _vertex_list.rotation[:] = (rot * _vertex_list.count)
606
+ _vertex_list.rotation[:] = rot * _vertex_list.count
607
607
 
608
608
  def update_visibility(self, visible: bool) -> None:
609
609
  visible_tuple = (visible,)
@@ -939,6 +939,7 @@ class TextLayout:
939
939
  # Boxes are all existing _AbstractBoxes, these are used to gather line information.
940
940
  # Note that this is only relevant to layouts that do not store directly on lines.
941
941
  self._boxes = []
942
+ self._lines = []
942
943
 
943
944
  #: :meta private:
944
945
  self.group_cache = {}
@@ -1139,10 +1140,11 @@ class TextLayout:
1139
1140
 
1140
1141
  anchor_y = self._get_top_anchor()
1141
1142
 
1142
- acc_anchor_x = self._anchor_left
1143
- for box in self._boxes:
1144
- box.update_anchor(acc_anchor_x, anchor_y)
1145
- acc_anchor_x += box.advance
1143
+ for line in self._lines:
1144
+ acc_anchor_x = self._anchor_left
1145
+ for box in line.boxes:
1146
+ box.update_anchor(acc_anchor_x, anchor_y)
1147
+ acc_anchor_x += box.advance
1146
1148
 
1147
1149
  @property
1148
1150
  def visible(self) -> bool:
@@ -1453,6 +1455,7 @@ class TextLayout:
1453
1455
 
1454
1456
  self._vertex_lists.clear()
1455
1457
  self._boxes.clear()
1458
+ self._lines.clear()
1456
1459
  self.group_cache.clear()
1457
1460
 
1458
1461
  if not self._document or not self._document.text:
@@ -1462,9 +1465,9 @@ class TextLayout:
1462
1465
  self._anchor_bottom = 0
1463
1466
  return
1464
1467
 
1465
- lines = self._get_lines()
1466
- self._ascent = lines[0].ascent
1467
- self._descent = lines[0].descent
1468
+ self._lines = self._get_lines()
1469
+ self._ascent = self._lines[0].ascent
1470
+ self._descent = self._lines[0].descent
1468
1471
 
1469
1472
  colors_iter = self._document.get_style_runs("color")
1470
1473
 
@@ -1476,7 +1479,7 @@ class TextLayout:
1476
1479
 
1477
1480
  context = _StaticLayoutContext(self, self._document, colors_iter, background_iter)
1478
1481
 
1479
- for line in lines:
1482
+ for line in self._lines:
1480
1483
  self._boxes.extend(line.boxes)
1481
1484
  self._create_vertex_lists(line.x, line.y, self._anchor_left, anchor_top, line.start, line.boxes, context)
1482
1485
 
pyglet/window/__init__.py CHANGED
@@ -91,6 +91,7 @@ from __future__ import annotations
91
91
 
92
92
  import sys
93
93
  from abc import abstractmethod
94
+ from collections import deque
94
95
  from typing import TYPE_CHECKING, Any, Callable, Sequence
95
96
 
96
97
  import pyglet
@@ -502,7 +503,7 @@ class BaseWindow(EventDispatcher, metaclass=_WindowMetaclass):
502
503
 
503
504
  """
504
505
  EventDispatcher.__init__(self)
505
- self._event_queue = []
506
+ self._event_queue = deque()
506
507
 
507
508
  if not display:
508
509
  display = pyglet.display.get_display()
@@ -677,7 +678,7 @@ class BaseWindow(EventDispatcher, metaclass=_WindowMetaclass):
677
678
  self._context = None
678
679
  if app.event_loop:
679
680
  app.event_loop.dispatch_event('on_window_close', self)
680
- self._event_queue = []
681
+ self._event_queue = deque()
681
682
 
682
683
  def dispatch_event(self, *args: Any) -> None:
683
684
  if not self._enable_event_queue or self._allow_dispatch_event:
@@ -167,15 +167,15 @@ class CocoaWindow(BaseWindow):
167
167
  self._nsview = PygletView.alloc().initWithFrame_cocoaWindow_(content_rect, self)
168
168
  self._nsview.setWantsBestResolutionOpenGLSurface_(True)
169
169
 
170
- if not self._fullscreen:
171
- if self._style in ("transparent", "overlay"):
172
- self._nswindow.setOpaque_(False)
173
- self._nswindow.setBackgroundColor_(NSColor.clearColor())
174
- self._nswindow.setHasShadow_(False)
170
+ if not self._fullscreen:
171
+ if self._style in ("transparent", "overlay"):
172
+ self._nswindow.setOpaque_(False)
173
+ self._nswindow.setBackgroundColor_(NSColor.clearColor())
174
+ self._nswindow.setHasShadow_(False)
175
175
 
176
- if self._style == "overlay":
177
- self.set_mouse_passthrough(True)
178
- self._nswindow.setLevel_(cocoapy.NSStatusWindowLevel)
176
+ if self._style == "overlay":
177
+ self.set_mouse_passthrough(True)
178
+ self._nswindow.setLevel_(cocoapy.NSStatusWindowLevel)
179
179
 
180
180
  self._nswindow.setContentView_(self._nsview)
181
181
  self._nswindow.makeFirstResponder_(self._nsview)
@@ -362,7 +362,7 @@ class CocoaWindow(BaseWindow):
362
362
 
363
363
  def dispatch_pending_events(self) -> None:
364
364
  while self._event_queue:
365
- event = self._event_queue.pop(0)
365
+ event = self._event_queue.popleft()
366
366
  EventDispatcher.dispatch_event(self, *event)
367
367
 
368
368
  def set_caption(self, caption: str) -> None:
@@ -90,7 +90,7 @@ class HeadlessWindow(BaseWindow):
90
90
 
91
91
  def dispatch_events(self) -> None:
92
92
  while self._event_queue:
93
- EventDispatcher.dispatch_event(self, *self._event_queue.pop(0))
93
+ EventDispatcher.dispatch_event(self, *self._event_queue.popleft())
94
94
 
95
95
  def dispatch_pending_events(self) -> None:
96
96
  pass
@@ -846,7 +846,7 @@ class Win32Window(BaseWindow):
846
846
  def dispatch_pending_events(self) -> None:
847
847
  """Legacy or manual dispatch."""
848
848
  while self._event_queue:
849
- event = self._event_queue.pop(0)
849
+ event = self._event_queue.popleft()
850
850
  if isinstance(event[0], str):
851
851
  # pyglet event
852
852
  EventDispatcher.dispatch_event(self, *event)
@@ -1036,7 +1036,7 @@ class XlibWindow(BaseWindow):
1036
1036
 
1037
1037
  def dispatch_pending_events(self) -> None:
1038
1038
  while self._event_queue:
1039
- EventDispatcher.dispatch_event(self, *self._event_queue.pop(0))
1039
+ EventDispatcher.dispatch_event(self, *self._event_queue.popleft())
1040
1040
 
1041
1041
  # Dispatch any context-related events
1042
1042
  if self._lost_context:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyglet
3
- Version: 2.1.8
3
+ Version: 2.1.10
4
4
  Summary: pyglet is a cross-platform games and multimedia package.
5
5
  Author-email: Alex Holkner & contributors <Alex.Holkner@gmail.com>
6
6
  Requires-Python: >=3.8