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