pyglet 2.1.13__py3-none-any.whl → 3.0.dev1__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.
Files changed (267) hide show
  1. pyglet/__init__.py +67 -61
  2. pyglet/__init__.pyi +15 -8
  3. pyglet/app/__init__.py +22 -13
  4. pyglet/app/async_app.py +212 -0
  5. pyglet/app/base.py +2 -1
  6. pyglet/app/{xlib.py → linux.py} +3 -3
  7. pyglet/config/__init__.py +101 -0
  8. pyglet/config/gl/__init__.py +30 -0
  9. pyglet/config/gl/egl.py +120 -0
  10. pyglet/config/gl/macos.py +262 -0
  11. pyglet/config/gl/windows.py +267 -0
  12. pyglet/config/gl/x11.py +142 -0
  13. pyglet/customtypes.py +43 -2
  14. pyglet/display/__init__.py +8 -6
  15. pyglet/display/base.py +3 -63
  16. pyglet/display/cocoa.py +12 -17
  17. pyglet/display/emscripten.py +39 -0
  18. pyglet/display/headless.py +23 -30
  19. pyglet/display/wayland.py +157 -0
  20. pyglet/display/win32.py +5 -21
  21. pyglet/display/xlib.py +19 -27
  22. pyglet/display/xlib_vidmoderestore.py +2 -2
  23. pyglet/enums.py +183 -0
  24. pyglet/event.py +0 -1
  25. pyglet/experimental/geoshader_sprite.py +15 -13
  26. pyglet/experimental/hidraw.py +6 -15
  27. pyglet/experimental/multitexture_sprite.py +31 -19
  28. pyglet/experimental/particles.py +13 -35
  29. pyglet/font/__init__.py +251 -85
  30. pyglet/font/base.py +116 -61
  31. pyglet/font/dwrite/__init__.py +349 -204
  32. pyglet/font/dwrite/dwrite_lib.py +27 -5
  33. pyglet/font/fontconfig.py +14 -6
  34. pyglet/font/freetype.py +138 -87
  35. pyglet/font/freetype_lib.py +19 -0
  36. pyglet/font/group.py +179 -0
  37. pyglet/font/harfbuzz/__init__.py +3 -3
  38. pyglet/font/pyodide_js.py +310 -0
  39. pyglet/font/quartz.py +319 -126
  40. pyglet/font/ttf.py +45 -3
  41. pyglet/font/user.py +14 -19
  42. pyglet/font/win32.py +45 -21
  43. pyglet/graphics/__init__.py +8 -787
  44. pyglet/graphics/allocation.py +115 -1
  45. pyglet/graphics/api/__init__.py +77 -0
  46. pyglet/graphics/api/base.py +299 -0
  47. pyglet/graphics/api/gl/__init__.py +58 -0
  48. pyglet/graphics/api/gl/base.py +24 -0
  49. pyglet/graphics/{vertexbuffer.py → api/gl/buffer.py} +104 -159
  50. pyglet/graphics/api/gl/cocoa/context.py +76 -0
  51. pyglet/graphics/api/gl/context.py +391 -0
  52. pyglet/graphics/api/gl/default_shaders.py +0 -0
  53. pyglet/graphics/api/gl/draw.py +627 -0
  54. pyglet/graphics/api/gl/egl/__init__.py +0 -0
  55. pyglet/graphics/api/gl/egl/context.py +92 -0
  56. pyglet/graphics/api/gl/enums.py +76 -0
  57. pyglet/graphics/api/gl/framebuffer.py +315 -0
  58. pyglet/graphics/api/gl/gl.py +5463 -0
  59. pyglet/graphics/api/gl/gl_info.py +188 -0
  60. pyglet/graphics/api/gl/global_opengl.py +226 -0
  61. pyglet/{gl → graphics/api/gl}/lib.py +34 -18
  62. pyglet/graphics/api/gl/shader.py +1476 -0
  63. pyglet/graphics/api/gl/shapes.py +55 -0
  64. pyglet/graphics/api/gl/sprite.py +102 -0
  65. pyglet/graphics/api/gl/state.py +219 -0
  66. pyglet/graphics/api/gl/text.py +190 -0
  67. pyglet/graphics/api/gl/texture.py +1526 -0
  68. pyglet/graphics/{vertexarray.py → api/gl/vertexarray.py} +11 -13
  69. pyglet/graphics/api/gl/vertexdomain.py +751 -0
  70. pyglet/graphics/api/gl/win32/__init__.py +0 -0
  71. pyglet/graphics/api/gl/win32/context.py +108 -0
  72. pyglet/graphics/api/gl/win32/wgl_info.py +24 -0
  73. pyglet/graphics/api/gl/xlib/__init__.py +0 -0
  74. pyglet/graphics/api/gl/xlib/context.py +174 -0
  75. pyglet/{gl → graphics/api/gl/xlib}/glx_info.py +26 -31
  76. pyglet/graphics/api/gl1/__init__.py +0 -0
  77. pyglet/{gl → graphics/api/gl1}/gl_compat.py +3 -2
  78. pyglet/graphics/api/gl2/__init__.py +0 -0
  79. pyglet/graphics/api/gl2/buffer.py +320 -0
  80. pyglet/graphics/api/gl2/draw.py +600 -0
  81. pyglet/graphics/api/gl2/global_opengl.py +122 -0
  82. pyglet/graphics/api/gl2/shader.py +200 -0
  83. pyglet/graphics/api/gl2/shapes.py +51 -0
  84. pyglet/graphics/api/gl2/sprite.py +79 -0
  85. pyglet/graphics/api/gl2/text.py +175 -0
  86. pyglet/graphics/api/gl2/vertexdomain.py +364 -0
  87. pyglet/graphics/api/webgl/__init__.py +233 -0
  88. pyglet/graphics/api/webgl/buffer.py +302 -0
  89. pyglet/graphics/api/webgl/context.py +234 -0
  90. pyglet/graphics/api/webgl/draw.py +590 -0
  91. pyglet/graphics/api/webgl/enums.py +76 -0
  92. pyglet/graphics/api/webgl/framebuffer.py +360 -0
  93. pyglet/graphics/api/webgl/gl.py +1537 -0
  94. pyglet/graphics/api/webgl/gl_info.py +130 -0
  95. pyglet/graphics/api/webgl/shader.py +1346 -0
  96. pyglet/graphics/api/webgl/shapes.py +92 -0
  97. pyglet/graphics/api/webgl/sprite.py +102 -0
  98. pyglet/graphics/api/webgl/state.py +227 -0
  99. pyglet/graphics/api/webgl/text.py +187 -0
  100. pyglet/graphics/api/webgl/texture.py +1227 -0
  101. pyglet/graphics/api/webgl/vertexarray.py +54 -0
  102. pyglet/graphics/api/webgl/vertexdomain.py +616 -0
  103. pyglet/graphics/api/webgl/webgl_js.pyi +307 -0
  104. pyglet/{image → graphics}/atlas.py +33 -32
  105. pyglet/graphics/base.py +10 -0
  106. pyglet/graphics/buffer.py +245 -0
  107. pyglet/graphics/draw.py +578 -0
  108. pyglet/graphics/framebuffer.py +26 -0
  109. pyglet/graphics/instance.py +178 -69
  110. pyglet/graphics/shader.py +267 -1553
  111. pyglet/graphics/state.py +83 -0
  112. pyglet/graphics/texture.py +703 -0
  113. pyglet/graphics/vertexdomain.py +695 -538
  114. pyglet/gui/ninepatch.py +10 -10
  115. pyglet/gui/widgets.py +120 -10
  116. pyglet/image/__init__.py +20 -1973
  117. pyglet/image/animation.py +12 -12
  118. pyglet/image/base.py +730 -0
  119. pyglet/image/codecs/__init__.py +9 -0
  120. pyglet/image/codecs/bmp.py +53 -30
  121. pyglet/image/codecs/dds.py +53 -31
  122. pyglet/image/codecs/gdiplus.py +38 -14
  123. pyglet/image/codecs/gdkpixbuf2.py +0 -2
  124. pyglet/image/codecs/js_image.py +99 -0
  125. pyglet/image/codecs/ktx2.py +161 -0
  126. pyglet/image/codecs/pil.py +1 -1
  127. pyglet/image/codecs/png.py +1 -1
  128. pyglet/image/codecs/wic.py +11 -2
  129. pyglet/info.py +26 -24
  130. pyglet/input/__init__.py +8 -0
  131. pyglet/input/base.py +163 -105
  132. pyglet/input/controller.py +13 -19
  133. pyglet/input/controller_db.py +39 -24
  134. pyglet/input/emscripten/__init__.py +18 -0
  135. pyglet/input/emscripten/gamepad_js.py +397 -0
  136. pyglet/input/linux/__init__.py +11 -5
  137. pyglet/input/linux/evdev.py +10 -11
  138. pyglet/input/linux/x11_xinput.py +2 -2
  139. pyglet/input/linux/x11_xinput_tablet.py +1 -1
  140. pyglet/input/macos/__init__.py +7 -2
  141. pyglet/input/macos/darwin_gc.py +559 -0
  142. pyglet/input/win32/__init__.py +1 -1
  143. pyglet/input/win32/directinput.py +34 -29
  144. pyglet/input/win32/xinput.py +11 -61
  145. pyglet/lib.py +3 -3
  146. pyglet/libs/__init__.py +1 -1
  147. pyglet/{gl → libs/darwin}/agl.py +1 -1
  148. pyglet/libs/darwin/cocoapy/__init__.py +2 -2
  149. pyglet/libs/darwin/cocoapy/cocoahelpers.py +181 -0
  150. pyglet/libs/darwin/cocoapy/cocoalibs.py +31 -0
  151. pyglet/libs/darwin/cocoapy/cocoatypes.py +27 -0
  152. pyglet/libs/darwin/cocoapy/runtime.py +81 -45
  153. pyglet/libs/darwin/coreaudio.py +4 -4
  154. pyglet/{gl → libs/darwin}/lib_agl.py +9 -8
  155. pyglet/libs/darwin/quartzkey.py +1 -3
  156. pyglet/libs/egl/__init__.py +2 -0
  157. pyglet/libs/egl/egl_lib.py +576 -0
  158. pyglet/libs/egl/eglext.py +51 -5
  159. pyglet/libs/linux/__init__.py +0 -0
  160. pyglet/libs/linux/egl/__init__.py +0 -0
  161. pyglet/libs/linux/egl/eglext.py +22 -0
  162. pyglet/libs/linux/glx/__init__.py +0 -0
  163. pyglet/{gl → libs/linux/glx}/glx.py +13 -14
  164. pyglet/{gl → libs/linux/glx}/glxext_arb.py +408 -192
  165. pyglet/{gl → libs/linux/glx}/glxext_mesa.py +1 -1
  166. pyglet/{gl → libs/linux/glx}/glxext_nv.py +345 -164
  167. pyglet/{gl → libs/linux/glx}/lib_glx.py +3 -2
  168. pyglet/libs/linux/wayland/__init__.py +0 -0
  169. pyglet/libs/linux/wayland/client.py +1068 -0
  170. pyglet/libs/linux/wayland/lib_wayland.py +207 -0
  171. pyglet/libs/linux/wayland/wayland_egl.py +38 -0
  172. pyglet/libs/{wayland → linux/wayland}/xkbcommon.py +26 -0
  173. pyglet/libs/{x11 → linux/x11}/xf86vmode.py +4 -4
  174. pyglet/libs/{x11 → linux/x11}/xinerama.py +2 -2
  175. pyglet/libs/{x11 → linux/x11}/xinput.py +10 -10
  176. pyglet/libs/linux/x11/xrandr.py +0 -0
  177. pyglet/libs/{x11 → linux/x11}/xrender.py +1 -1
  178. pyglet/libs/shared/__init__.py +0 -0
  179. pyglet/libs/shared/spirv/__init__.py +0 -0
  180. pyglet/libs/shared/spirv/lib_shaderc.py +85 -0
  181. pyglet/libs/shared/spirv/lib_spirv_cross.py +126 -0
  182. pyglet/libs/win32/__init__.py +28 -8
  183. pyglet/libs/win32/constants.py +59 -48
  184. pyglet/libs/win32/context_managers.py +20 -3
  185. pyglet/libs/win32/dinput.py +105 -88
  186. pyglet/{gl → libs/win32}/lib_wgl.py +52 -26
  187. pyglet/libs/win32/types.py +58 -23
  188. pyglet/{gl → libs/win32}/wgl.py +32 -25
  189. pyglet/{gl → libs/win32}/wglext_arb.py +364 -2
  190. pyglet/media/__init__.py +9 -10
  191. pyglet/media/codecs/__init__.py +12 -1
  192. pyglet/media/codecs/base.py +99 -96
  193. pyglet/media/codecs/ffmpeg.py +2 -2
  194. pyglet/media/codecs/ffmpeg_lib/libavformat.py +3 -8
  195. pyglet/media/codecs/webaudio_pyodide.py +111 -0
  196. pyglet/media/drivers/__init__.py +9 -4
  197. pyglet/media/drivers/base.py +4 -4
  198. pyglet/media/drivers/openal/__init__.py +1 -1
  199. pyglet/media/drivers/openal/adaptation.py +3 -3
  200. pyglet/media/drivers/pulse/__init__.py +1 -1
  201. pyglet/media/drivers/pulse/adaptation.py +3 -3
  202. pyglet/media/drivers/pyodide_js/__init__.py +8 -0
  203. pyglet/media/drivers/pyodide_js/adaptation.py +288 -0
  204. pyglet/media/drivers/xaudio2/adaptation.py +3 -3
  205. pyglet/media/player.py +276 -193
  206. pyglet/media/player_worker_thread.py +1 -1
  207. pyglet/model/__init__.py +39 -29
  208. pyglet/model/codecs/base.py +4 -4
  209. pyglet/model/codecs/gltf.py +3 -3
  210. pyglet/model/codecs/obj.py +71 -43
  211. pyglet/resource.py +129 -78
  212. pyglet/shapes.py +154 -194
  213. pyglet/sprite.py +47 -164
  214. pyglet/text/__init__.py +44 -54
  215. pyglet/text/caret.py +12 -7
  216. pyglet/text/document.py +19 -17
  217. pyglet/text/formats/html.py +2 -2
  218. pyglet/text/formats/structured.py +10 -40
  219. pyglet/text/layout/__init__.py +20 -13
  220. pyglet/text/layout/base.py +176 -287
  221. pyglet/text/layout/incremental.py +9 -10
  222. pyglet/text/layout/scrolling.py +7 -95
  223. pyglet/window/__init__.py +183 -172
  224. pyglet/window/cocoa/__init__.py +62 -51
  225. pyglet/window/cocoa/pyglet_delegate.py +2 -25
  226. pyglet/window/cocoa/pyglet_view.py +9 -8
  227. pyglet/window/dialog/__init__.py +184 -0
  228. pyglet/window/dialog/base.py +99 -0
  229. pyglet/window/dialog/darwin.py +121 -0
  230. pyglet/window/dialog/linux.py +72 -0
  231. pyglet/window/dialog/windows.py +194 -0
  232. pyglet/window/emscripten/__init__.py +779 -0
  233. pyglet/window/headless/__init__.py +44 -28
  234. pyglet/window/key.py +2 -0
  235. pyglet/window/mouse.py +2 -2
  236. pyglet/window/wayland/__init__.py +377 -0
  237. pyglet/window/win32/__init__.py +101 -46
  238. pyglet/window/xlib/__init__.py +104 -66
  239. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/METADATA +2 -3
  240. pyglet-3.0.dev1.dist-info/RECORD +322 -0
  241. {pyglet-2.1.13.dist-info → pyglet-3.0.dev1.dist-info}/WHEEL +1 -1
  242. pyglet/gl/__init__.py +0 -208
  243. pyglet/gl/base.py +0 -499
  244. pyglet/gl/cocoa.py +0 -309
  245. pyglet/gl/gl.py +0 -4625
  246. pyglet/gl/gl.pyi +0 -2320
  247. pyglet/gl/gl_compat.pyi +0 -3097
  248. pyglet/gl/gl_info.py +0 -190
  249. pyglet/gl/headless.py +0 -166
  250. pyglet/gl/wgl_info.py +0 -36
  251. pyglet/gl/wglext_nv.py +0 -1096
  252. pyglet/gl/win32.py +0 -268
  253. pyglet/gl/xlib.py +0 -295
  254. pyglet/image/buffer.py +0 -274
  255. pyglet/image/codecs/s3tc.py +0 -354
  256. pyglet/libs/x11/xrandr.py +0 -166
  257. pyglet-2.1.13.dist-info/RECORD +0 -234
  258. /pyglet/{libs/wayland → graphics/api/gl/cocoa}/__init__.py +0 -0
  259. /pyglet/libs/{egl → linux/egl}/egl.py +0 -0
  260. /pyglet/libs/{egl → linux/egl}/lib.py +0 -0
  261. /pyglet/libs/{ioctl.py → linux/ioctl.py} +0 -0
  262. /pyglet/libs/{wayland → linux/wayland}/gbm.py +0 -0
  263. /pyglet/libs/{x11 → linux/x11}/__init__.py +0 -0
  264. /pyglet/libs/{x11 → linux/x11}/cursorfont.py +0 -0
  265. /pyglet/libs/{x11 → linux/x11}/xlib.py +0 -0
  266. /pyglet/libs/{x11 → linux/x11}/xsync.py +0 -0
  267. {pyglet-2.1.13.dist-info/licenses → pyglet-3.0.dev1.dist-info}/LICENSE +0 -0
@@ -1,8 +1,9 @@
1
+ from __future__ import annotations
1
2
  import atexit
2
3
  import struct
3
4
  import warnings
4
5
  from ctypes import HRESULT
5
- from ctypes.wintypes import ATOM, HFONT, HGDIOBJ, HGLOBAL, HMENU, HMODULE, INT, LPVOID, PUINT
6
+ from ctypes.wintypes import ATOM, HFONT, HGDIOBJ, HGLOBAL, HMENU, HMODULE, INT, LPVOID, PUINT, HKEY, LPBYTE, LPCVOID
6
7
 
7
8
  import pyglet
8
9
 
@@ -11,7 +12,7 @@ from .types import *
11
12
 
12
13
  IS64 = struct.calcsize("P") == 8
13
14
 
14
- _debug_win32 = pyglet.options['debug_win32']
15
+ _debug_win32 = pyglet.options.debug_win32
15
16
 
16
17
  DebugLibrary = lambda lib: ctypes.WinDLL(lib, use_last_error=True if _debug_win32 else False)
17
18
 
@@ -22,9 +23,9 @@ _dwmapi = DebugLibrary('dwmapi')
22
23
  _shell32 = DebugLibrary('shell32')
23
24
  _ole32 = DebugLibrary('ole32')
24
25
  _oleaut32 = DebugLibrary('oleaut32')
25
-
26
- if constants.WINDOWS_8_1_OR_GREATER:
27
- _shcore = DebugLibrary('shcore')
26
+ _shcore = DebugLibrary('shcore')
27
+ _advapi32 = DebugLibrary("advapi32")
28
+ _comdlg32 = DebugLibrary("comdlg32")
28
29
 
29
30
  # _gdi32
30
31
  _gdi32.AddFontMemResourceEx.restype = HANDLE
@@ -261,8 +262,13 @@ _dwmapi.DwmFlush.restype = c_int
261
262
  _dwmapi.DwmFlush.argtypes = []
262
263
  _dwmapi.DwmGetColorizationColor.restype = HRESULT
263
264
  _dwmapi.DwmGetColorizationColor.argtypes = [POINTER(DWORD), POINTER(BOOL)]
265
+ _dwmapi.DwmGetWindowAttribute.restype = HRESULT
266
+ _dwmapi.DwmGetWindowAttribute.argtypes = [HWND, DWORD, PVOID, DWORD]
264
267
  _dwmapi.DwmEnableBlurBehindWindow.restype = HRESULT
265
268
  _dwmapi.DwmEnableBlurBehindWindow.argtypes = [HWND, POINTER(DWM_BLURBEHIND)]
269
+ _dwmapi.DwmSetWindowAttribute.restype = HRESULT
270
+ _dwmapi.DwmSetWindowAttribute.argtypes = [HWND, DWORD, LPCVOID, DWORD]
271
+
266
272
 
267
273
  # _shell32
268
274
  _shell32.DragAcceptFiles.restype = c_void
@@ -302,6 +308,21 @@ if constants.WINDOWS_8_1_OR_GREATER:
302
308
  _shcore.GetDpiForMonitor.argtypes = [HMONITOR, MONITOR_DPI_TYPE, POINTER(UINT), POINTER(UINT)]
303
309
  _shcore.GetDpiForMonitor.restype = HRESULT
304
310
 
311
+ # _advapi32
312
+ _advapi32.RegCloseKey.argtypes = [HKEY]
313
+ _advapi32.RegCloseKey.restype = LONG
314
+ _advapi32.RegOpenKeyExW.argtypes = [HKEY, LPCWSTR, DWORD, REGSAM, POINTER(HKEY)]
315
+ _advapi32.RegOpenKeyExW.restype = LONG
316
+ _advapi32.RegQueryValueExW.argtypes = [HKEY,LPCWSTR,LPVOID, POINTER(DWORD), LPBYTE, POINTER(DWORD)]
317
+ _advapi32.RegQueryValueExW.restype = LONG
318
+
319
+ # _comdlg32
320
+ _comdlg32.GetOpenFileNameW.argtypes = [POINTER(OPENFILENAMEW)]
321
+ _comdlg32.GetOpenFileNameW.restype = BOOL
322
+ _comdlg32.GetSaveFileNameW.argtypes = [POINTER(OPENFILENAMEW)]
323
+ _comdlg32.GetSaveFileNameW.restype = BOOL
324
+
325
+
305
326
  if _debug_win32:
306
327
  import traceback
307
328
 
@@ -311,8 +332,7 @@ if _debug_win32:
311
332
  def win32_errcheck(result, func, args):
312
333
  last_err = ctypes.get_last_error()
313
334
  if last_err != 0: # If the result is not success and last error is invalid.
314
- for entry in traceback.format_list(traceback.extract_stack()[:-1]):
315
- _log_win32.write(entry)
335
+ _log_win32.writelines(traceback.format_list(traceback.extract_stack()[:-1]))
316
336
  print(f"[Result {result}] Error #{last_err} - {ctypes.FormatError(last_err)}", file=_log_win32)
317
337
  return args
318
338
 
@@ -335,7 +355,7 @@ if _debug_win32:
335
355
 
336
356
  # Initialize COM. Required for: WIC (DirectWrite), WMF, and XInput
337
357
  try:
338
- if pyglet.options["com_mta"] is True:
358
+ if pyglet.options.com_mta is True:
339
359
  _ole32.CoInitializeEx(None, constants.COINIT_MULTITHREADED)
340
360
  else:
341
361
  _ole32.CoInitializeEx(None, constants.COINIT_APARTMENTTHREADED)
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import sys
2
3
 
3
4
  # Most of this file is win32con.py from Python for Windows Extensions:
@@ -19,24 +20,24 @@ VK_OEM_7 = 0xde
19
20
  VK_OEM_8 = 0xdf
20
21
  VK_OEM_102 = 0xe2
21
22
 
22
- # Copyright (c) 1994-2001, Mark Hammond
23
+ # Copyright (c) 1994-2001, Mark Hammond
23
24
  # All rights reserved.
24
- #
25
- # Redistribution and use in source and binary forms, with or without
26
- # modification, are permitted provided that the following conditions
25
+ #
26
+ # Redistribution and use in source and binary forms, with or without
27
+ # modification, are permitted provided that the following conditions
27
28
  # are met:
28
- #
29
- # Redistributions of source code must retain the above copyright notice,
29
+ #
30
+ # Redistributions of source code must retain the above copyright notice,
30
31
  # this list of conditions and the following disclaimer.
31
- #
32
- # Redistributions in binary form must reproduce the above copyright
33
- # notice, this list of conditions and the following disclaimer in
32
+ #
33
+ # Redistributions in binary form must reproduce the above copyright
34
+ # notice, this list of conditions and the following disclaimer in
34
35
  # the documentation and/or other materials provided with the distribution.
35
- #
36
- # Neither name of Mark Hammond nor the name of contributors may be used
37
- # to endorse or promote products derived from this software without
38
- # specific prior written permission.
39
- #
36
+ #
37
+ # Neither name of Mark Hammond nor the name of contributors may be used
38
+ # to endorse or promote products derived from this software without
39
+ # specific prior written permission.
40
+ #
40
41
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
41
42
  # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42
43
  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -3509,7 +3510,7 @@ ELF_CULTURE_LATIN = 0
3509
3510
  RASTER_FONTTYPE = 1
3510
3511
  DEVICE_FONTTYPE = 2
3511
3512
  TRUETYPE_FONTTYPE = 4
3512
- def PALETTEINDEX(i): return ((16777216 | (i)))
3513
+ def PALETTEINDEX(i): return (16777216 | (i))
3513
3514
 
3514
3515
  PC_RESERVED = 1
3515
3516
  PC_EXPLICIT = 2
@@ -3564,42 +3565,42 @@ STOCK_LAST = 16
3564
3565
  CLR_INVALID = -1
3565
3566
 
3566
3567
  # Exception/Status codes from winuser.h and winnt.h
3567
- STATUS_WAIT_0 = 0
3568
- STATUS_ABANDONED_WAIT_0 = 128
3569
- STATUS_USER_APC = 192
3570
- STATUS_TIMEOUT = 258
3571
- STATUS_PENDING = 259
3572
- STATUS_SEGMENT_NOTIFICATION = 1073741829
3573
- STATUS_GUARD_PAGE_VIOLATION = -2147483647
3574
- STATUS_DATATYPE_MISALIGNMENT = -2147483646
3575
- STATUS_BREAKPOINT = -2147483645
3576
- STATUS_SINGLE_STEP = -2147483644
3577
- STATUS_ACCESS_VIOLATION = -1073741819
3578
- STATUS_IN_PAGE_ERROR = -1073741818
3579
- STATUS_INVALID_HANDLE = -1073741816
3580
- STATUS_NO_MEMORY = -1073741801
3581
- STATUS_ILLEGAL_INSTRUCTION = -1073741795
3582
- STATUS_NONCONTINUABLE_EXCEPTION = -1073741787
3583
- STATUS_INVALID_DISPOSITION = -1073741786
3584
- STATUS_ARRAY_BOUNDS_EXCEEDED = -1073741684
3585
- STATUS_FLOAT_DENORMAL_OPERAND = -1073741683
3586
- STATUS_FLOAT_DIVIDE_BY_ZERO = -1073741682
3587
- STATUS_FLOAT_INEXACT_RESULT = -1073741681
3588
- STATUS_FLOAT_INVALID_OPERATION = -1073741680
3589
- STATUS_FLOAT_OVERFLOW = -1073741679
3590
- STATUS_FLOAT_STACK_CHECK = -1073741678
3591
- STATUS_FLOAT_UNDERFLOW = -1073741677
3592
- STATUS_INTEGER_DIVIDE_BY_ZERO = -1073741676
3593
- STATUS_INTEGER_OVERFLOW = -1073741675
3594
- STATUS_PRIVILEGED_INSTRUCTION = -1073741674
3595
- STATUS_STACK_OVERFLOW = -1073741571
3596
- STATUS_CONTROL_C_EXIT = -1073741510
3568
+ STATUS_WAIT_0 = 0
3569
+ STATUS_ABANDONED_WAIT_0 = 128
3570
+ STATUS_USER_APC = 192
3571
+ STATUS_TIMEOUT = 258
3572
+ STATUS_PENDING = 259
3573
+ STATUS_SEGMENT_NOTIFICATION = 1073741829
3574
+ STATUS_GUARD_PAGE_VIOLATION = -2147483647
3575
+ STATUS_DATATYPE_MISALIGNMENT = -2147483646
3576
+ STATUS_BREAKPOINT = -2147483645
3577
+ STATUS_SINGLE_STEP = -2147483644
3578
+ STATUS_ACCESS_VIOLATION = -1073741819
3579
+ STATUS_IN_PAGE_ERROR = -1073741818
3580
+ STATUS_INVALID_HANDLE = -1073741816
3581
+ STATUS_NO_MEMORY = -1073741801
3582
+ STATUS_ILLEGAL_INSTRUCTION = -1073741795
3583
+ STATUS_NONCONTINUABLE_EXCEPTION = -1073741787
3584
+ STATUS_INVALID_DISPOSITION = -1073741786
3585
+ STATUS_ARRAY_BOUNDS_EXCEEDED = -1073741684
3586
+ STATUS_FLOAT_DENORMAL_OPERAND = -1073741683
3587
+ STATUS_FLOAT_DIVIDE_BY_ZERO = -1073741682
3588
+ STATUS_FLOAT_INEXACT_RESULT = -1073741681
3589
+ STATUS_FLOAT_INVALID_OPERATION = -1073741680
3590
+ STATUS_FLOAT_OVERFLOW = -1073741679
3591
+ STATUS_FLOAT_STACK_CHECK = -1073741678
3592
+ STATUS_FLOAT_UNDERFLOW = -1073741677
3593
+ STATUS_INTEGER_DIVIDE_BY_ZERO = -1073741676
3594
+ STATUS_INTEGER_OVERFLOW = -1073741675
3595
+ STATUS_PRIVILEGED_INSTRUCTION = -1073741674
3596
+ STATUS_STACK_OVERFLOW = -1073741571
3597
+ STATUS_CONTROL_C_EXIT = -1073741510
3597
3598
 
3598
3599
 
3599
3600
  WAIT_FAILED = -1
3600
3601
  WAIT_OBJECT_0 = STATUS_WAIT_0 + 0
3601
3602
 
3602
- WAIT_ABANDONED = STATUS_ABANDONED_WAIT_0 + 0
3603
+ WAIT_ABANDONED = STATUS_ABANDONED_WAIT_0 + 0
3603
3604
  WAIT_ABANDONED_0 = STATUS_ABANDONED_WAIT_0 + 0
3604
3605
 
3605
3606
  WAIT_TIMEOUT = STATUS_TIMEOUT
@@ -4186,7 +4187,7 @@ PM_NOREMOVE = 0
4186
4187
  PM_REMOVE = 1
4187
4188
  PM_NOYIELD = 2
4188
4189
  # Name clashes with key.MOD_ALT, key.MOD_CONTROL and key.MOD_SHIFT
4189
- WIN32_MOD_ALT = 1
4190
+ WIN32_MOD_ALT = 1
4190
4191
  WIN32_MOD_CONTROL = 2
4191
4192
  WIN32_MOD_SHIFT = 4
4192
4193
  WIN32_MOD_WIN = 8
@@ -5037,6 +5038,7 @@ WINDOWS_8_1_OR_GREATER = sys.getwindowsversion() >= (6, 3)
5037
5038
  WINDOWS_10_ANNIVERSARY_UPDATE_OR_GREATER = sys.getwindowsversion() >= (10, 0, 14393) # 1607
5038
5039
  WINDOWS_10_CREATORS_UPDATE_OR_GREATER = sys.getwindowsversion() >= (10, 0, 15063) # 1703
5039
5040
  WINDOWS_10_1809_OR_GREATER = sys.getwindowsversion() >= (10, 0, 17763) # 1809
5041
+ WINDOWS_11_21H2_OR_GREATER = sys.getwindowsversion() >= (10, 0, 22000)
5040
5042
 
5041
5043
  MSGFLT_ALLOW = 1
5042
5044
  MSGFLT_DISALLOW = 2
@@ -5086,4 +5088,13 @@ USER_DEFAULT_SCREEN_DPI = 96
5086
5088
 
5087
5089
  QDC_ONLY_ACTIVE_PATHS = 0x00000002
5088
5090
  DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 0x00000001
5089
- DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 0x00000002
5091
+ DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 0x00000002
5092
+
5093
+ # Since Windows 11 21H2
5094
+ DWMWA_USE_IMMERSIVE_DARK_MODE = 20
5095
+ DWMWA_WINDOW_CORNER_PREFERENCE = 33
5096
+ DWMWA_BORDER_COLOR = 34
5097
+ DWMWA_CAPTION_COLOR = 35
5098
+ DWMWA_TEXT_COLOR = 36
5099
+ DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37
5100
+ DWMWA_SYSTEMBACKDROP_TYPE = 38
@@ -27,15 +27,20 @@ After::
27
27
  return result
28
28
 
29
29
  """
30
+ from __future__ import annotations
31
+
30
32
  from contextlib import contextmanager
31
- from typing import Optional, Generator
32
- from ctypes.wintypes import HANDLE
33
+ from typing import Generator, TYPE_CHECKING
33
34
  from ctypes import WinError
34
35
  from pyglet.libs.win32 import _user32 as user32
35
36
 
37
+ if TYPE_CHECKING:
38
+ from pyglet.libs.win32.com import COMObject
39
+ from ctypes.wintypes import HANDLE
40
+
36
41
 
37
42
  @contextmanager
38
- def device_context(window_handle: Optional[int] = None) -> Generator[HANDLE, None, None]:
43
+ def device_context(window_handle: int | None = None) -> Generator[HANDLE, None, None]:
39
44
  """
40
45
  A Windows device context wrapped as a context manager.
41
46
 
@@ -55,3 +60,15 @@ def device_context(window_handle: Optional[int] = None) -> Generator[HANDLE, Non
55
60
  finally:
56
61
  if not user32.ReleaseDC(None, _dc):
57
62
  raise WinError()
63
+
64
+
65
+ @contextmanager
66
+ def com_context(com_object: COMObject) -> Generator[COMObject, None, None]:
67
+ """A simple context manager for a COM object.
68
+
69
+ This can help reduce missed release calls leading to leaks.
70
+ """
71
+ try:
72
+ yield com_object
73
+ finally:
74
+ com_object.Release()
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import ctypes
4
- from ctypes.wintypes import BOOL, DWORD, HANDLE, HWND, LPDWORD, LPVOID, UINT, WCHAR, WORD
4
+ from ctypes.wintypes import BOOL, DWORD, HANDLE, HWND, LONG, LPDWORD, LPVOID, UINT, WCHAR, WORD
5
5
 
6
6
  from pyglet.libs.win32 import com
7
7
 
@@ -122,8 +122,10 @@ DIDC_ALIAS = 0x00010000
122
122
  DIDC_PHANTOM = 0x00020000
123
123
  DIDC_HIDDEN = 0x00040000
124
124
 
125
+
125
126
  def DIDFT_GETINSTANCE(n):
126
- return (n >> 8) & 0xffff
127
+ return (n >> 8) & 0xFFFF
128
+
127
129
 
128
130
  DIDFT_ALL = 0x00000000
129
131
 
@@ -204,8 +206,7 @@ DISCL_NOWINKEY = 0x00000010
204
206
  DIPROP_BUFFERSIZE = 1
205
207
  DIPROP_GUIDANDPATH = 12
206
208
 
207
- GUID_XAxis = \
208
- com.GUID(0xA36D02E0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00)
209
+ GUID_XAxis = com.GUID(0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00)
209
210
 
210
211
 
211
212
  class DIDEVICEINSTANCE(ctypes.Structure):
@@ -220,9 +221,12 @@ class DIDEVICEINSTANCE(ctypes.Structure):
220
221
  ('wUsagePage', WORD),
221
222
  ('wUsage', WORD),
222
223
  )
224
+
225
+
223
226
  LPDIDEVICEINSTANCE = ctypes.POINTER(DIDEVICEINSTANCE)
224
227
  LPDIENUMDEVICESCALLBACK = ctypes.WINFUNCTYPE(BOOL, LPDIDEVICEINSTANCE, LPVOID)
225
228
 
229
+
226
230
  class DIDEVICEOBJECTINSTANCE(ctypes.Structure):
227
231
  _fields_ = (
228
232
  ('dwSize', DWORD),
@@ -241,9 +245,11 @@ class DIDEVICEOBJECTINSTANCE(ctypes.Structure):
241
245
  ('wExponent', WORD),
242
246
  ('wReportId', WORD),
243
247
  )
248
+
249
+
244
250
  LPDIDEVICEOBJECTINSTANCE = ctypes.POINTER(DIDEVICEOBJECTINSTANCE)
245
- LPDIENUMDEVICEOBJECTSCALLBACK = \
246
- ctypes.WINFUNCTYPE( BOOL, LPDIDEVICEOBJECTINSTANCE, LPVOID)
251
+ LPDIENUMDEVICEOBJECTSCALLBACK = ctypes.WINFUNCTYPE(BOOL, LPDIDEVICEOBJECTINSTANCE, LPVOID)
252
+
247
253
 
248
254
  class DIOBJECTDATAFORMAT(ctypes.Structure):
249
255
  _fields_ = (
@@ -253,8 +259,11 @@ class DIOBJECTDATAFORMAT(ctypes.Structure):
253
259
  ('dwFlags', DWORD),
254
260
  )
255
261
  __slots__ = [n for n, t in _fields_]
262
+
263
+
256
264
  LPDIOBJECTDATAFORMAT = ctypes.POINTER(DIOBJECTDATAFORMAT)
257
265
 
266
+
258
267
  class DIDATAFORMAT(ctypes.Structure):
259
268
  _fields_ = (
260
269
  ('dwSize', DWORD),
@@ -265,8 +274,11 @@ class DIDATAFORMAT(ctypes.Structure):
265
274
  ('rgodf', LPDIOBJECTDATAFORMAT),
266
275
  )
267
276
  __slots__ = [n for n, t in _fields_]
277
+
278
+
268
279
  LPDIDATAFORMAT = ctypes.POINTER(DIDATAFORMAT)
269
280
 
281
+
270
282
  class DIDEVICEOBJECTDATA(ctypes.Structure):
271
283
  _fields_ = (
272
284
  ('dwOfs', DWORD),
@@ -275,8 +287,11 @@ class DIDEVICEOBJECTDATA(ctypes.Structure):
275
287
  ('dwSequence', DWORD),
276
288
  ('uAppData', ctypes.POINTER(UINT)),
277
289
  )
290
+
291
+
278
292
  LPDIDEVICEOBJECTDATA = ctypes.POINTER(DIDEVICEOBJECTDATA)
279
293
 
294
+
280
295
  class DIPROPHEADER(ctypes.Structure):
281
296
  _fields_ = (
282
297
  ('dwSize', DWORD),
@@ -284,109 +299,111 @@ class DIPROPHEADER(ctypes.Structure):
284
299
  ('dwObj', DWORD),
285
300
  ('dwHow', DWORD),
286
301
  )
302
+
303
+
287
304
  LPDIPROPHEADER = ctypes.POINTER(DIPROPHEADER)
288
305
 
306
+
289
307
  class DIPROPDWORD(ctypes.Structure):
290
308
  _fields_ = (
291
309
  ('diph', DIPROPHEADER),
292
310
  ('dwData', DWORD),
293
311
  )
294
312
 
313
+
295
314
  # All method names in the interfaces are filled in, but unused (so far)
296
315
  # methods have no parameters.. they'll crash when we try and use them, at
297
316
  # which point we can go in and fill them in.
298
317
 
318
+
319
+ # Define DIJOYSTATE2 based on the C++ struct
320
+ class DIJOYSTATE2(ctypes.Structure):
321
+ _fields_ = [
322
+ ("lX", LONG), # X-axis
323
+ ("lY", LONG), # Y-axis
324
+ ("lZ", LONG), # Z-axis
325
+ ("lRx", LONG), # X-axis rotation
326
+ ("lRy", LONG), # Y-axis rotation
327
+ ("lRz", LONG), # Z-axis rotation
328
+ ("rglSlider", LONG * 2), # Two slider axes
329
+ ("rgdwPOV", DWORD * 4), # Four POVs (D-pad directions)
330
+ ("rgbButtons", ctypes.c_ubyte * 128), # 128 buttons
331
+ ("lVX", LONG), # X-axis velocity
332
+ ("lVY", LONG), # Y-axis velocity
333
+ ("lVZ", LONG), # Z-axis velocity
334
+ ("lVRx", LONG), # Angular velocity X
335
+ ("lVRy", LONG), # Angular velocity Y
336
+ ("lVRz", LONG), # Angular velocity Z
337
+ ("rglVSlider", LONG * 2),
338
+ ("lAX", LONG), # Acceleration X
339
+ ("lAY", LONG), # Acceleration Y
340
+ ("lAZ", LONG), # Acceleration Z
341
+ ("lARx", LONG), # Angular acceleration X
342
+ ("lARy", LONG), # Angular acceleration Y
343
+ ("lARz", LONG), # Angular acceleration Z
344
+ ("rglASlider", LONG * 2),
345
+ ("lFX", LONG), # Force X
346
+ ("lFY", LONG), # Force Y
347
+ ("lFZ", LONG), # Force Z
348
+ ("lFRx", LONG), # Force angular X
349
+ ("lFRy", LONG), # Force angular Y
350
+ ("lFRz", LONG), # Force angular Z
351
+ ("rglFSlider", LONG * 2),
352
+ ]
353
+
354
+
299
355
  # IDirect* interfaces are all Unicode (e.g. IDirectInputDevice8W).
300
356
 
357
+
301
358
  class IDirectInputDevice8(com.pIUnknown):
302
359
  _methods_ = [
303
- ('GetCapabilities',
304
- com.STDMETHOD()),
305
- ('EnumObjects',
306
- com.STDMETHOD(LPDIENUMDEVICEOBJECTSCALLBACK, LPVOID, DWORD)),
307
- ('GetProperty',
308
- com.STDMETHOD(LPVOID, LPDIPROPHEADER)),
309
- ('SetProperty',
310
- com.STDMETHOD(LPVOID, LPDIPROPHEADER)),
311
- ('Acquire',
312
- com.STDMETHOD()),
313
- ('Unacquire',
314
- com.STDMETHOD()),
315
- ('GetDeviceState',
316
- com.STDMETHOD()),
317
- ('GetDeviceData',
318
- com.STDMETHOD(DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD)),
319
- ('SetDataFormat',
320
- com.STDMETHOD(LPDIDATAFORMAT)),
321
- ('SetEventNotification',
322
- com.STDMETHOD(HANDLE)),
323
- ('SetCooperativeLevel',
324
- com.STDMETHOD(HWND, DWORD)),
325
- ('GetObjectInfo',
326
- com.STDMETHOD()),
327
- ('GetDeviceInfo',
328
- com.STDMETHOD()),
329
- ('RunControlPanel',
330
- com.STDMETHOD()),
331
- ('Initialize',
332
- com.STDMETHOD()),
333
- ('CreateEffect',
334
- com.STDMETHOD()),
335
- ('EnumEffects',
336
- com.STDMETHOD()),
337
- ('GetEffectInfo',
338
- com.STDMETHOD()),
339
- ('GetForceFeedbackState',
340
- com.STDMETHOD()),
341
- ('SendForceFeedbackCommand',
342
- com.STDMETHOD()),
343
- ('EnumCreatedEffectObjects',
344
- com.STDMETHOD()),
345
- ('Escape',
346
- com.STDMETHOD()),
347
- ('Poll',
348
- com.STDMETHOD()),
349
- ('SendDeviceData',
350
- com.STDMETHOD()),
351
- ('EnumEffectsInFile',
352
- com.STDMETHOD()),
353
- ('WriteEffectToFile',
354
- com.STDMETHOD()),
355
- ('BuildActionMap',
356
- com.STDMETHOD()),
357
- ('SetActionMap',
358
- com.STDMETHOD()),
359
- ('GetImageInfo',
360
- com.STDMETHOD()),
361
- ]
360
+ ('GetCapabilities', com.STDMETHOD()),
361
+ ('EnumObjects', com.STDMETHOD(LPDIENUMDEVICEOBJECTSCALLBACK, LPVOID, DWORD)),
362
+ ('GetProperty', com.STDMETHOD(LPVOID, LPDIPROPHEADER)),
363
+ ('SetProperty', com.STDMETHOD(LPVOID, LPDIPROPHEADER)),
364
+ ('Acquire', com.STDMETHOD()),
365
+ ('Unacquire', com.STDMETHOD()),
366
+ ('GetDeviceState', com.STDMETHOD(DWORD, LPVOID)),
367
+ ('GetDeviceData', com.STDMETHOD(DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD)),
368
+ ('SetDataFormat', com.STDMETHOD(LPDIDATAFORMAT)),
369
+ ('SetEventNotification', com.STDMETHOD(HANDLE)),
370
+ ('SetCooperativeLevel', com.STDMETHOD(HWND, DWORD)),
371
+ ('GetObjectInfo', com.STDMETHOD()),
372
+ ('GetDeviceInfo', com.STDMETHOD()),
373
+ ('RunControlPanel', com.STDMETHOD()),
374
+ ('Initialize', com.STDMETHOD()),
375
+ ('CreateEffect', com.STDMETHOD()),
376
+ ('EnumEffects', com.STDMETHOD()),
377
+ ('GetEffectInfo', com.STDMETHOD()),
378
+ ('GetForceFeedbackState', com.STDMETHOD()),
379
+ ('SendForceFeedbackCommand', com.STDMETHOD()),
380
+ ('EnumCreatedEffectObjects', com.STDMETHOD()),
381
+ ('Escape', com.STDMETHOD()),
382
+ ('Poll', com.STDMETHOD()),
383
+ ('SendDeviceData', com.STDMETHOD()),
384
+ ('EnumEffectsInFile', com.STDMETHOD()),
385
+ ('WriteEffectToFile', com.STDMETHOD()),
386
+ ('BuildActionMap', com.STDMETHOD()),
387
+ ('SetActionMap', com.STDMETHOD()),
388
+ ('GetImageInfo', com.STDMETHOD()),
389
+ ]
390
+
362
391
 
363
392
  class IDirectInput8(com.pIUnknown):
364
393
  _methods_ = [
365
- ('CreateDevice',
366
- com.STDMETHOD(ctypes.POINTER(com.GUID),
367
- ctypes.POINTER(IDirectInputDevice8),
368
- ctypes.c_void_p)),
369
- ('EnumDevices',
370
- com.STDMETHOD(DWORD, LPDIENUMDEVICESCALLBACK, LPVOID, DWORD)),
371
- ('GetDeviceStatus',
372
- com.STDMETHOD()),
373
- ('RunControlPanel',
374
- com.STDMETHOD()),
375
- ('Initialize',
376
- com.STDMETHOD()),
377
- ('FindDevice',
378
- com.STDMETHOD()),
379
- ('EnumDevicesBySemantics',
380
- com.STDMETHOD()),
381
- ('ConfigureDevices',
382
- com.STDMETHOD()),
394
+ ('CreateDevice', com.STDMETHOD(ctypes.POINTER(com.GUID), ctypes.POINTER(IDirectInputDevice8), ctypes.c_void_p)),
395
+ ('EnumDevices', com.STDMETHOD(DWORD, LPDIENUMDEVICESCALLBACK, LPVOID, DWORD)),
396
+ ('GetDeviceStatus', com.STDMETHOD()),
397
+ ('RunControlPanel', com.STDMETHOD()),
398
+ ('Initialize', com.STDMETHOD()),
399
+ ('FindDevice', com.STDMETHOD()),
400
+ ('EnumDevicesBySemantics', com.STDMETHOD()),
401
+ ('ConfigureDevices', com.STDMETHOD()),
383
402
  ]
384
403
 
385
- IID_IDirectInput8W = \
386
- com.GUID(0xBF798031,0x483A,0x4DA2,0xAA,0x99,0x5D,0x64,0xED,0x36,0x97,0x00)
404
+
405
+ IID_IDirectInput8W = com.GUID(0xBF798031, 0x483A, 0x4DA2, 0xAA, 0x99, 0x5D, 0x64, 0xED, 0x36, 0x97, 0x00)
387
406
 
388
407
  DIRECTINPUT_VERSION = 0x0800
389
408
  DirectInput8Create = lib.DirectInput8Create
390
- DirectInput8Create.argtypes = \
391
- (ctypes.c_void_p, DWORD, com.LPGUID, ctypes.c_void_p, ctypes.c_void_p)
392
-
409
+ DirectInput8Create.argtypes = (ctypes.c_void_p, DWORD, com.LPGUID, ctypes.c_void_p, ctypes.c_void_p)