vispy 0.14.0__cp311-cp311-macosx_11_0_arm64.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.

Potentially problematic release.


This version of vispy might be problematic. Click here for more details.

Files changed (519) hide show
  1. vispy/__init__.py +33 -0
  2. vispy/app/__init__.py +15 -0
  3. vispy/app/_default_app.py +76 -0
  4. vispy/app/_detect_eventloop.py +148 -0
  5. vispy/app/application.py +263 -0
  6. vispy/app/backends/__init__.py +52 -0
  7. vispy/app/backends/_egl.py +264 -0
  8. vispy/app/backends/_glfw.py +513 -0
  9. vispy/app/backends/_jupyter_rfb.py +278 -0
  10. vispy/app/backends/_offscreen_util.py +121 -0
  11. vispy/app/backends/_osmesa.py +235 -0
  12. vispy/app/backends/_pyglet.py +451 -0
  13. vispy/app/backends/_pyqt4.py +36 -0
  14. vispy/app/backends/_pyqt5.py +36 -0
  15. vispy/app/backends/_pyqt6.py +40 -0
  16. vispy/app/backends/_pyside.py +37 -0
  17. vispy/app/backends/_pyside2.py +52 -0
  18. vispy/app/backends/_pyside6.py +53 -0
  19. vispy/app/backends/_qt.py +968 -0
  20. vispy/app/backends/_sdl2.py +444 -0
  21. vispy/app/backends/_template.py +244 -0
  22. vispy/app/backends/_test.py +8 -0
  23. vispy/app/backends/_tk.py +800 -0
  24. vispy/app/backends/_wx.py +476 -0
  25. vispy/app/backends/tests/__init__.py +0 -0
  26. vispy/app/backends/tests/test_offscreen_util.py +52 -0
  27. vispy/app/backends/tests/test_rfb.py +77 -0
  28. vispy/app/base.py +294 -0
  29. vispy/app/canvas.py +828 -0
  30. vispy/app/qt.py +92 -0
  31. vispy/app/tests/__init__.py +0 -0
  32. vispy/app/tests/qt-designer.ui +58 -0
  33. vispy/app/tests/test_app.py +442 -0
  34. vispy/app/tests/test_backends.py +164 -0
  35. vispy/app/tests/test_canvas.py +122 -0
  36. vispy/app/tests/test_context.py +92 -0
  37. vispy/app/tests/test_qt.py +47 -0
  38. vispy/app/tests/test_simultaneous.py +134 -0
  39. vispy/app/timer.py +174 -0
  40. vispy/color/__init__.py +17 -0
  41. vispy/color/_color_dict.py +193 -0
  42. vispy/color/color_array.py +447 -0
  43. vispy/color/color_space.py +181 -0
  44. vispy/color/colormap.py +1134 -0
  45. vispy/color/tests/__init__.py +0 -0
  46. vispy/color/tests/test_color.py +352 -0
  47. vispy/conftest.py +12 -0
  48. vispy/ext/__init__.py +0 -0
  49. vispy/ext/cocoapy.py +1542 -0
  50. vispy/ext/cubehelix.py +138 -0
  51. vispy/ext/egl.py +375 -0
  52. vispy/ext/fontconfig.py +118 -0
  53. vispy/ext/gdi32plus.py +206 -0
  54. vispy/ext/osmesa.py +105 -0
  55. vispy/geometry/__init__.py +23 -0
  56. vispy/geometry/_triangulation_debugger.py +171 -0
  57. vispy/geometry/calculations.py +134 -0
  58. vispy/geometry/curves.py +399 -0
  59. vispy/geometry/generation.py +643 -0
  60. vispy/geometry/isocurve.py +175 -0
  61. vispy/geometry/isosurface.py +465 -0
  62. vispy/geometry/meshdata.py +698 -0
  63. vispy/geometry/normals.py +78 -0
  64. vispy/geometry/parametric.py +56 -0
  65. vispy/geometry/polygon.py +137 -0
  66. vispy/geometry/rect.py +210 -0
  67. vispy/geometry/tests/__init__.py +0 -0
  68. vispy/geometry/tests/test_calculations.py +23 -0
  69. vispy/geometry/tests/test_generation.py +56 -0
  70. vispy/geometry/tests/test_meshdata.py +106 -0
  71. vispy/geometry/tests/test_triangulation.py +506 -0
  72. vispy/geometry/torusknot.py +142 -0
  73. vispy/geometry/triangulation.py +876 -0
  74. vispy/gloo/__init__.py +56 -0
  75. vispy/gloo/buffer.py +505 -0
  76. vispy/gloo/context.py +272 -0
  77. vispy/gloo/framebuffer.py +257 -0
  78. vispy/gloo/gl/__init__.py +234 -0
  79. vispy/gloo/gl/_constants.py +332 -0
  80. vispy/gloo/gl/_es2.py +986 -0
  81. vispy/gloo/gl/_gl2.py +1365 -0
  82. vispy/gloo/gl/_proxy.py +499 -0
  83. vispy/gloo/gl/_pyopengl2.py +362 -0
  84. vispy/gloo/gl/dummy.py +24 -0
  85. vispy/gloo/gl/es2.py +62 -0
  86. vispy/gloo/gl/gl2.py +98 -0
  87. vispy/gloo/gl/glplus.py +168 -0
  88. vispy/gloo/gl/pyopengl2.py +97 -0
  89. vispy/gloo/gl/tests/__init__.py +0 -0
  90. vispy/gloo/gl/tests/test_basics.py +282 -0
  91. vispy/gloo/gl/tests/test_functionality.py +566 -0
  92. vispy/gloo/gl/tests/test_names.py +246 -0
  93. vispy/gloo/gl/tests/test_use.py +71 -0
  94. vispy/gloo/glir.py +1816 -0
  95. vispy/gloo/globject.py +101 -0
  96. vispy/gloo/preprocessor.py +67 -0
  97. vispy/gloo/program.py +543 -0
  98. vispy/gloo/tests/__init__.py +0 -0
  99. vispy/gloo/tests/test_buffer.py +558 -0
  100. vispy/gloo/tests/test_context.py +119 -0
  101. vispy/gloo/tests/test_framebuffer.py +195 -0
  102. vispy/gloo/tests/test_glir.py +307 -0
  103. vispy/gloo/tests/test_globject.py +35 -0
  104. vispy/gloo/tests/test_program.py +302 -0
  105. vispy/gloo/tests/test_texture.py +732 -0
  106. vispy/gloo/tests/test_use_gloo.py +187 -0
  107. vispy/gloo/tests/test_util.py +60 -0
  108. vispy/gloo/tests/test_wrappers.py +261 -0
  109. vispy/gloo/texture.py +1045 -0
  110. vispy/gloo/util.py +129 -0
  111. vispy/gloo/wrappers.py +762 -0
  112. vispy/glsl/__init__.py +42 -0
  113. vispy/glsl/antialias/antialias.glsl +7 -0
  114. vispy/glsl/antialias/cap-butt.glsl +31 -0
  115. vispy/glsl/antialias/cap-round.glsl +29 -0
  116. vispy/glsl/antialias/cap-square.glsl +30 -0
  117. vispy/glsl/antialias/cap-triangle-in.glsl +30 -0
  118. vispy/glsl/antialias/cap-triangle-out.glsl +30 -0
  119. vispy/glsl/antialias/cap.glsl +67 -0
  120. vispy/glsl/antialias/caps.glsl +67 -0
  121. vispy/glsl/antialias/filled.glsl +50 -0
  122. vispy/glsl/antialias/outline.glsl +40 -0
  123. vispy/glsl/antialias/stroke.glsl +43 -0
  124. vispy/glsl/arrowheads/angle.glsl +99 -0
  125. vispy/glsl/arrowheads/arrowheads.frag +60 -0
  126. vispy/glsl/arrowheads/arrowheads.glsl +12 -0
  127. vispy/glsl/arrowheads/arrowheads.vert +83 -0
  128. vispy/glsl/arrowheads/curved.glsl +48 -0
  129. vispy/glsl/arrowheads/inhibitor.glsl +26 -0
  130. vispy/glsl/arrowheads/stealth.glsl +46 -0
  131. vispy/glsl/arrowheads/triangle.glsl +97 -0
  132. vispy/glsl/arrowheads/util.glsl +13 -0
  133. vispy/glsl/arrows/angle-30.glsl +12 -0
  134. vispy/glsl/arrows/angle-60.glsl +12 -0
  135. vispy/glsl/arrows/angle-90.glsl +12 -0
  136. vispy/glsl/arrows/arrow.frag +39 -0
  137. vispy/glsl/arrows/arrow.vert +49 -0
  138. vispy/glsl/arrows/arrows.glsl +17 -0
  139. vispy/glsl/arrows/common.glsl +187 -0
  140. vispy/glsl/arrows/curved.glsl +63 -0
  141. vispy/glsl/arrows/stealth.glsl +50 -0
  142. vispy/glsl/arrows/triangle-30.glsl +12 -0
  143. vispy/glsl/arrows/triangle-60.glsl +12 -0
  144. vispy/glsl/arrows/triangle-90.glsl +12 -0
  145. vispy/glsl/arrows/util.glsl +98 -0
  146. vispy/glsl/build_spatial_filters.py +660 -0
  147. vispy/glsl/collections/agg-fast-path.frag +20 -0
  148. vispy/glsl/collections/agg-fast-path.vert +78 -0
  149. vispy/glsl/collections/agg-glyph.frag +60 -0
  150. vispy/glsl/collections/agg-glyph.vert +33 -0
  151. vispy/glsl/collections/agg-marker.frag +35 -0
  152. vispy/glsl/collections/agg-marker.vert +48 -0
  153. vispy/glsl/collections/agg-path.frag +55 -0
  154. vispy/glsl/collections/agg-path.vert +166 -0
  155. vispy/glsl/collections/agg-point.frag +21 -0
  156. vispy/glsl/collections/agg-point.vert +35 -0
  157. vispy/glsl/collections/agg-segment.frag +32 -0
  158. vispy/glsl/collections/agg-segment.vert +75 -0
  159. vispy/glsl/collections/marker.frag +38 -0
  160. vispy/glsl/collections/marker.vert +48 -0
  161. vispy/glsl/collections/raw-path.frag +15 -0
  162. vispy/glsl/collections/raw-path.vert +24 -0
  163. vispy/glsl/collections/raw-point.frag +14 -0
  164. vispy/glsl/collections/raw-point.vert +31 -0
  165. vispy/glsl/collections/raw-segment.frag +18 -0
  166. vispy/glsl/collections/raw-segment.vert +26 -0
  167. vispy/glsl/collections/raw-triangle.frag +13 -0
  168. vispy/glsl/collections/raw-triangle.vert +26 -0
  169. vispy/glsl/collections/sdf-glyph-ticks.vert +69 -0
  170. vispy/glsl/collections/sdf-glyph.frag +80 -0
  171. vispy/glsl/collections/sdf-glyph.vert +59 -0
  172. vispy/glsl/collections/tick-labels.vert +71 -0
  173. vispy/glsl/colormaps/autumn.glsl +20 -0
  174. vispy/glsl/colormaps/blues.glsl +20 -0
  175. vispy/glsl/colormaps/color-space.glsl +17 -0
  176. vispy/glsl/colormaps/colormaps.glsl +24 -0
  177. vispy/glsl/colormaps/cool.glsl +20 -0
  178. vispy/glsl/colormaps/fire.glsl +21 -0
  179. vispy/glsl/colormaps/gray.glsl +20 -0
  180. vispy/glsl/colormaps/greens.glsl +20 -0
  181. vispy/glsl/colormaps/hot.glsl +22 -0
  182. vispy/glsl/colormaps/ice.glsl +20 -0
  183. vispy/glsl/colormaps/icefire.glsl +23 -0
  184. vispy/glsl/colormaps/parse.py +40 -0
  185. vispy/glsl/colormaps/reds.glsl +20 -0
  186. vispy/glsl/colormaps/spring.glsl +20 -0
  187. vispy/glsl/colormaps/summer.glsl +20 -0
  188. vispy/glsl/colormaps/user.glsl +22 -0
  189. vispy/glsl/colormaps/util.glsl +41 -0
  190. vispy/glsl/colormaps/wheel.glsl +21 -0
  191. vispy/glsl/colormaps/winter.glsl +20 -0
  192. vispy/glsl/lines/agg.frag +320 -0
  193. vispy/glsl/lines/agg.vert +241 -0
  194. vispy/glsl/markers/arrow.glsl +12 -0
  195. vispy/glsl/markers/asterisk.glsl +16 -0
  196. vispy/glsl/markers/chevron.glsl +14 -0
  197. vispy/glsl/markers/clover.glsl +20 -0
  198. vispy/glsl/markers/club.glsl +31 -0
  199. vispy/glsl/markers/cross.glsl +17 -0
  200. vispy/glsl/markers/diamond.glsl +12 -0
  201. vispy/glsl/markers/disc.glsl +9 -0
  202. vispy/glsl/markers/ellipse.glsl +67 -0
  203. vispy/glsl/markers/hbar.glsl +9 -0
  204. vispy/glsl/markers/heart.glsl +15 -0
  205. vispy/glsl/markers/infinity.glsl +15 -0
  206. vispy/glsl/markers/marker-sdf.frag +74 -0
  207. vispy/glsl/markers/marker-sdf.vert +41 -0
  208. vispy/glsl/markers/marker.frag +36 -0
  209. vispy/glsl/markers/marker.vert +46 -0
  210. vispy/glsl/markers/markers.glsl +24 -0
  211. vispy/glsl/markers/pin.glsl +18 -0
  212. vispy/glsl/markers/ring.glsl +11 -0
  213. vispy/glsl/markers/spade.glsl +28 -0
  214. vispy/glsl/markers/square.glsl +10 -0
  215. vispy/glsl/markers/tag.glsl +11 -0
  216. vispy/glsl/markers/triangle.glsl +14 -0
  217. vispy/glsl/markers/vbar.glsl +9 -0
  218. vispy/glsl/math/circle-through-2-points.glsl +30 -0
  219. vispy/glsl/math/constants.glsl +48 -0
  220. vispy/glsl/math/double.glsl +114 -0
  221. vispy/glsl/math/functions.glsl +20 -0
  222. vispy/glsl/math/point-to-line-distance.glsl +31 -0
  223. vispy/glsl/math/point-to-line-projection.glsl +29 -0
  224. vispy/glsl/math/signed-line-distance.glsl +27 -0
  225. vispy/glsl/math/signed-segment-distance.glsl +30 -0
  226. vispy/glsl/misc/regular-grid.frag +244 -0
  227. vispy/glsl/misc/spatial-filters.frag +1407 -0
  228. vispy/glsl/misc/viewport-NDC.glsl +20 -0
  229. vispy/glsl/transforms/azimuthal-equal-area.glsl +32 -0
  230. vispy/glsl/transforms/azimuthal-equidistant.glsl +38 -0
  231. vispy/glsl/transforms/hammer.glsl +44 -0
  232. vispy/glsl/transforms/identity.glsl +6 -0
  233. vispy/glsl/transforms/identity_forward.glsl +23 -0
  234. vispy/glsl/transforms/identity_inverse.glsl +23 -0
  235. vispy/glsl/transforms/linear-scale.glsl +127 -0
  236. vispy/glsl/transforms/log-scale.glsl +126 -0
  237. vispy/glsl/transforms/mercator-transverse-forward.glsl +40 -0
  238. vispy/glsl/transforms/mercator-transverse-inverse.glsl +40 -0
  239. vispy/glsl/transforms/panzoom.glsl +10 -0
  240. vispy/glsl/transforms/polar.glsl +41 -0
  241. vispy/glsl/transforms/position.glsl +44 -0
  242. vispy/glsl/transforms/power-scale.glsl +139 -0
  243. vispy/glsl/transforms/projection.glsl +7 -0
  244. vispy/glsl/transforms/pvm.glsl +13 -0
  245. vispy/glsl/transforms/rotate.glsl +45 -0
  246. vispy/glsl/transforms/trackball.glsl +15 -0
  247. vispy/glsl/transforms/translate.glsl +35 -0
  248. vispy/glsl/transforms/transverse_mercator.glsl +38 -0
  249. vispy/glsl/transforms/viewport-clipping.glsl +14 -0
  250. vispy/glsl/transforms/viewport-transform.glsl +16 -0
  251. vispy/glsl/transforms/viewport.glsl +50 -0
  252. vispy/glsl/transforms/x.glsl +24 -0
  253. vispy/glsl/transforms/y.glsl +19 -0
  254. vispy/glsl/transforms/z.glsl +14 -0
  255. vispy/io/__init__.py +20 -0
  256. vispy/io/_data/spatial-filters.npy +0 -0
  257. vispy/io/datasets.py +94 -0
  258. vispy/io/image.py +231 -0
  259. vispy/io/mesh.py +122 -0
  260. vispy/io/stl.py +167 -0
  261. vispy/io/tests/__init__.py +0 -0
  262. vispy/io/tests/test_image.py +47 -0
  263. vispy/io/tests/test_io.py +121 -0
  264. vispy/io/wavefront.py +350 -0
  265. vispy/plot/__init__.py +36 -0
  266. vispy/plot/fig.py +58 -0
  267. vispy/plot/plotwidget.py +522 -0
  268. vispy/plot/tests/__init__.py +0 -0
  269. vispy/plot/tests/test_plot.py +46 -0
  270. vispy/scene/__init__.py +43 -0
  271. vispy/scene/cameras/__init__.py +27 -0
  272. vispy/scene/cameras/_base.py +38 -0
  273. vispy/scene/cameras/arcball.py +106 -0
  274. vispy/scene/cameras/base_camera.py +538 -0
  275. vispy/scene/cameras/fly.py +474 -0
  276. vispy/scene/cameras/magnify.py +163 -0
  277. vispy/scene/cameras/panzoom.py +308 -0
  278. vispy/scene/cameras/perspective.py +333 -0
  279. vispy/scene/cameras/tests/__init__.py +0 -0
  280. vispy/scene/cameras/tests/test_cameras.py +27 -0
  281. vispy/scene/cameras/tests/test_link.py +53 -0
  282. vispy/scene/cameras/tests/test_perspective.py +122 -0
  283. vispy/scene/cameras/turntable.py +173 -0
  284. vispy/scene/canvas.py +639 -0
  285. vispy/scene/events.py +85 -0
  286. vispy/scene/node.py +644 -0
  287. vispy/scene/subscene.py +20 -0
  288. vispy/scene/tests/__init__.py +0 -0
  289. vispy/scene/tests/test_canvas.py +119 -0
  290. vispy/scene/tests/test_node.py +142 -0
  291. vispy/scene/tests/test_visuals.py +141 -0
  292. vispy/scene/visuals.py +276 -0
  293. vispy/scene/widgets/__init__.py +18 -0
  294. vispy/scene/widgets/anchor.py +25 -0
  295. vispy/scene/widgets/axis.py +88 -0
  296. vispy/scene/widgets/colorbar.py +176 -0
  297. vispy/scene/widgets/console.py +351 -0
  298. vispy/scene/widgets/grid.py +509 -0
  299. vispy/scene/widgets/label.py +50 -0
  300. vispy/scene/widgets/tests/__init__.py +0 -0
  301. vispy/scene/widgets/tests/test_colorbar.py +47 -0
  302. vispy/scene/widgets/viewbox.py +199 -0
  303. vispy/scene/widgets/widget.py +478 -0
  304. vispy/testing/__init__.py +51 -0
  305. vispy/testing/_runners.py +446 -0
  306. vispy/testing/_testing.py +416 -0
  307. vispy/testing/image_tester.py +473 -0
  308. vispy/testing/rendered_array_tester.py +85 -0
  309. vispy/testing/tests/__init__.py +0 -0
  310. vispy/testing/tests/test_testing.py +20 -0
  311. vispy/util/__init__.py +17 -0
  312. vispy/util/bunch.py +15 -0
  313. vispy/util/check_environment.py +57 -0
  314. vispy/util/config.py +490 -0
  315. vispy/util/dpi/__init__.py +19 -0
  316. vispy/util/dpi/_linux.py +69 -0
  317. vispy/util/dpi/_quartz.py +26 -0
  318. vispy/util/dpi/_win32.py +34 -0
  319. vispy/util/dpi/tests/__init__.py +0 -0
  320. vispy/util/dpi/tests/test_dpi.py +16 -0
  321. vispy/util/eq.py +41 -0
  322. vispy/util/event.py +774 -0
  323. vispy/util/fetching.py +276 -0
  324. vispy/util/filter.py +44 -0
  325. vispy/util/fonts/__init__.py +14 -0
  326. vispy/util/fonts/_freetype.py +73 -0
  327. vispy/util/fonts/_quartz.py +192 -0
  328. vispy/util/fonts/_triage.py +36 -0
  329. vispy/util/fonts/_vispy_fonts.py +20 -0
  330. vispy/util/fonts/_win32.py +105 -0
  331. vispy/util/fonts/data/OpenSans-Bold.ttf +0 -0
  332. vispy/util/fonts/data/OpenSans-BoldItalic.ttf +0 -0
  333. vispy/util/fonts/data/OpenSans-Italic.ttf +0 -0
  334. vispy/util/fonts/data/OpenSans-Regular.ttf +0 -0
  335. vispy/util/fonts/tests/__init__.py +0 -0
  336. vispy/util/fonts/tests/test_font.py +45 -0
  337. vispy/util/fourier.py +69 -0
  338. vispy/util/frozen.py +25 -0
  339. vispy/util/gallery_scraper.py +268 -0
  340. vispy/util/keys.py +91 -0
  341. vispy/util/logs.py +358 -0
  342. vispy/util/osmesa_gl.py +17 -0
  343. vispy/util/profiler.py +135 -0
  344. vispy/util/ptime.py +16 -0
  345. vispy/util/quaternion.py +229 -0
  346. vispy/util/svg/__init__.py +18 -0
  347. vispy/util/svg/base.py +20 -0
  348. vispy/util/svg/color.py +219 -0
  349. vispy/util/svg/element.py +51 -0
  350. vispy/util/svg/geometry.py +478 -0
  351. vispy/util/svg/group.py +66 -0
  352. vispy/util/svg/length.py +81 -0
  353. vispy/util/svg/number.py +25 -0
  354. vispy/util/svg/path.py +332 -0
  355. vispy/util/svg/shapes.py +57 -0
  356. vispy/util/svg/style.py +59 -0
  357. vispy/util/svg/svg.py +40 -0
  358. vispy/util/svg/transform.py +223 -0
  359. vispy/util/svg/transformable.py +28 -0
  360. vispy/util/svg/viewport.py +73 -0
  361. vispy/util/tests/__init__.py +0 -0
  362. vispy/util/tests/test_config.py +58 -0
  363. vispy/util/tests/test_docstring_parameters.py +123 -0
  364. vispy/util/tests/test_emitter_group.py +262 -0
  365. vispy/util/tests/test_event_emitter.py +743 -0
  366. vispy/util/tests/test_fourier.py +35 -0
  367. vispy/util/tests/test_gallery_scraper.py +112 -0
  368. vispy/util/tests/test_import.py +127 -0
  369. vispy/util/tests/test_key.py +22 -0
  370. vispy/util/tests/test_logging.py +45 -0
  371. vispy/util/tests/test_run.py +14 -0
  372. vispy/util/tests/test_transforms.py +42 -0
  373. vispy/util/tests/test_vispy.py +48 -0
  374. vispy/util/transforms.py +201 -0
  375. vispy/util/wrappers.py +155 -0
  376. vispy/version.py +4 -0
  377. vispy/visuals/__init__.py +50 -0
  378. vispy/visuals/_scalable_textures.py +485 -0
  379. vispy/visuals/axis.py +678 -0
  380. vispy/visuals/border.py +208 -0
  381. vispy/visuals/box.py +79 -0
  382. vispy/visuals/collections/__init__.py +30 -0
  383. vispy/visuals/collections/agg_fast_path_collection.py +219 -0
  384. vispy/visuals/collections/agg_path_collection.py +197 -0
  385. vispy/visuals/collections/agg_point_collection.py +52 -0
  386. vispy/visuals/collections/agg_segment_collection.py +142 -0
  387. vispy/visuals/collections/array_list.py +401 -0
  388. vispy/visuals/collections/base_collection.py +482 -0
  389. vispy/visuals/collections/collection.py +253 -0
  390. vispy/visuals/collections/path_collection.py +23 -0
  391. vispy/visuals/collections/point_collection.py +19 -0
  392. vispy/visuals/collections/polygon_collection.py +25 -0
  393. vispy/visuals/collections/raw_path_collection.py +119 -0
  394. vispy/visuals/collections/raw_point_collection.py +113 -0
  395. vispy/visuals/collections/raw_polygon_collection.py +77 -0
  396. vispy/visuals/collections/raw_segment_collection.py +112 -0
  397. vispy/visuals/collections/raw_triangle_collection.py +78 -0
  398. vispy/visuals/collections/segment_collection.py +19 -0
  399. vispy/visuals/collections/triangle_collection.py +16 -0
  400. vispy/visuals/collections/util.py +168 -0
  401. vispy/visuals/colorbar.py +699 -0
  402. vispy/visuals/cube.py +41 -0
  403. vispy/visuals/ellipse.py +163 -0
  404. vispy/visuals/filters/__init__.py +10 -0
  405. vispy/visuals/filters/base_filter.py +242 -0
  406. vispy/visuals/filters/clipper.py +60 -0
  407. vispy/visuals/filters/clipping_planes.py +122 -0
  408. vispy/visuals/filters/color.py +181 -0
  409. vispy/visuals/filters/markers.py +28 -0
  410. vispy/visuals/filters/mesh.py +796 -0
  411. vispy/visuals/filters/picking.py +60 -0
  412. vispy/visuals/filters/tests/__init__.py +3 -0
  413. vispy/visuals/filters/tests/test_primitive_picking_filters.py +70 -0
  414. vispy/visuals/filters/tests/test_wireframe_filter.py +16 -0
  415. vispy/visuals/glsl/__init__.py +1 -0
  416. vispy/visuals/glsl/antialiasing.py +133 -0
  417. vispy/visuals/glsl/color.py +63 -0
  418. vispy/visuals/graphs/__init__.py +1 -0
  419. vispy/visuals/graphs/graph.py +240 -0
  420. vispy/visuals/graphs/layouts/__init__.py +55 -0
  421. vispy/visuals/graphs/layouts/circular.py +49 -0
  422. vispy/visuals/graphs/layouts/force_directed.py +211 -0
  423. vispy/visuals/graphs/layouts/networkx_layout.py +87 -0
  424. vispy/visuals/graphs/layouts/random.py +52 -0
  425. vispy/visuals/graphs/tests/__init__.py +1 -0
  426. vispy/visuals/graphs/tests/test_layouts.py +139 -0
  427. vispy/visuals/graphs/tests/test_networkx_layout.py +47 -0
  428. vispy/visuals/graphs/util.py +120 -0
  429. vispy/visuals/gridlines.py +105 -0
  430. vispy/visuals/gridmesh.py +98 -0
  431. vispy/visuals/histogram.py +58 -0
  432. vispy/visuals/image.py +688 -0
  433. vispy/visuals/image_complex.py +130 -0
  434. vispy/visuals/infinite_line.py +199 -0
  435. vispy/visuals/instanced_mesh.py +152 -0
  436. vispy/visuals/isocurve.py +213 -0
  437. vispy/visuals/isoline.py +241 -0
  438. vispy/visuals/isosurface.py +113 -0
  439. vispy/visuals/line/__init__.py +6 -0
  440. vispy/visuals/line/arrow.py +289 -0
  441. vispy/visuals/line/dash_atlas.py +90 -0
  442. vispy/visuals/line/line.py +545 -0
  443. vispy/visuals/line_plot.py +135 -0
  444. vispy/visuals/linear_region.py +199 -0
  445. vispy/visuals/markers.py +810 -0
  446. vispy/visuals/mesh.py +373 -0
  447. vispy/visuals/mesh_normals.py +159 -0
  448. vispy/visuals/plane.py +54 -0
  449. vispy/visuals/polygon.py +145 -0
  450. vispy/visuals/rectangle.py +196 -0
  451. vispy/visuals/regular_polygon.py +56 -0
  452. vispy/visuals/scrolling_lines.py +197 -0
  453. vispy/visuals/shaders/__init__.py +17 -0
  454. vispy/visuals/shaders/compiler.py +206 -0
  455. vispy/visuals/shaders/expression.py +99 -0
  456. vispy/visuals/shaders/function.py +788 -0
  457. vispy/visuals/shaders/multiprogram.py +145 -0
  458. vispy/visuals/shaders/parsing.py +140 -0
  459. vispy/visuals/shaders/program.py +161 -0
  460. vispy/visuals/shaders/shader_object.py +162 -0
  461. vispy/visuals/shaders/tests/__init__.py +0 -0
  462. vispy/visuals/shaders/tests/test_function.py +486 -0
  463. vispy/visuals/shaders/tests/test_multiprogram.py +78 -0
  464. vispy/visuals/shaders/tests/test_parsing.py +57 -0
  465. vispy/visuals/shaders/variable.py +272 -0
  466. vispy/visuals/spectrogram.py +169 -0
  467. vispy/visuals/sphere.py +80 -0
  468. vispy/visuals/surface_plot.py +192 -0
  469. vispy/visuals/tests/__init__.py +0 -0
  470. vispy/visuals/tests/test_arrows.py +109 -0
  471. vispy/visuals/tests/test_axis.py +120 -0
  472. vispy/visuals/tests/test_collections.py +15 -0
  473. vispy/visuals/tests/test_colorbar.py +179 -0
  474. vispy/visuals/tests/test_colormap.py +97 -0
  475. vispy/visuals/tests/test_ellipse.py +122 -0
  476. vispy/visuals/tests/test_histogram.py +24 -0
  477. vispy/visuals/tests/test_image.py +390 -0
  478. vispy/visuals/tests/test_image_complex.py +36 -0
  479. vispy/visuals/tests/test_infinite_line.py +53 -0
  480. vispy/visuals/tests/test_instanced_mesh.py +50 -0
  481. vispy/visuals/tests/test_isosurface.py +22 -0
  482. vispy/visuals/tests/test_linear_region.py +152 -0
  483. vispy/visuals/tests/test_markers.py +54 -0
  484. vispy/visuals/tests/test_mesh.py +261 -0
  485. vispy/visuals/tests/test_mesh_normals.py +218 -0
  486. vispy/visuals/tests/test_polygon.py +112 -0
  487. vispy/visuals/tests/test_rectangle.py +163 -0
  488. vispy/visuals/tests/test_regular_polygon.py +111 -0
  489. vispy/visuals/tests/test_scalable_textures.py +180 -0
  490. vispy/visuals/tests/test_sdf.py +73 -0
  491. vispy/visuals/tests/test_spectrogram.py +42 -0
  492. vispy/visuals/tests/test_text.py +95 -0
  493. vispy/visuals/tests/test_volume.py +542 -0
  494. vispy/visuals/tests/test_windbarb.py +33 -0
  495. vispy/visuals/text/__init__.py +7 -0
  496. vispy/visuals/text/_sdf_cpu.cpython-311-darwin.so +0 -0
  497. vispy/visuals/text/_sdf_cpu.pyx +110 -0
  498. vispy/visuals/text/_sdf_gpu.py +316 -0
  499. vispy/visuals/text/text.py +675 -0
  500. vispy/visuals/transforms/__init__.py +34 -0
  501. vispy/visuals/transforms/_util.py +191 -0
  502. vispy/visuals/transforms/base_transform.py +233 -0
  503. vispy/visuals/transforms/chain.py +300 -0
  504. vispy/visuals/transforms/interactive.py +98 -0
  505. vispy/visuals/transforms/linear.py +564 -0
  506. vispy/visuals/transforms/nonlinear.py +398 -0
  507. vispy/visuals/transforms/tests/__init__.py +0 -0
  508. vispy/visuals/transforms/tests/test_transforms.py +243 -0
  509. vispy/visuals/transforms/transform_system.py +339 -0
  510. vispy/visuals/tube.py +173 -0
  511. vispy/visuals/visual.py +923 -0
  512. vispy/visuals/volume.py +1335 -0
  513. vispy/visuals/windbarb.py +291 -0
  514. vispy/visuals/xyz_axis.py +34 -0
  515. vispy-0.14.0.dist-info/LICENSE.txt +36 -0
  516. vispy-0.14.0.dist-info/METADATA +218 -0
  517. vispy-0.14.0.dist-info/RECORD +519 -0
  518. vispy-0.14.0.dist-info/WHEEL +5 -0
  519. vispy-0.14.0.dist-info/top_level.txt +1 -0
vispy/ext/cocoapy.py ADDED
@@ -0,0 +1,1542 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from ctypes import (cdll, util, Structure, cast, byref, POINTER, CFUNCTYPE,
4
+ c_int, c_long, c_ulong, c_ushort, c_wchar, c_uint32,
5
+ c_double, c_uint, c_float, c_void_p, c_char_p, c_bool,
6
+ c_buffer, c_ubyte, c_byte, c_int8, c_int16, c_int32,
7
+ c_int64, c_short, c_longlong, c_size_t, sizeof,
8
+ c_uint8, c_longdouble, c_char, c_ulonglong, py_object,
9
+ alignment, ArgumentError)
10
+
11
+ import platform
12
+ import struct
13
+ import sys
14
+
15
+ if sys.version_info[0] >= 3:
16
+ string_types = str,
17
+ else:
18
+ string_types = basestring, # noqa
19
+
20
+
21
+ # handle dlopen cache changes in macOS 11 (Big Sur)
22
+ # ref https://stackoverflow.com/questions/63475461/unable-to-import-opengl-gl-in-python-on-macos
23
+ try:
24
+ import OpenGL.GL # noqa
25
+ except ImportError:
26
+ # print('Drat, patching for Big Sur')
27
+ orig_util_find_library = util.find_library
28
+
29
+ def new_util_find_library(name):
30
+ res = orig_util_find_library(name)
31
+ if res:
32
+ return res
33
+ lut = {
34
+ 'objc': 'libobjc.dylib',
35
+ 'quartz': 'Quartz.framework/Quartz'
36
+ }
37
+ return lut.get(name, name+'.framework/'+name)
38
+ util.find_library = new_util_find_library
39
+
40
+
41
+ # Based on Pyglet code
42
+
43
+ ##############################################################################
44
+ # cocoatypes.py
45
+
46
+ __LP64__ = (8 * struct.calcsize("P") == 64)
47
+ __i386__ = (platform.machine() == 'i386')
48
+
49
+ PyObjectEncoding = b'{PyObject=@}'
50
+
51
+
52
+ def encoding_for_ctype(vartype):
53
+ typecodes = {c_char: b'c', c_int: b'i', c_short: b's', c_long: b'l',
54
+ c_longlong: b'q', c_ubyte: b'C', c_uint: b'I', c_ushort: b'S',
55
+ c_ulong: b'L', c_ulonglong: b'Q', c_float: b'f',
56
+ c_double: b'd', c_bool: b'B', c_char_p: b'*', c_void_p: b'@',
57
+ py_object: PyObjectEncoding}
58
+ return typecodes.get(vartype, b'?')
59
+
60
+ if __LP64__:
61
+ NSInteger = c_long
62
+ NSUInteger = c_ulong
63
+ CGFloat = c_double
64
+ NSPointEncoding = b'{CGPoint=dd}'
65
+ NSSizeEncoding = b'{CGSize=dd}'
66
+ NSRectEncoding = b'{CGRect={CGPoint=dd}{CGSize=dd}}'
67
+ NSRangeEncoding = b'{_NSRange=QQ}'
68
+ else:
69
+ NSInteger = c_int
70
+ NSUInteger = c_uint
71
+ CGFloat = c_float
72
+ NSPointEncoding = b'{_NSPoint=ff}'
73
+ NSSizeEncoding = b'{_NSSize=ff}'
74
+ NSRectEncoding = b'{_NSRect={_NSPoint=ff}{_NSSize=ff}}'
75
+ NSRangeEncoding = b'{_NSRange=II}'
76
+
77
+ NSIntegerEncoding = encoding_for_ctype(NSInteger)
78
+ NSUIntegerEncoding = encoding_for_ctype(NSUInteger)
79
+ CGFloatEncoding = encoding_for_ctype(CGFloat)
80
+
81
+ CGImageEncoding = b'{CGImage=}'
82
+ NSZoneEncoding = b'{_NSZone=}'
83
+
84
+
85
+ class NSPoint(Structure):
86
+ _fields_ = [("x", CGFloat), ("y", CGFloat)]
87
+ CGPoint = NSPoint
88
+
89
+
90
+ class NSSize(Structure):
91
+ _fields_ = [("width", CGFloat), ("height", CGFloat)]
92
+ CGSize = NSSize
93
+
94
+
95
+ class NSRect(Structure):
96
+ _fields_ = [("origin", NSPoint), ("size", NSSize)]
97
+ CGRect = NSRect
98
+
99
+
100
+ NSTimeInterval = c_double
101
+ CFIndex = c_long
102
+ UniChar = c_ushort
103
+ unichar = c_wchar
104
+ CGGlyph = c_ushort
105
+
106
+
107
+ class CFRange(Structure):
108
+ _fields_ = [("location", CFIndex), ("length", CFIndex)]
109
+
110
+
111
+ class NSRange(Structure):
112
+ _fields_ = [("location", NSUInteger), ("length", NSUInteger)]
113
+
114
+
115
+ CFTypeID = c_ulong
116
+ CFNumberType = c_uint32
117
+
118
+
119
+ ##############################################################################
120
+ # runtime.py
121
+
122
+ __LP64__ = (8*struct.calcsize("P") == 64)
123
+ __i386__ = (platform.machine() == 'i386')
124
+
125
+ if sizeof(c_void_p) == 4:
126
+ c_ptrdiff_t = c_int32
127
+ elif sizeof(c_void_p) == 8:
128
+ c_ptrdiff_t = c_int64
129
+
130
+ objc = cdll.LoadLibrary(util.find_library('objc'))
131
+
132
+ objc.class_addIvar.restype = c_bool
133
+ objc.class_addIvar.argtypes = [c_void_p, c_char_p, c_size_t, c_uint8, c_char_p]
134
+
135
+ objc.class_addMethod.restype = c_bool
136
+
137
+ objc.class_addProtocol.restype = c_bool
138
+ objc.class_addProtocol.argtypes = [c_void_p, c_void_p]
139
+
140
+ objc.class_conformsToProtocol.restype = c_bool
141
+ objc.class_conformsToProtocol.argtypes = [c_void_p, c_void_p]
142
+
143
+ objc.class_copyIvarList.restype = POINTER(c_void_p)
144
+ objc.class_copyIvarList.argtypes = [c_void_p, POINTER(c_uint)]
145
+
146
+ objc.class_copyMethodList.restype = POINTER(c_void_p)
147
+ objc.class_copyMethodList.argtypes = [c_void_p, POINTER(c_uint)]
148
+
149
+ objc.class_copyPropertyList.restype = POINTER(c_void_p)
150
+ objc.class_copyPropertyList.argtypes = [c_void_p, POINTER(c_uint)]
151
+
152
+ objc.class_copyProtocolList.restype = POINTER(c_void_p)
153
+ objc.class_copyProtocolList.argtypes = [c_void_p, POINTER(c_uint)]
154
+
155
+ objc.class_createInstance.restype = c_void_p
156
+ objc.class_createInstance.argtypes = [c_void_p, c_size_t]
157
+
158
+ objc.class_getClassMethod.restype = c_void_p
159
+ objc.class_getClassMethod.argtypes = [c_void_p, c_void_p]
160
+
161
+ objc.class_getClassVariable.restype = c_void_p
162
+ objc.class_getClassVariable.argtypes = [c_void_p, c_char_p]
163
+
164
+ objc.class_getInstanceMethod.restype = c_void_p
165
+ objc.class_getInstanceMethod.argtypes = [c_void_p, c_void_p]
166
+
167
+ objc.class_getInstanceSize.restype = c_size_t
168
+ objc.class_getInstanceSize.argtypes = [c_void_p]
169
+
170
+ objc.class_getInstanceVariable.restype = c_void_p
171
+ objc.class_getInstanceVariable.argtypes = [c_void_p, c_char_p]
172
+
173
+ objc.class_getIvarLayout.restype = c_char_p
174
+ objc.class_getIvarLayout.argtypes = [c_void_p]
175
+
176
+ objc.class_getMethodImplementation.restype = c_void_p
177
+ objc.class_getMethodImplementation.argtypes = [c_void_p, c_void_p]
178
+
179
+ if platform.machine() != "arm64":
180
+ objc.class_getMethodImplementation_stret.restype = c_void_p
181
+ objc.class_getMethodImplementation_stret.argtypes = [c_void_p, c_void_p]
182
+
183
+ objc.class_getName.restype = c_char_p
184
+ objc.class_getName.argtypes = [c_void_p]
185
+
186
+ objc.class_getProperty.restype = c_void_p
187
+ objc.class_getProperty.argtypes = [c_void_p, c_char_p]
188
+
189
+ objc.class_getSuperclass.restype = c_void_p
190
+ objc.class_getSuperclass.argtypes = [c_void_p]
191
+
192
+ objc.class_getVersion.restype = c_int
193
+ objc.class_getVersion.argtypes = [c_void_p]
194
+
195
+ objc.class_getWeakIvarLayout.restype = c_char_p
196
+ objc.class_getWeakIvarLayout.argtypes = [c_void_p]
197
+
198
+ objc.class_isMetaClass.restype = c_bool
199
+ objc.class_isMetaClass.argtypes = [c_void_p]
200
+
201
+ objc.class_replaceMethod.restype = c_void_p
202
+ objc.class_replaceMethod.argtypes = [c_void_p, c_void_p, c_void_p, c_char_p]
203
+
204
+ objc.class_respondsToSelector.restype = c_bool
205
+ objc.class_respondsToSelector.argtypes = [c_void_p, c_void_p]
206
+
207
+ objc.class_setIvarLayout.restype = None
208
+ objc.class_setIvarLayout.argtypes = [c_void_p, c_char_p]
209
+
210
+ objc.class_setSuperclass.restype = c_void_p
211
+ objc.class_setSuperclass.argtypes = [c_void_p, c_void_p]
212
+
213
+ objc.class_setVersion.restype = None
214
+ objc.class_setVersion.argtypes = [c_void_p, c_int]
215
+
216
+ objc.class_setWeakIvarLayout.restype = None
217
+ objc.class_setWeakIvarLayout.argtypes = [c_void_p, c_char_p]
218
+
219
+ objc.ivar_getName.restype = c_char_p
220
+ objc.ivar_getName.argtypes = [c_void_p]
221
+
222
+ objc.ivar_getOffset.restype = c_ptrdiff_t
223
+ objc.ivar_getOffset.argtypes = [c_void_p]
224
+
225
+ objc.ivar_getTypeEncoding.restype = c_char_p
226
+ objc.ivar_getTypeEncoding.argtypes = [c_void_p]
227
+
228
+ objc.method_copyArgumentType.restype = c_char_p
229
+ objc.method_copyArgumentType.argtypes = [c_void_p, c_uint]
230
+
231
+ objc.method_copyReturnType.restype = c_char_p
232
+ objc.method_copyReturnType.argtypes = [c_void_p]
233
+
234
+ objc.method_exchangeImplementations.restype = None
235
+ objc.method_exchangeImplementations.argtypes = [c_void_p, c_void_p]
236
+
237
+ objc.method_getArgumentType.restype = None
238
+ objc.method_getArgumentType.argtypes = [c_void_p, c_uint, c_char_p, c_size_t]
239
+
240
+ objc.method_getImplementation.restype = c_void_p
241
+ objc.method_getImplementation.argtypes = [c_void_p]
242
+
243
+ objc.method_getName.restype = c_void_p
244
+ objc.method_getName.argtypes = [c_void_p]
245
+
246
+ objc.method_getNumberOfArguments.restype = c_uint
247
+ objc.method_getNumberOfArguments.argtypes = [c_void_p]
248
+
249
+ objc.method_getReturnType.restype = None
250
+ objc.method_getReturnType.argtypes = [c_void_p, c_char_p, c_size_t]
251
+
252
+ objc.method_getTypeEncoding.restype = c_char_p
253
+ objc.method_getTypeEncoding.argtypes = [c_void_p]
254
+
255
+ objc.method_setImplementation.restype = c_void_p
256
+ objc.method_setImplementation.argtypes = [c_void_p, c_void_p]
257
+
258
+ objc.objc_allocateClassPair.restype = c_void_p
259
+ objc.objc_allocateClassPair.argtypes = [c_void_p, c_char_p, c_size_t]
260
+
261
+ objc.objc_copyProtocolList.restype = POINTER(c_void_p)
262
+ objc.objc_copyProtocolList.argtypes = [POINTER(c_int)]
263
+
264
+ objc.objc_getAssociatedObject.restype = c_void_p
265
+ objc.objc_getAssociatedObject.argtypes = [c_void_p, c_void_p]
266
+
267
+ objc.objc_getClass.restype = c_void_p
268
+ objc.objc_getClass.argtypes = [c_char_p]
269
+
270
+ objc.objc_getClassList.restype = c_int
271
+ objc.objc_getClassList.argtypes = [c_void_p, c_int]
272
+
273
+ objc.objc_getMetaClass.restype = c_void_p
274
+ objc.objc_getMetaClass.argtypes = [c_char_p]
275
+
276
+ objc.objc_getProtocol.restype = c_void_p
277
+ objc.objc_getProtocol.argtypes = [c_char_p]
278
+
279
+ if platform.machine() != "arm64":
280
+ objc.objc_msgSendSuper_stret.restype = None
281
+ objc.objc_msgSend_stret.restype = None
282
+
283
+ objc.objc_registerClassPair.restype = None
284
+ objc.objc_registerClassPair.argtypes = [c_void_p]
285
+
286
+ objc.objc_removeAssociatedObjects.restype = None
287
+ objc.objc_removeAssociatedObjects.argtypes = [c_void_p]
288
+
289
+ objc.objc_setAssociatedObject.restype = None
290
+ objc.objc_setAssociatedObject.argtypes = [c_void_p, c_void_p, c_void_p, c_int]
291
+
292
+ objc.object_copy.restype = c_void_p
293
+ objc.object_copy.argtypes = [c_void_p, c_size_t]
294
+
295
+ objc.object_dispose.restype = c_void_p
296
+ objc.object_dispose.argtypes = [c_void_p]
297
+
298
+ objc.object_getClass.restype = c_void_p
299
+ objc.object_getClass.argtypes = [c_void_p]
300
+
301
+ objc.object_getClassName.restype = c_char_p
302
+ objc.object_getClassName.argtypes = [c_void_p]
303
+
304
+ objc.object_getInstanceVariable.restype = c_void_p
305
+ objc.object_getInstanceVariable.argtypes = [c_void_p, c_char_p, c_void_p]
306
+
307
+ objc.object_getIvar.restype = c_void_p
308
+ objc.object_getIvar.argtypes = [c_void_p, c_void_p]
309
+
310
+ objc.object_setClass.restype = c_void_p
311
+ objc.object_setClass.argtypes = [c_void_p, c_void_p]
312
+
313
+ objc.object_setInstanceVariable.restype = c_void_p
314
+
315
+ objc.object_setIvar.restype = None
316
+ objc.object_setIvar.argtypes = [c_void_p, c_void_p, c_void_p]
317
+
318
+ objc.property_getAttributes.restype = c_char_p
319
+ objc.property_getAttributes.argtypes = [c_void_p]
320
+
321
+ objc.property_getName.restype = c_char_p
322
+ objc.property_getName.argtypes = [c_void_p]
323
+
324
+ objc.protocol_conformsToProtocol.restype = c_bool
325
+ objc.protocol_conformsToProtocol.argtypes = [c_void_p, c_void_p]
326
+
327
+
328
+ class OBJC_METHOD_DESCRIPTION(Structure):
329
+ _fields_ = [("name", c_void_p), ("types", c_char_p)]
330
+
331
+
332
+ objc.protocol_copyMethodDescriptionList.restype = \
333
+ POINTER(OBJC_METHOD_DESCRIPTION)
334
+ objc.protocol_copyMethodDescriptionList.argtypes = [c_void_p, c_bool,
335
+ c_bool, POINTER(c_uint)]
336
+
337
+ objc.protocol_copyPropertyList.restype = c_void_p
338
+ objc.protocol_copyPropertyList.argtypes = [c_void_p, POINTER(c_uint)]
339
+
340
+ objc.protocol_copyProtocolList = POINTER(c_void_p)
341
+ objc.protocol_copyProtocolList.argtypes = [c_void_p, POINTER(c_uint)]
342
+
343
+ objc.protocol_getMethodDescription.restype = OBJC_METHOD_DESCRIPTION
344
+ objc.protocol_getMethodDescription.argtypes = [c_void_p, c_void_p,
345
+ c_bool, c_bool]
346
+
347
+ objc.protocol_getName.restype = c_char_p
348
+ objc.protocol_getName.argtypes = [c_void_p]
349
+
350
+ objc.sel_getName.restype = c_char_p
351
+ objc.sel_getName.argtypes = [c_void_p]
352
+
353
+ objc.sel_isEqual.restype = c_bool
354
+ objc.sel_isEqual.argtypes = [c_void_p, c_void_p]
355
+
356
+ objc.sel_registerName.restype = c_void_p
357
+ objc.sel_registerName.argtypes = [c_char_p]
358
+
359
+
360
+ def ensure_bytes(x):
361
+ if isinstance(x, bytes):
362
+ return x
363
+ return x.encode('ascii')
364
+
365
+
366
+ def get_selector(name):
367
+ return c_void_p(objc.sel_registerName(ensure_bytes(name)))
368
+
369
+
370
+ def get_class(name):
371
+ return c_void_p(objc.objc_getClass(ensure_bytes(name)))
372
+
373
+
374
+ def get_object_class(obj):
375
+ return c_void_p(objc.object_getClass(obj))
376
+
377
+
378
+ def get_metaclass(name):
379
+ return c_void_p(objc.objc_getMetaClass(ensure_bytes(name)))
380
+
381
+
382
+ def get_superclass_of_object(obj):
383
+ cls = c_void_p(objc.object_getClass(obj))
384
+ return c_void_p(objc.class_getSuperclass(cls))
385
+
386
+
387
+ def x86_should_use_stret(restype):
388
+ if not isinstance(restype, type(Structure)):
389
+ return False
390
+ if not __LP64__ and sizeof(restype) <= 8:
391
+ return False
392
+ if __LP64__ and sizeof(restype) <= 16: # maybe? I don't know?
393
+ return False
394
+ return True
395
+
396
+
397
+ def should_use_fpret(restype):
398
+ if not __i386__:
399
+ return False
400
+ if __LP64__ and restype == c_longdouble:
401
+ return True
402
+ if not __LP64__ and restype in (c_float, c_double, c_longdouble):
403
+ return True
404
+ return False
405
+
406
+
407
+ def send_message(receiver, selName, *args, **kwargs):
408
+ if isinstance(receiver, string_types):
409
+ receiver = get_class(receiver)
410
+ selector = get_selector(selName)
411
+ restype = kwargs.get('restype', c_void_p)
412
+ argtypes = kwargs.get('argtypes', [])
413
+ if should_use_fpret(restype):
414
+ objc.objc_msgSend_fpret.restype = restype
415
+ objc.objc_msgSend_fpret.argtypes = [c_void_p, c_void_p] + argtypes
416
+ result = objc.objc_msgSend_fpret(receiver, selector, *args)
417
+ elif x86_should_use_stret(restype):
418
+ objc.objc_msgSend_stret.argtypes = [POINTER(restype), c_void_p,
419
+ c_void_p] + argtypes
420
+ result = restype()
421
+ objc.objc_msgSend_stret(byref(result), receiver, selector, *args)
422
+ else:
423
+ objc.objc_msgSend.restype = restype
424
+ objc.objc_msgSend.argtypes = [c_void_p, c_void_p] + argtypes
425
+ result = objc.objc_msgSend(receiver, selector, *args)
426
+ if restype == c_void_p:
427
+ result = c_void_p(result)
428
+ return result
429
+
430
+
431
+ class OBJC_SUPER(Structure):
432
+ _fields_ = [('receiver', c_void_p), ('class', c_void_p)]
433
+
434
+ OBJC_SUPER_PTR = POINTER(OBJC_SUPER)
435
+
436
+
437
+ def send_super(receiver, selName, *args, **kwargs):
438
+ if hasattr(receiver, '_as_parameter_'):
439
+ receiver = receiver._as_parameter_
440
+ superclass = get_superclass_of_object(receiver)
441
+ super_struct = OBJC_SUPER(receiver, superclass)
442
+ selector = get_selector(selName)
443
+ restype = kwargs.get('restype', c_void_p)
444
+ argtypes = kwargs.get('argtypes', None)
445
+ objc.objc_msgSendSuper.restype = restype
446
+ if argtypes:
447
+ objc.objc_msgSendSuper.argtypes = [OBJC_SUPER_PTR, c_void_p] + argtypes
448
+ else:
449
+ objc.objc_msgSendSuper.argtypes = None
450
+ result = objc.objc_msgSendSuper(byref(super_struct), selector, *args)
451
+ if restype == c_void_p:
452
+ result = c_void_p(result)
453
+ return result
454
+
455
+
456
+ cfunctype_table = {}
457
+
458
+
459
+ def parse_type_encoding(encoding):
460
+ type_encodings = []
461
+ brace_count = 0 # number of unclosed curly braces
462
+ bracket_count = 0 # number of unclosed square brackets
463
+ typecode = b''
464
+ for c in encoding:
465
+ if isinstance(c, int):
466
+ c = bytes([c])
467
+
468
+ if c == b'{':
469
+ if typecode and typecode[-1:] != b'^' and brace_count == 0 and \
470
+ bracket_count == 0:
471
+ type_encodings.append(typecode)
472
+ typecode = b''
473
+ typecode += c
474
+ brace_count += 1
475
+ elif c == b'}':
476
+ typecode += c
477
+ brace_count -= 1
478
+ assert(brace_count >= 0)
479
+ elif c == b'[':
480
+ if typecode and typecode[-1:] != b'^' and brace_count == 0 and \
481
+ bracket_count == 0:
482
+ type_encodings.append(typecode)
483
+ typecode = b''
484
+ typecode += c
485
+ bracket_count += 1
486
+ elif c == b']':
487
+ typecode += c
488
+ bracket_count -= 1
489
+ assert(bracket_count >= 0)
490
+ elif brace_count or bracket_count:
491
+ typecode += c
492
+ elif c in b'0123456789':
493
+ pass
494
+ elif c in b'rnNoORV':
495
+ pass
496
+ elif c in b'^cislqCISLQfdBv*@#:b?':
497
+ if typecode and typecode[-1:] == b'^':
498
+ typecode += c
499
+ else:
500
+ if typecode:
501
+ type_encodings.append(typecode)
502
+ typecode = c
503
+
504
+ if typecode:
505
+ type_encodings.append(typecode)
506
+
507
+ return type_encodings
508
+
509
+
510
+ def cfunctype_for_encoding(encoding):
511
+ if encoding in cfunctype_table:
512
+ return cfunctype_table[encoding]
513
+ typecodes = {b'c': c_char, b'i': c_int, b's': c_short, b'l': c_long,
514
+ b'q': c_longlong, b'C': c_ubyte, b'I': c_uint, b'S': c_ushort,
515
+ b'L': c_ulong, b'Q': c_ulonglong, b'f': c_float,
516
+ b'd': c_double, b'B': c_bool, b'v': None, b'*': c_char_p,
517
+ b'@': c_void_p, b'#': c_void_p, b':': c_void_p,
518
+ NSPointEncoding: NSPoint, NSSizeEncoding: NSSize,
519
+ NSRectEncoding: NSRect, NSRangeEncoding: NSRange,
520
+ PyObjectEncoding: py_object}
521
+ argtypes = []
522
+ for code in parse_type_encoding(encoding):
523
+ if code in typecodes:
524
+ argtypes.append(typecodes[code])
525
+ elif code[0:1] == b'^' and code[1:] in typecodes:
526
+ argtypes.append(POINTER(typecodes[code[1:]]))
527
+ else:
528
+ raise Exception('unknown type encoding: ' + code)
529
+
530
+ cfunctype = CFUNCTYPE(*argtypes)
531
+ cfunctype_table[encoding] = cfunctype
532
+ return cfunctype
533
+
534
+
535
+ def create_subclass(superclass, name):
536
+ if isinstance(superclass, string_types):
537
+ superclass = get_class(superclass)
538
+ return c_void_p(objc.objc_allocateClassPair(superclass,
539
+ ensure_bytes(name), 0))
540
+
541
+
542
+ def register_subclass(subclass):
543
+ objc.objc_registerClassPair(subclass)
544
+
545
+
546
+ def add_method(cls, selName, method, types):
547
+ type_encodings = parse_type_encoding(types)
548
+ assert(type_encodings[1] == b'@') # ensure id self typecode
549
+ assert(type_encodings[2] == b':') # ensure SEL cmd typecode
550
+ selector = get_selector(selName)
551
+ cfunctype = cfunctype_for_encoding(types)
552
+ imp = cfunctype(method)
553
+ objc.class_addMethod.argtypes = [c_void_p, c_void_p, cfunctype, c_char_p]
554
+ objc.class_addMethod(cls, selector, imp, types)
555
+ return imp
556
+
557
+
558
+ def add_ivar(cls, name, vartype):
559
+ return objc.class_addIvar(cls, ensure_bytes(name), sizeof(vartype),
560
+ alignment(vartype), encoding_for_ctype(vartype))
561
+
562
+
563
+ def set_instance_variable(obj, varname, value, vartype):
564
+ objc.object_setInstanceVariable.argtypes = [c_void_p, c_char_p, vartype]
565
+ objc.object_setInstanceVariable(obj, ensure_bytes(varname), value)
566
+
567
+
568
+ def get_instance_variable(obj, varname, vartype):
569
+ variable = vartype()
570
+ objc.object_getInstanceVariable(obj, ensure_bytes(varname),
571
+ byref(variable))
572
+ return variable.value
573
+
574
+
575
+ class ObjCMethod(object):
576
+ """This represents an unbound Objective-C method (really an IMP)."""
577
+
578
+ typecodes = {b'c': c_byte, b'i': c_int, b's': c_short, b'l': c_long,
579
+ b'q': c_longlong, b'C': c_ubyte, b'I': c_uint, b'S': c_ushort,
580
+ b'L': c_ulong, b'Q': c_ulonglong, b'f': c_float,
581
+ b'd': c_double, b'B': c_bool, b'v': None, b'Vv': None,
582
+ b'*': c_char_p, b'@': c_void_p, b'#': c_void_p,
583
+ b':': c_void_p, b'^v': c_void_p, b'?': c_void_p,
584
+ NSPointEncoding: NSPoint, NSSizeEncoding: NSSize,
585
+ NSRectEncoding: NSRect, NSRangeEncoding: NSRange,
586
+ PyObjectEncoding: py_object}
587
+ cfunctype_table = {}
588
+
589
+ def __init__(self, method):
590
+ self.selector = c_void_p(objc.method_getName(method))
591
+ self.name = objc.sel_getName(self.selector)
592
+ self.pyname = self.name.replace(b':', b'_')
593
+ self.encoding = objc.method_getTypeEncoding(method)
594
+ self.return_type = objc.method_copyReturnType(method)
595
+ self.nargs = objc.method_getNumberOfArguments(method)
596
+ self.imp = c_void_p(objc.method_getImplementation(method))
597
+ self.argument_types = []
598
+ for i in range(self.nargs):
599
+ buffer = c_buffer(512)
600
+ objc.method_getArgumentType(method, i, buffer, len(buffer))
601
+ self.argument_types.append(buffer.value)
602
+ try:
603
+ self.argtypes = [self.ctype_for_encoding(t)
604
+ for t in self.argument_types]
605
+ except ValueError:
606
+ self.argtypes = None
607
+ try:
608
+ if self.return_type == b'@':
609
+ self.restype = ObjCInstance
610
+ elif self.return_type == b'#':
611
+ self.restype = ObjCClass
612
+ else:
613
+ self.restype = self.ctype_for_encoding(self.return_type)
614
+ except ValueError:
615
+ self.restype = None
616
+ self.func = None
617
+
618
+ def ctype_for_encoding(self, encoding):
619
+ """Return ctypes type for an encoded Objective-C type."""
620
+ if encoding in self.typecodes:
621
+ return self.typecodes[encoding]
622
+ elif encoding[0:1] == b'^' and encoding[1:] in self.typecodes:
623
+ return POINTER(self.typecodes[encoding[1:]])
624
+ elif encoding[0:1] == b'^' and encoding[1:] in [CGImageEncoding,
625
+ NSZoneEncoding]:
626
+ return c_void_p
627
+ elif encoding[0:1] == b'r' and encoding[1:] in self.typecodes:
628
+ return self.typecodes[encoding[1:]]
629
+ elif encoding[0:2] == b'r^' and encoding[2:] in self.typecodes:
630
+ return POINTER(self.typecodes[encoding[2:]])
631
+ else:
632
+ raise ValueError('unknown encoding for %s: %s'
633
+ % (self.name, encoding))
634
+
635
+ def get_prototype(self):
636
+ if self.restype == ObjCInstance or self.restype == ObjCClass:
637
+ self.prototype = CFUNCTYPE(c_void_p, *self.argtypes)
638
+ else:
639
+ self.prototype = CFUNCTYPE(self.restype, *self.argtypes)
640
+ return self.prototype
641
+
642
+ def __repr__(self):
643
+ return "<ObjCMethod: %s %s>" % (self.name, self.encoding)
644
+
645
+ def get_callable(self):
646
+ if not self.func:
647
+ prototype = self.get_prototype()
648
+ self.func = cast(self.imp, prototype)
649
+ if self.restype == ObjCInstance or self.restype == ObjCClass:
650
+ self.func.restype = c_void_p
651
+ else:
652
+ self.func.restype = self.restype
653
+ self.func.argtypes = self.argtypes
654
+ return self.func
655
+
656
+ def __call__(self, objc_id, *args):
657
+ f = self.get_callable()
658
+ try:
659
+ result = f(objc_id, self.selector, *args)
660
+ if self.restype == ObjCInstance:
661
+ result = ObjCInstance(result)
662
+ elif self.restype == ObjCClass:
663
+ result = ObjCClass(result)
664
+ return result
665
+ except ArgumentError as error:
666
+ error.args += ('selector = ' + self.name,
667
+ 'argtypes =' + str(self.argtypes),
668
+ 'encoding = ' + self.encoding)
669
+ raise
670
+
671
+
672
+ class ObjCBoundMethod(object):
673
+ def __init__(self, method, objc_id):
674
+ self.method = method
675
+ self.objc_id = objc_id
676
+
677
+ def __repr__(self):
678
+ return '<ObjCBoundMethod %s (%s)>' % (self.method.name, self.objc_id)
679
+
680
+ def __call__(self, *args):
681
+ return self.method(self.objc_id, *args)
682
+
683
+
684
+ class ObjCClass(object):
685
+ _registered_classes = {}
686
+
687
+ def __new__(cls, class_name_or_ptr):
688
+ if isinstance(class_name_or_ptr, string_types):
689
+ name = class_name_or_ptr
690
+ ptr = get_class(name)
691
+ else:
692
+ ptr = class_name_or_ptr
693
+ if not isinstance(ptr, c_void_p):
694
+ ptr = c_void_p(ptr)
695
+ name = objc.class_getName(ptr)
696
+
697
+ if name in cls._registered_classes:
698
+ return cls._registered_classes[name]
699
+
700
+ objc_class = super(ObjCClass, cls).__new__(cls)
701
+ objc_class.ptr = ptr
702
+ objc_class.name = name
703
+ objc_class.instance_methods = {} # mapping of name -> instance method
704
+ objc_class.class_methods = {} # mapping of name -> class method
705
+ objc_class._as_parameter_ = ptr # for ctypes argument passing
706
+
707
+ cls._registered_classes[name] = objc_class
708
+ objc_class.cache_instance_methods()
709
+ objc_class.cache_class_methods()
710
+ return objc_class
711
+
712
+ def __repr__(self):
713
+ return "<ObjCClass: %s at %s>" % (self.name, str(self.ptr.value))
714
+
715
+ def cache_instance_methods(self):
716
+ count = c_uint()
717
+ method_array = objc.class_copyMethodList(self.ptr, byref(count))
718
+ for i in range(count.value):
719
+ method = c_void_p(method_array[i])
720
+ objc_method = ObjCMethod(method)
721
+ self.instance_methods[objc_method.pyname] = objc_method
722
+
723
+ def cache_class_methods(self):
724
+ count = c_uint()
725
+ args = [objc.object_getClass(self.ptr), byref(count)]
726
+ method_array = objc.class_copyMethodList(*args)
727
+ for i in range(count.value):
728
+ method = c_void_p(method_array[i])
729
+ objc_method = ObjCMethod(method)
730
+ self.class_methods[objc_method.pyname] = objc_method
731
+
732
+ def get_instance_method(self, name):
733
+ if name in self.instance_methods:
734
+ return self.instance_methods[name]
735
+ else:
736
+ selector = get_selector(name.replace(b'_', b':'))
737
+ method = c_void_p(objc.class_getInstanceMethod(self.ptr, selector))
738
+ if method.value:
739
+ objc_method = ObjCMethod(method)
740
+ self.instance_methods[name] = objc_method
741
+ return objc_method
742
+ return None
743
+
744
+ def get_class_method(self, name):
745
+ if name in self.class_methods:
746
+ return self.class_methods[name]
747
+ else:
748
+ selector = get_selector(name.replace(b'_', b':'))
749
+ method = c_void_p(objc.class_getClassMethod(self.ptr, selector))
750
+ if method.value:
751
+ objc_method = ObjCMethod(method)
752
+ self.class_methods[name] = objc_method
753
+ return objc_method
754
+ return None
755
+
756
+ def __getattr__(self, name):
757
+ name = ensure_bytes(name)
758
+ method = self.get_class_method(name)
759
+ if method:
760
+ return ObjCBoundMethod(method, self.ptr)
761
+ method = self.get_instance_method(name)
762
+ if method:
763
+ return method
764
+ raise AttributeError('ObjCClass %s has no attribute %s'
765
+ % (self.name, name))
766
+
767
+
768
+ class ObjCInstance(object):
769
+ _cached_objects = {}
770
+
771
+ def __new__(cls, object_ptr):
772
+ if not isinstance(object_ptr, c_void_p):
773
+ object_ptr = c_void_p(object_ptr)
774
+ if not object_ptr.value:
775
+ return None
776
+ if object_ptr.value in cls._cached_objects:
777
+ return cls._cached_objects[object_ptr.value]
778
+
779
+ objc_instance = super(ObjCInstance, cls).__new__(cls)
780
+ objc_instance.ptr = object_ptr
781
+ objc_instance._as_parameter_ = object_ptr
782
+ class_ptr = c_void_p(objc.object_getClass(object_ptr))
783
+ objc_instance.objc_class = ObjCClass(class_ptr)
784
+
785
+ cls._cached_objects[object_ptr.value] = objc_instance
786
+ observer = send_message(send_message('DeallocationObserver', 'alloc'),
787
+ 'initWithObject:', objc_instance)
788
+ objc.objc_setAssociatedObject(objc_instance, observer, observer, 0x301)
789
+ send_message(observer, 'release')
790
+ return objc_instance
791
+
792
+ def __repr__(self):
793
+ if self.objc_class.name == b'NSCFString':
794
+ from .cocoalibs import cfstring_to_string
795
+ string = cfstring_to_string(self)
796
+ return ("<ObjCInstance %#x: %s (%s) at %s>"
797
+ % (id(self), self.objc_class.name, string,
798
+ str(self.ptr.value)))
799
+ return ("<ObjCInstance %#x: %s at %s>"
800
+ % (id(self), self.objc_class.name, str(self.ptr.value)))
801
+
802
+ def __getattr__(self, name):
803
+ name = ensure_bytes(name)
804
+ method = self.objc_class.get_instance_method(name)
805
+ if method:
806
+ return ObjCBoundMethod(method, self)
807
+ method = self.objc_class.get_class_method(name)
808
+ if method:
809
+ return ObjCBoundMethod(method, self.objc_class.ptr)
810
+ keys = list(self.objc_class.instance_methods.keys())
811
+ raise AttributeError('ObjCInstance %s has no attribute %s, only:\n%s'
812
+ % (self.objc_class.name, name, keys))
813
+
814
+
815
+ def convert_method_arguments(encoding, args):
816
+ new_args = []
817
+ arg_encodings = parse_type_encoding(encoding)[3:]
818
+ for e, a in zip(arg_encodings, args):
819
+ if e == b'@':
820
+ new_args.append(ObjCInstance(a))
821
+ elif e == b'#':
822
+ new_args.append(ObjCClass(a))
823
+ else:
824
+ new_args.append(a)
825
+ return new_args
826
+
827
+
828
+ class ObjCSubclass(object):
829
+
830
+ def __init__(self, superclass, name, register=True):
831
+ self._imp_table = {}
832
+ self.name = name
833
+ self.objc_cls = create_subclass(superclass, name)
834
+ self._as_parameter_ = self.objc_cls
835
+ if register:
836
+ self.register()
837
+
838
+ def register(self):
839
+ objc.objc_registerClassPair(self.objc_cls)
840
+ self.objc_metaclass = get_metaclass(self.name)
841
+
842
+ def add_ivar(self, varname, vartype):
843
+ return add_ivar(self.objc_cls, varname, vartype)
844
+
845
+ def add_method(self, method, name, encoding):
846
+ imp = add_method(self.objc_cls, name, method, encoding)
847
+ self._imp_table[name] = imp
848
+
849
+ def add_class_method(self, method, name, encoding):
850
+ imp = add_method(self.objc_metaclass, name, method, encoding)
851
+ self._imp_table[name] = imp
852
+
853
+ def rawmethod(self, encoding):
854
+ encoding = ensure_bytes(encoding)
855
+ typecodes = parse_type_encoding(encoding)
856
+ typecodes.insert(1, b'@:')
857
+ encoding = b''.join(typecodes)
858
+
859
+ def decorator(f):
860
+ name = f.__name__.replace('_', ':')
861
+ self.add_method(f, name, encoding)
862
+ return f
863
+ return decorator
864
+
865
+ def method(self, encoding):
866
+ encoding = ensure_bytes(encoding)
867
+ typecodes = parse_type_encoding(encoding)
868
+ typecodes.insert(1, b'@:')
869
+ encoding = b''.join(typecodes)
870
+
871
+ def decorator(f):
872
+ def objc_method(objc_self, objc_cmd, *args):
873
+ py_self = ObjCInstance(objc_self)
874
+ py_self.objc_cmd = objc_cmd
875
+ args = convert_method_arguments(encoding, args)
876
+ result = f(py_self, *args)
877
+ if isinstance(result, ObjCClass):
878
+ result = result.ptr.value
879
+ elif isinstance(result, ObjCInstance):
880
+ result = result.ptr.value
881
+ return result
882
+ name = f.__name__.replace('_', ':')
883
+ self.add_method(objc_method, name, encoding)
884
+ return objc_method
885
+ return decorator
886
+
887
+ def classmethod(self, encoding):
888
+ """Function decorator for class methods."""
889
+ # Add encodings for hidden self and cmd arguments.
890
+ encoding = ensure_bytes(encoding)
891
+ typecodes = parse_type_encoding(encoding)
892
+ typecodes.insert(1, b'@:')
893
+ encoding = b''.join(typecodes)
894
+
895
+ def decorator(f):
896
+ def objc_class_method(objc_cls, objc_cmd, *args):
897
+ py_cls = ObjCClass(objc_cls)
898
+ py_cls.objc_cmd = objc_cmd
899
+ args = convert_method_arguments(encoding, args)
900
+ result = f(py_cls, *args)
901
+ if isinstance(result, ObjCClass):
902
+ result = result.ptr.value
903
+ elif isinstance(result, ObjCInstance):
904
+ result = result.ptr.value
905
+ return result
906
+ name = f.__name__.replace('_', ':')
907
+ self.add_class_method(objc_class_method, name, encoding)
908
+ return objc_class_method
909
+ return decorator
910
+
911
+
912
+ # XXX This causes segfaults in all backends (yikes!), and makes it so that
913
+ # pyglet can't even be loaded. We'll just have to live with leaks for now,
914
+ # which is probably alright since we only use the
915
+ # NSFontManager.sharedFontManager class currently.
916
+
917
+ # class DeallocationObserver_Implementation(object):
918
+ # DeallocationObserver = ObjCSubclass('NSObject', 'DeallocationObserver',
919
+ # register=False)
920
+ # DeallocationObserver.add_ivar('observed_object', c_void_p)
921
+ # DeallocationObserver.register()
922
+ #
923
+ # @DeallocationObserver.rawmethod('@@')
924
+ # def initWithObject_(self, cmd, anObject):
925
+ # self = send_super(self, 'init')
926
+ # self = self.value
927
+ # set_instance_variable(self, 'observed_object', anObject, c_void_p)
928
+ # return self
929
+ #
930
+ # @DeallocationObserver.rawmethod('v')
931
+ # def dealloc(self, cmd):
932
+ # anObject = get_instance_variable(self, 'observed_object', c_void_p)
933
+ # ObjCInstance._cached_objects.pop(anObject, None)
934
+ # send_super(self, 'dealloc')
935
+ #
936
+ # @DeallocationObserver.rawmethod('v')
937
+ # def finalize(self, cmd):
938
+ # anObject = get_instance_variable(self, 'observed_object', c_void_p)
939
+ # ObjCInstance._cached_objects.pop(anObject, None)
940
+ # send_super(self, 'finalize')
941
+
942
+
943
+ ##############################################################################
944
+ # cocoalibs.py
945
+
946
+ cf = cdll.LoadLibrary(util.find_library('CoreFoundation'))
947
+
948
+ kCFStringEncodingUTF8 = 0x08000100
949
+
950
+ CFAllocatorRef = c_void_p
951
+ CFStringEncoding = c_uint32
952
+
953
+ cf.CFStringCreateWithCString.restype = c_void_p
954
+ cf.CFStringCreateWithCString.argtypes = [CFAllocatorRef, c_void_p,
955
+ CFStringEncoding]
956
+
957
+ cf.CFRelease.restype = c_void_p
958
+ cf.CFRelease.argtypes = [c_void_p]
959
+
960
+ cf.CFStringGetLength.restype = CFIndex
961
+ cf.CFStringGetLength.argtypes = [c_void_p]
962
+
963
+ cf.CFStringGetMaximumSizeForEncoding.restype = CFIndex
964
+ cf.CFStringGetMaximumSizeForEncoding.argtypes = [CFIndex, CFStringEncoding]
965
+
966
+ cf.CFStringGetCString.restype = c_bool
967
+ cf.CFStringGetCString.argtypes = [c_void_p, c_char_p, CFIndex,
968
+ CFStringEncoding]
969
+
970
+ cf.CFStringGetTypeID.restype = CFTypeID
971
+ cf.CFStringGetTypeID.argtypes = []
972
+
973
+ cf.CFAttributedStringCreate.restype = c_void_p
974
+ cf.CFAttributedStringCreate.argtypes = [CFAllocatorRef, c_void_p, c_void_p]
975
+
976
+ cf.CFURLCreateWithFileSystemPath.restype = c_void_p
977
+ cf.CFURLCreateWithFileSystemPath.argtypes = [CFAllocatorRef, c_void_p,
978
+ CFIndex, c_bool]
979
+
980
+
981
+ def CFSTR(string):
982
+ args = [None, string.encode('utf8'), kCFStringEncodingUTF8]
983
+ return ObjCInstance(c_void_p(cf.CFStringCreateWithCString(*args)))
984
+
985
+
986
+ def get_NSString(string):
987
+ """Autoreleased version of CFSTR"""
988
+ return CFSTR(string).autorelease()
989
+
990
+
991
+ def cfstring_to_string(cfstring):
992
+ length = cf.CFStringGetLength(cfstring)
993
+ size = cf.CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8)
994
+ buffer = c_buffer(size + 1)
995
+ result = cf.CFStringGetCString(cfstring, buffer, len(buffer),
996
+ kCFStringEncodingUTF8)
997
+ if result:
998
+ return buffer.value.decode('utf8')
999
+
1000
+
1001
+ cf.CFDataCreate.restype = c_void_p
1002
+ cf.CFDataCreate.argtypes = [c_void_p, c_void_p, CFIndex]
1003
+
1004
+ cf.CFDataGetBytes.restype = None
1005
+ cf.CFDataGetBytes.argtypes = [c_void_p, CFRange, c_void_p]
1006
+
1007
+ cf.CFDataGetLength.restype = CFIndex
1008
+ cf.CFDataGetLength.argtypes = [c_void_p]
1009
+
1010
+ cf.CFDictionaryGetValue.restype = c_void_p
1011
+ cf.CFDictionaryGetValue.argtypes = [c_void_p, c_void_p]
1012
+
1013
+ cf.CFDictionaryAddValue.restype = None
1014
+ cf.CFDictionaryAddValue.argtypes = [c_void_p, c_void_p, c_void_p]
1015
+
1016
+ cf.CFDictionaryCreateMutable.restype = c_void_p
1017
+ cf.CFDictionaryCreateMutable.argtypes = [CFAllocatorRef, CFIndex,
1018
+ c_void_p, c_void_p]
1019
+
1020
+ cf.CFNumberCreate.restype = c_void_p
1021
+ cf.CFNumberCreate.argtypes = [CFAllocatorRef, CFNumberType, c_void_p]
1022
+
1023
+ cf.CFNumberGetType.restype = CFNumberType
1024
+ cf.CFNumberGetType.argtypes = [c_void_p]
1025
+
1026
+ cf.CFNumberGetValue.restype = c_ubyte
1027
+ cf.CFNumberGetValue.argtypes = [c_void_p, CFNumberType, c_void_p]
1028
+
1029
+ cf.CFNumberGetTypeID.restype = CFTypeID
1030
+ cf.CFNumberGetTypeID.argtypes = []
1031
+
1032
+ cf.CFGetTypeID.restype = CFTypeID
1033
+ cf.CFGetTypeID.argtypes = [c_void_p]
1034
+
1035
+ # CFNumber.h
1036
+ kCFNumberSInt8Type = 1
1037
+ kCFNumberSInt16Type = 2
1038
+ kCFNumberSInt32Type = 3
1039
+ kCFNumberSInt64Type = 4
1040
+ kCFNumberFloat32Type = 5
1041
+ kCFNumberFloat64Type = 6
1042
+ kCFNumberCharType = 7
1043
+ kCFNumberShortType = 8
1044
+ kCFNumberIntType = 9
1045
+ kCFNumberLongType = 10
1046
+ kCFNumberLongLongType = 11
1047
+ kCFNumberFloatType = 12
1048
+ kCFNumberDoubleType = 13
1049
+ kCFNumberCFIndexType = 14
1050
+ kCFNumberNSIntegerType = 15
1051
+ kCFNumberCGFloatType = 16
1052
+ kCFNumberMaxType = 16
1053
+
1054
+
1055
+ def cfnumber_to_number(cfnumber):
1056
+ """Convert CFNumber to python int or float."""
1057
+ numeric_type = cf.CFNumberGetType(cfnumber)
1058
+ cfnum_to_ctype = {kCFNumberSInt8Type: c_int8, kCFNumberSInt16Type: c_int16,
1059
+ kCFNumberSInt32Type: c_int32,
1060
+ kCFNumberSInt64Type: c_int64,
1061
+ kCFNumberFloat32Type: c_float,
1062
+ kCFNumberFloat64Type: c_double,
1063
+ kCFNumberCharType: c_byte, kCFNumberShortType: c_short,
1064
+ kCFNumberIntType: c_int, kCFNumberLongType: c_long,
1065
+ kCFNumberLongLongType: c_longlong,
1066
+ kCFNumberFloatType: c_float,
1067
+ kCFNumberDoubleType: c_double,
1068
+ kCFNumberCFIndexType: CFIndex,
1069
+ kCFNumberCGFloatType: CGFloat}
1070
+
1071
+ if numeric_type in cfnum_to_ctype:
1072
+ t = cfnum_to_ctype[numeric_type]
1073
+ result = t()
1074
+ if cf.CFNumberGetValue(cfnumber, numeric_type, byref(result)):
1075
+ return result.value
1076
+ else:
1077
+ raise Exception(
1078
+ 'cfnumber_to_number: unhandled CFNumber type %d' % numeric_type)
1079
+
1080
+ # Dictionary of cftypes matched to the method converting them to python values.
1081
+ known_cftypes = {cf.CFStringGetTypeID(): cfstring_to_string,
1082
+ cf.CFNumberGetTypeID(): cfnumber_to_number}
1083
+
1084
+
1085
+ def cftype_to_value(cftype):
1086
+ """Convert a CFType into an equivalent python type.
1087
+ The convertible CFTypes are taken from the known_cftypes
1088
+ dictionary, which may be added to if another library implements
1089
+ its own conversion methods.
1090
+ """
1091
+ if not cftype:
1092
+ return None
1093
+ typeID = cf.CFGetTypeID(cftype)
1094
+ if typeID in known_cftypes:
1095
+ convert_function = known_cftypes[typeID]
1096
+ return convert_function(cftype)
1097
+ else:
1098
+ return cftype
1099
+
1100
+ cf.CFSetGetCount.restype = CFIndex
1101
+ cf.CFSetGetCount.argtypes = [c_void_p]
1102
+
1103
+ cf.CFSetGetValues.restype = None
1104
+ # PyPy 1.7 is fine with 2nd arg as POINTER(c_void_p),
1105
+ # but CPython ctypes 1.1.0 complains, so just use c_void_p.
1106
+ cf.CFSetGetValues.argtypes = [c_void_p, c_void_p]
1107
+
1108
+
1109
+ def cfset_to_set(cfset):
1110
+ """Convert CFSet to python set."""
1111
+ count = cf.CFSetGetCount(cfset)
1112
+ buffer = (c_void_p * count)()
1113
+ cf.CFSetGetValues(cfset, byref(buffer))
1114
+ return set([cftype_to_value(c_void_p(buffer[i])) for i in range(count)])
1115
+
1116
+ cf.CFArrayGetCount.restype = CFIndex
1117
+ cf.CFArrayGetCount.argtypes = [c_void_p]
1118
+
1119
+ cf.CFArrayGetValueAtIndex.restype = c_void_p
1120
+ cf.CFArrayGetValueAtIndex.argtypes = [c_void_p, CFIndex]
1121
+
1122
+
1123
+ def cfarray_to_list(cfarray):
1124
+ """Convert CFArray to python list."""
1125
+ count = cf.CFArrayGetCount(cfarray)
1126
+ return [cftype_to_value(c_void_p(cf.CFArrayGetValueAtIndex(cfarray, i)))
1127
+ for i in range(count)]
1128
+
1129
+
1130
+ kCFRunLoopDefaultMode = c_void_p.in_dll(cf, 'kCFRunLoopDefaultMode')
1131
+
1132
+ cf.CFRunLoopGetCurrent.restype = c_void_p
1133
+ cf.CFRunLoopGetCurrent.argtypes = []
1134
+
1135
+ cf.CFRunLoopGetMain.restype = c_void_p
1136
+ cf.CFRunLoopGetMain.argtypes = []
1137
+
1138
+ cf.CFShow.restype = None
1139
+ cf.CFShow.argtypes = [c_void_p]
1140
+
1141
+ ######################################################################
1142
+
1143
+ # APPLICATION KIT
1144
+
1145
+ # Even though we don't use this directly, it must be loaded so that
1146
+ # we can find the NSApplication, NSWindow, and NSView classes.
1147
+ appkit = cdll.LoadLibrary(util.find_library('AppKit'))
1148
+
1149
+ NSDefaultRunLoopMode = c_void_p.in_dll(appkit, 'NSDefaultRunLoopMode')
1150
+ NSEventTrackingRunLoopMode = c_void_p.in_dll(
1151
+ appkit, 'NSEventTrackingRunLoopMode')
1152
+ NSApplicationDidHideNotification = c_void_p.in_dll(
1153
+ appkit, 'NSApplicationDidHideNotification')
1154
+ NSApplicationDidUnhideNotification = c_void_p.in_dll(
1155
+ appkit, 'NSApplicationDidUnhideNotification')
1156
+
1157
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSEvent.h
1158
+ # NSAnyEventMask = 0xFFFFFFFFL # NSUIntegerMax
1159
+ # Commented out b/c not Py3k compatible
1160
+
1161
+ NSKeyDown = 10
1162
+ NSKeyUp = 11
1163
+ NSFlagsChanged = 12
1164
+ NSApplicationDefined = 15
1165
+
1166
+ NSAlphaShiftKeyMask = 1 << 16
1167
+ NSShiftKeyMask = 1 << 17
1168
+ NSControlKeyMask = 1 << 18
1169
+ NSAlternateKeyMask = 1 << 19
1170
+ NSCommandKeyMask = 1 << 20
1171
+ NSNumericPadKeyMask = 1 << 21
1172
+ NSHelpKeyMask = 1 << 22
1173
+ NSFunctionKeyMask = 1 << 23
1174
+
1175
+ NSInsertFunctionKey = 0xF727
1176
+ NSDeleteFunctionKey = 0xF728
1177
+ NSHomeFunctionKey = 0xF729
1178
+ NSBeginFunctionKey = 0xF72A
1179
+ NSEndFunctionKey = 0xF72B
1180
+ NSPageUpFunctionKey = 0xF72C
1181
+ NSPageDownFunctionKey = 0xF72D
1182
+
1183
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h
1184
+ NSBorderlessWindowMask = 0
1185
+ NSTitledWindowMask = 1 << 0
1186
+ NSClosableWindowMask = 1 << 1
1187
+ NSMiniaturizableWindowMask = 1 << 2
1188
+ NSResizableWindowMask = 1 << 3
1189
+
1190
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSPanel.h
1191
+ NSUtilityWindowMask = 1 << 4
1192
+
1193
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSGraphics.h
1194
+ NSBackingStoreRetained = 0
1195
+ NSBackingStoreNonretained = 1
1196
+ NSBackingStoreBuffered = 2
1197
+
1198
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSTrackingArea.h
1199
+ NSTrackingMouseEnteredAndExited = 0x01
1200
+ NSTrackingMouseMoved = 0x02
1201
+ NSTrackingCursorUpdate = 0x04
1202
+ NSTrackingActiveInActiveApp = 0x40
1203
+
1204
+ # /System/Library/Frameworks/AppKit.framework/Headers/NSOpenGL.h
1205
+ NSOpenGLPFAAllRenderers = 1 # choose from all available renderers
1206
+ NSOpenGLPFADoubleBuffer = 5 # choose a double buffered pixel format
1207
+ NSOpenGLPFAStereo = 6 # stereo buffering supported
1208
+ NSOpenGLPFAAuxBuffers = 7 # number of aux buffers
1209
+ NSOpenGLPFAColorSize = 8 # number of color buffer bits
1210
+ NSOpenGLPFAAlphaSize = 11 # number of alpha component bits
1211
+ NSOpenGLPFADepthSize = 12 # number of depth buffer bits
1212
+ NSOpenGLPFAStencilSize = 13 # number of stencil buffer bits
1213
+ NSOpenGLPFAAccumSize = 14 # number of accum buffer bits
1214
+ NSOpenGLPFAMinimumPolicy = 51 # never choose smaller buffers than requested
1215
+ NSOpenGLPFAMaximumPolicy = 52 # choose largest buffers of type requested
1216
+ NSOpenGLPFAOffScreen = 53 # choose an off-screen capable renderer
1217
+ NSOpenGLPFAFullScreen = 54 # choose a full-screen capable renderer
1218
+ NSOpenGLPFASampleBuffers = 55 # number of multi sample buffers
1219
+ NSOpenGLPFASamples = 56 # number of samples per multi sample buffer
1220
+ NSOpenGLPFAAuxDepthStencil = 57 # each aux buffer has its own depth stencil
1221
+ NSOpenGLPFAColorFloat = 58 # color buffers store floating point pixels
1222
+ NSOpenGLPFAMultisample = 59 # choose multisampling
1223
+ NSOpenGLPFASupersample = 60 # choose supersampling
1224
+ NSOpenGLPFASampleAlpha = 61 # request alpha filtering
1225
+ NSOpenGLPFARendererID = 70 # request renderer by ID
1226
+ NSOpenGLPFASingleRenderer = 71 # choose a single renderer for all screens
1227
+ NSOpenGLPFANoRecovery = 72 # disable all failure recovery systems
1228
+ NSOpenGLPFAAccelerated = 73 # choose a hardware accelerated renderer
1229
+ NSOpenGLPFAClosestPolicy = 74 # choose the closest color buffer to request
1230
+ NSOpenGLPFARobust = 75 # renderer does not need failure recovery
1231
+ NSOpenGLPFABackingStore = 76 # back buffer contents are valid after swap
1232
+ NSOpenGLPFAMPSafe = 78 # renderer is multi-processor safe
1233
+ NSOpenGLPFAWindow = 80 # can be used to render to an onscreen window
1234
+ NSOpenGLPFAMultiScreen = 81 # single window can span multiple screens
1235
+ NSOpenGLPFACompliant = 83 # renderer is opengl compliant
1236
+ NSOpenGLPFAScreenMask = 84 # bit mask of supported physical screens
1237
+ NSOpenGLPFAPixelBuffer = 90 # can be used to render to a pbuffer
1238
+ # can be used to render offline to a pbuffer
1239
+ NSOpenGLPFARemotePixelBuffer = 91
1240
+ NSOpenGLPFAAllowOfflineRenderers = 96 # allow use of offline renderers
1241
+ # choose a hardware accelerated compute device
1242
+ NSOpenGLPFAAcceleratedCompute = 97
1243
+ # number of virtual screens in this format
1244
+ NSOpenGLPFAVirtualScreenCount = 128
1245
+
1246
+ NSOpenGLCPSwapInterval = 222
1247
+
1248
+
1249
+ # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/...
1250
+ # CoreGraphics.framework/Headers/CGImage.h
1251
+ kCGImageAlphaNone = 0
1252
+ kCGImageAlphaPremultipliedLast = 1
1253
+ kCGImageAlphaPremultipliedFirst = 2
1254
+ kCGImageAlphaLast = 3
1255
+ kCGImageAlphaFirst = 4
1256
+ kCGImageAlphaNoneSkipLast = 5
1257
+ kCGImageAlphaNoneSkipFirst = 6
1258
+ kCGImageAlphaOnly = 7
1259
+
1260
+ kCGImageAlphaPremultipliedLast = 1
1261
+
1262
+ kCGBitmapAlphaInfoMask = 0x1F
1263
+ kCGBitmapFloatComponents = 1 << 8
1264
+
1265
+ kCGBitmapByteOrderMask = 0x7000
1266
+ kCGBitmapByteOrderDefault = 0 << 12
1267
+ kCGBitmapByteOrder16Little = 1 << 12
1268
+ kCGBitmapByteOrder32Little = 2 << 12
1269
+ kCGBitmapByteOrder16Big = 3 << 12
1270
+ kCGBitmapByteOrder32Big = 4 << 12
1271
+
1272
+ # NSApplication.h
1273
+ NSApplicationPresentationDefault = 0
1274
+ NSApplicationPresentationHideDock = 1 << 1
1275
+ NSApplicationPresentationHideMenuBar = 1 << 3
1276
+ NSApplicationPresentationDisableProcessSwitching = 1 << 5
1277
+ NSApplicationPresentationDisableHideApplication = 1 << 8
1278
+
1279
+ # NSRunningApplication.h
1280
+ NSApplicationActivationPolicyRegular = 0
1281
+ NSApplicationActivationPolicyAccessory = 1
1282
+ NSApplicationActivationPolicyProhibited = 2
1283
+
1284
+ ######################################################################
1285
+
1286
+ # QUARTZ / COREGRAPHICS
1287
+
1288
+ quartz = cdll.LoadLibrary(util.find_library('quartz'))
1289
+
1290
+ CGDirectDisplayID = c_uint32 # CGDirectDisplay.h
1291
+ CGError = c_int32 # CGError.h
1292
+ CGBitmapInfo = c_uint32 # CGImage.h
1293
+
1294
+ # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/...
1295
+ # ImageIO.framework/Headers/CGImageProperties.h
1296
+ kCGImagePropertyGIFDictionary = c_void_p.in_dll(
1297
+ quartz, 'kCGImagePropertyGIFDictionary')
1298
+ kCGImagePropertyGIFDelayTime = c_void_p.in_dll(
1299
+ quartz, 'kCGImagePropertyGIFDelayTime')
1300
+
1301
+ # /System/Library/Frameworks/ApplicationServices.framework/Frameworks/...
1302
+ # CoreGraphics.framework/Headers/CGColorSpace.h
1303
+ kCGRenderingIntentDefault = 0
1304
+
1305
+ quartz.CGDisplayIDToOpenGLDisplayMask.restype = c_uint32
1306
+ quartz.CGDisplayIDToOpenGLDisplayMask.argtypes = [c_uint32]
1307
+
1308
+ quartz.CGMainDisplayID.restype = CGDirectDisplayID
1309
+ quartz.CGMainDisplayID.argtypes = []
1310
+
1311
+ quartz.CGShieldingWindowLevel.restype = c_int32
1312
+ quartz.CGShieldingWindowLevel.argtypes = []
1313
+
1314
+ quartz.CGCursorIsVisible.restype = c_bool
1315
+
1316
+ quartz.CGDisplayCopyAllDisplayModes.restype = c_void_p
1317
+ quartz.CGDisplayCopyAllDisplayModes.argtypes = [CGDirectDisplayID, c_void_p]
1318
+
1319
+ quartz.CGDisplaySetDisplayMode.restype = CGError
1320
+ quartz.CGDisplaySetDisplayMode.argtypes = [
1321
+ CGDirectDisplayID, c_void_p, c_void_p]
1322
+
1323
+ quartz.CGDisplayCapture.restype = CGError
1324
+ quartz.CGDisplayCapture.argtypes = [CGDirectDisplayID]
1325
+
1326
+ quartz.CGDisplayRelease.restype = CGError
1327
+ quartz.CGDisplayRelease.argtypes = [CGDirectDisplayID]
1328
+
1329
+ quartz.CGDisplayCopyDisplayMode.restype = c_void_p
1330
+ quartz.CGDisplayCopyDisplayMode.argtypes = [CGDirectDisplayID]
1331
+
1332
+ quartz.CGDisplayModeGetRefreshRate.restype = c_double
1333
+ quartz.CGDisplayModeGetRefreshRate.argtypes = [c_void_p]
1334
+
1335
+ quartz.CGDisplayModeRetain.restype = c_void_p
1336
+ quartz.CGDisplayModeRetain.argtypes = [c_void_p]
1337
+
1338
+ quartz.CGDisplayModeRelease.restype = None
1339
+ quartz.CGDisplayModeRelease.argtypes = [c_void_p]
1340
+
1341
+ quartz.CGDisplayModeGetWidth.restype = c_size_t
1342
+ quartz.CGDisplayModeGetWidth.argtypes = [c_void_p]
1343
+
1344
+ quartz.CGDisplayModeGetHeight.restype = c_size_t
1345
+ quartz.CGDisplayModeGetHeight.argtypes = [c_void_p]
1346
+
1347
+ quartz.CGDisplayModeCopyPixelEncoding.restype = c_void_p
1348
+ quartz.CGDisplayModeCopyPixelEncoding.argtypes = [c_void_p]
1349
+
1350
+ quartz.CGGetActiveDisplayList.restype = CGError
1351
+ quartz.CGGetActiveDisplayList.argtypes = [
1352
+ c_uint32, POINTER(CGDirectDisplayID), POINTER(c_uint32)]
1353
+
1354
+ quartz.CGDisplayBounds.restype = CGRect
1355
+ quartz.CGDisplayBounds.argtypes = [CGDirectDisplayID]
1356
+
1357
+ quartz.CGImageSourceCreateWithData.restype = c_void_p
1358
+ quartz.CGImageSourceCreateWithData.argtypes = [c_void_p, c_void_p]
1359
+
1360
+ quartz.CGImageSourceCreateImageAtIndex.restype = c_void_p
1361
+ quartz.CGImageSourceCreateImageAtIndex.argtypes = [
1362
+ c_void_p, c_size_t, c_void_p]
1363
+
1364
+ quartz.CGImageSourceCopyPropertiesAtIndex.restype = c_void_p
1365
+ quartz.CGImageSourceCopyPropertiesAtIndex.argtypes = [
1366
+ c_void_p, c_size_t, c_void_p]
1367
+
1368
+ quartz.CGImageGetDataProvider.restype = c_void_p
1369
+ quartz.CGImageGetDataProvider.argtypes = [c_void_p]
1370
+
1371
+ quartz.CGDataProviderCopyData.restype = c_void_p
1372
+ quartz.CGDataProviderCopyData.argtypes = [c_void_p]
1373
+
1374
+ quartz.CGDataProviderCreateWithCFData.restype = c_void_p
1375
+ quartz.CGDataProviderCreateWithCFData.argtypes = [c_void_p]
1376
+
1377
+ quartz.CGImageCreate.restype = c_void_p
1378
+ quartz.CGImageCreate.argtypes = [c_size_t, c_size_t, c_size_t, c_size_t,
1379
+ c_size_t, c_void_p, c_uint32, c_void_p,
1380
+ c_void_p, c_bool, c_int]
1381
+
1382
+ quartz.CGImageRelease.restype = None
1383
+ quartz.CGImageRelease.argtypes = [c_void_p]
1384
+
1385
+ quartz.CGImageGetBytesPerRow.restype = c_size_t
1386
+ quartz.CGImageGetBytesPerRow.argtypes = [c_void_p]
1387
+
1388
+ quartz.CGImageGetWidth.restype = c_size_t
1389
+ quartz.CGImageGetWidth.argtypes = [c_void_p]
1390
+
1391
+ quartz.CGImageGetHeight.restype = c_size_t
1392
+ quartz.CGImageGetHeight.argtypes = [c_void_p]
1393
+
1394
+ quartz.CGImageGetBitsPerPixel.restype = c_size_t
1395
+ quartz.CGImageGetBitsPerPixel.argtypes = [c_void_p]
1396
+
1397
+ quartz.CGImageGetBitmapInfo.restype = CGBitmapInfo
1398
+ quartz.CGImageGetBitmapInfo.argtypes = [c_void_p]
1399
+
1400
+ quartz.CGColorSpaceCreateDeviceRGB.restype = c_void_p
1401
+ quartz.CGColorSpaceCreateDeviceRGB.argtypes = []
1402
+
1403
+ quartz.CGDataProviderRelease.restype = None
1404
+ quartz.CGDataProviderRelease.argtypes = [c_void_p]
1405
+
1406
+ quartz.CGColorSpaceRelease.restype = None
1407
+ quartz.CGColorSpaceRelease.argtypes = [c_void_p]
1408
+
1409
+ quartz.CGWarpMouseCursorPosition.restype = CGError
1410
+ quartz.CGWarpMouseCursorPosition.argtypes = [CGPoint]
1411
+
1412
+ quartz.CGDisplayMoveCursorToPoint.restype = CGError
1413
+ quartz.CGDisplayMoveCursorToPoint.argtypes = [CGDirectDisplayID, CGPoint]
1414
+
1415
+ quartz.CGAssociateMouseAndMouseCursorPosition.restype = CGError
1416
+ quartz.CGAssociateMouseAndMouseCursorPosition.argtypes = [c_bool]
1417
+
1418
+ quartz.CGBitmapContextCreate.restype = c_void_p
1419
+ quartz.CGBitmapContextCreate.argtypes = [
1420
+ c_void_p, c_size_t, c_size_t, c_size_t, c_size_t, c_void_p, CGBitmapInfo]
1421
+
1422
+ quartz.CGBitmapContextCreateImage.restype = c_void_p
1423
+ quartz.CGBitmapContextCreateImage.argtypes = [c_void_p]
1424
+
1425
+ quartz.CGFontCreateWithDataProvider.restype = c_void_p
1426
+ quartz.CGFontCreateWithDataProvider.argtypes = [c_void_p]
1427
+
1428
+ quartz.CGFontCreateWithFontName.restype = c_void_p
1429
+ quartz.CGFontCreateWithFontName.argtypes = [c_void_p]
1430
+
1431
+ quartz.CGContextDrawImage.restype = None
1432
+ quartz.CGContextDrawImage.argtypes = [c_void_p, CGRect, c_void_p]
1433
+
1434
+ quartz.CGContextRelease.restype = None
1435
+ quartz.CGContextRelease.argtypes = [c_void_p]
1436
+
1437
+ quartz.CGContextSetTextPosition.restype = None
1438
+ quartz.CGContextSetTextPosition.argtypes = [c_void_p, CGFloat, CGFloat]
1439
+
1440
+ quartz.CGContextSetShouldAntialias.restype = None
1441
+ quartz.CGContextSetShouldAntialias.argtypes = [c_void_p, c_bool]
1442
+
1443
+ quartz.CGDataProviderCreateWithURL.restype = c_void_p
1444
+ quartz.CGDataProviderCreateWithURL.argtypes = [c_void_p]
1445
+
1446
+ quartz.CGFontCreateWithDataProvider.restype = c_void_p
1447
+ quartz.CGFontCreateWithDataProvider.argtypes = [c_void_p]
1448
+
1449
+ quartz.CGDisplayScreenSize.argtypes = [CGDirectDisplayID]
1450
+ quartz.CGDisplayScreenSize.restype = CGSize
1451
+
1452
+ quartz.CGDisplayBounds.argtypes = [CGDirectDisplayID]
1453
+ quartz.CGDisplayBounds.restype = CGRect
1454
+
1455
+ ######################################################################
1456
+
1457
+ # CORETEXT
1458
+ ct = cdll.LoadLibrary(util.find_library('CoreText'))
1459
+
1460
+ # Types
1461
+ CTFontOrientation = c_uint32 # CTFontDescriptor.h
1462
+ CTFontSymbolicTraits = c_uint32 # CTFontTraits.h
1463
+
1464
+ # CoreText constants
1465
+ kCTFontAttributeName = c_void_p.in_dll(ct, 'kCTFontAttributeName')
1466
+ kCTFontFamilyNameAttribute = c_void_p.in_dll(ct, 'kCTFontFamilyNameAttribute')
1467
+ kCTFontSymbolicTrait = c_void_p.in_dll(ct, 'kCTFontSymbolicTrait')
1468
+ kCTFontWeightTrait = c_void_p.in_dll(ct, 'kCTFontWeightTrait')
1469
+ kCTFontTraitsAttribute = c_void_p.in_dll(ct, 'kCTFontTraitsAttribute')
1470
+
1471
+ # constants from CTFontTraits.h
1472
+ kCTFontItalicTrait = (1 << 0)
1473
+ kCTFontBoldTrait = (1 << 1)
1474
+
1475
+ ct.CTLineCreateWithAttributedString.restype = c_void_p
1476
+ ct.CTLineCreateWithAttributedString.argtypes = [c_void_p]
1477
+
1478
+ ct.CTLineDraw.restype = None
1479
+ ct.CTLineDraw.argtypes = [c_void_p, c_void_p]
1480
+
1481
+ ct.CTFontGetBoundingRectsForGlyphs.restype = CGRect
1482
+ ct.CTFontGetBoundingRectsForGlyphs.argtypes = [
1483
+ c_void_p, CTFontOrientation, POINTER(CGGlyph), POINTER(CGRect), CFIndex]
1484
+
1485
+ ct.CTFontGetAdvancesForGlyphs.restype = c_double
1486
+ ct.CTFontGetAdvancesForGlyphs.argtypes = [
1487
+ c_void_p, CTFontOrientation, POINTER(CGGlyph), POINTER(CGSize), CFIndex]
1488
+
1489
+ ct.CTFontGetAscent.restype = CGFloat
1490
+ ct.CTFontGetAscent.argtypes = [c_void_p]
1491
+
1492
+ ct.CTFontGetDescent.restype = CGFloat
1493
+ ct.CTFontGetDescent.argtypes = [c_void_p]
1494
+
1495
+ ct.CTFontGetSymbolicTraits.restype = CTFontSymbolicTraits
1496
+ ct.CTFontGetSymbolicTraits.argtypes = [c_void_p]
1497
+
1498
+ ct.CTFontGetGlyphsForCharacters.restype = c_bool
1499
+ ct.CTFontGetGlyphsForCharacters.argtypes = [
1500
+ c_void_p, POINTER(UniChar), POINTER(CGGlyph), CFIndex]
1501
+
1502
+ ct.CTFontCreateWithGraphicsFont.restype = c_void_p
1503
+ ct.CTFontCreateWithGraphicsFont.argtypes = [c_void_p, CGFloat, c_void_p,
1504
+ c_void_p]
1505
+
1506
+ ct.CTFontCopyFamilyName.restype = c_void_p
1507
+ ct.CTFontCopyFamilyName.argtypes = [c_void_p]
1508
+
1509
+ ct.CTFontCopyFullName.restype = c_void_p
1510
+ ct.CTFontCopyFullName.argtypes = [c_void_p]
1511
+
1512
+ ct.CTFontCreateWithFontDescriptor.restype = c_void_p
1513
+ ct.CTFontCreateWithFontDescriptor.argtypes = [c_void_p, CGFloat, c_void_p]
1514
+
1515
+ ct.CTFontCreateCopyWithAttributes.restype = c_void_p
1516
+ ct.CTFontCreateCopyWithAttributes.argtypes = [c_void_p, CGFloat, c_void_p,
1517
+ c_void_p]
1518
+
1519
+ ct.CTFontDescriptorCreateWithAttributes.restype = c_void_p
1520
+ ct.CTFontDescriptorCreateWithAttributes.argtypes = [c_void_p]
1521
+
1522
+ ct.CTTypesetterCreateWithAttributedString.restype = c_void_p
1523
+ ct.CTTypesetterCreateWithAttributedString.argtypes = [c_void_p]
1524
+
1525
+ ct.CTTypesetterCreateLine.restype = c_void_p
1526
+ ct.CTTypesetterCreateLine.argtypes = [c_void_p, CFRange]
1527
+
1528
+ ct.CTLineGetOffsetForStringIndex.restype = CGFloat
1529
+ ct.CTLineGetOffsetForStringIndex.argtypes = [c_void_p, CFIndex,
1530
+ POINTER(CGFloat)]
1531
+
1532
+ ct.CTFontManagerCreateFontDescriptorsFromURL.restype = c_void_p
1533
+ ct.CTFontManagerCreateFontDescriptorsFromURL.argtypes = [c_void_p]
1534
+
1535
+ ######################################################################
1536
+
1537
+ # FOUNDATION
1538
+
1539
+ # foundation = cdll.LoadLibrary(util.find_library('Foundation'))
1540
+
1541
+ # foundation.NSMouseInRect.restype = c_bool
1542
+ # foundation.NSMouseInRect.argtypes = [NSPoint, NSRect, c_bool]