wxPython 4.3.2__cp315-cp315-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.
Files changed (472) hide show
  1. wx/WebView2Loader.dll +0 -0
  2. wx/__init__.py +22 -0
  3. wx/__init__.pyi +10 -0
  4. wx/__version__.py +9 -0
  5. wx/__version__.pyi +15 -0
  6. wx/_adv.cp315-win_amd64.pyd +0 -0
  7. wx/_aui.cp315-win_amd64.pyd +0 -0
  8. wx/_core.cp315-win_amd64.pyd +0 -0
  9. wx/_dataview.cp315-win_amd64.pyd +0 -0
  10. wx/_glcanvas.cp315-win_amd64.pyd +0 -0
  11. wx/_grid.cp315-win_amd64.pyd +0 -0
  12. wx/_html.cp315-win_amd64.pyd +0 -0
  13. wx/_html2.cp315-win_amd64.pyd +0 -0
  14. wx/_media.cp315-win_amd64.pyd +0 -0
  15. wx/_msw.cp315-win_amd64.pyd +0 -0
  16. wx/_propgrid.cp315-win_amd64.pyd +0 -0
  17. wx/_ribbon.cp315-win_amd64.pyd +0 -0
  18. wx/_richtext.cp315-win_amd64.pyd +0 -0
  19. wx/_stc.cp315-win_amd64.pyd +0 -0
  20. wx/_xml.cp315-win_amd64.pyd +0 -0
  21. wx/_xrc.cp315-win_amd64.pyd +0 -0
  22. wx/adv.py +127 -0
  23. wx/adv.pyi +5931 -0
  24. wx/aui.py +70 -0
  25. wx/aui.pyi +4805 -0
  26. wx/core.py +3417 -0
  27. wx/core.pyi +62949 -0
  28. wx/dataview.py +176 -0
  29. wx/dataview.pyi +3828 -0
  30. wx/gizmos.py +18 -0
  31. wx/glcanvas.py +13 -0
  32. wx/glcanvas.pyi +544 -0
  33. wx/grid.py +237 -0
  34. wx/grid.pyi +5678 -0
  35. wx/html.py +38 -0
  36. wx/html.pyi +3283 -0
  37. wx/html2.py +46 -0
  38. wx/html2.pyi +1301 -0
  39. wx/include/wxPython/sip.h +1938 -0
  40. wx/include/wxPython/wxpy_api.h +418 -0
  41. wx/lib/CDate.py +201 -0
  42. wx/lib/ClickableHtmlWindow.py +57 -0
  43. wx/lib/__init__.py +0 -0
  44. wx/lib/activex.py +178 -0
  45. wx/lib/activexwrapper.py +153 -0
  46. wx/lib/agw/__init__.py +128 -0
  47. wx/lib/agw/advancedsplash.py +563 -0
  48. wx/lib/agw/aquabutton.py +1127 -0
  49. wx/lib/agw/artmanager.py +2110 -0
  50. wx/lib/agw/aui/__init__.py +295 -0
  51. wx/lib/agw/aui/aui_constants.py +2616 -0
  52. wx/lib/agw/aui/aui_switcherdialog.py +1232 -0
  53. wx/lib/agw/aui/aui_utilities.py +648 -0
  54. wx/lib/agw/aui/auibar.py +4045 -0
  55. wx/lib/agw/aui/auibook.py +6288 -0
  56. wx/lib/agw/aui/dockart.py +1198 -0
  57. wx/lib/agw/aui/framemanager.py +10485 -0
  58. wx/lib/agw/aui/tabart.py +2749 -0
  59. wx/lib/agw/aui/tabmdi.py +679 -0
  60. wx/lib/agw/balloontip.py +1157 -0
  61. wx/lib/agw/buttonpanel.py +2787 -0
  62. wx/lib/agw/cubecolourdialog.py +3529 -0
  63. wx/lib/agw/customtreectrl.py +9908 -0
  64. wx/lib/agw/data/ShortcutEditor_1.png +0 -0
  65. wx/lib/agw/data/ShortcutEditor_1_thumb.png +0 -0
  66. wx/lib/agw/data/ShortcutEditor_2.png +0 -0
  67. wx/lib/agw/data/ShortcutEditor_2_thumb.png +0 -0
  68. wx/lib/agw/data/ShortcutEditor_3.png +0 -0
  69. wx/lib/agw/data/ShortcutEditor_3_thumb.png +0 -0
  70. wx/lib/agw/data/ShortcutEditor_4.png +0 -0
  71. wx/lib/agw/data/ShortcutEditor_4_thumb.png +0 -0
  72. wx/lib/agw/data/default_help_text.html +105 -0
  73. wx/lib/agw/flatmenu.py +7392 -0
  74. wx/lib/agw/flatnotebook.py +6669 -0
  75. wx/lib/agw/floatspin.py +1820 -0
  76. wx/lib/agw/fmcustomizedlg.py +535 -0
  77. wx/lib/agw/fmresources.py +407 -0
  78. wx/lib/agw/foldpanelbar.py +2282 -0
  79. wx/lib/agw/fourwaysplitter.py +1130 -0
  80. wx/lib/agw/genericmessagedialog.py +1549 -0
  81. wx/lib/agw/gradientbutton.py +731 -0
  82. wx/lib/agw/hyperlink.py +664 -0
  83. wx/lib/agw/hypertreelist.py +5756 -0
  84. wx/lib/agw/infobar.py +885 -0
  85. wx/lib/agw/knobctrl.py +944 -0
  86. wx/lib/agw/labelbook.py +3028 -0
  87. wx/lib/agw/multidirdialog.py +581 -0
  88. wx/lib/agw/peakmeter.py +1028 -0
  89. wx/lib/agw/persist/__init__.py +188 -0
  90. wx/lib/agw/persist/persist_constants.py +283 -0
  91. wx/lib/agw/persist/persist_handlers.py +2614 -0
  92. wx/lib/agw/persist/persistencemanager.py +863 -0
  93. wx/lib/agw/piectrl.py +1082 -0
  94. wx/lib/agw/pybusyinfo.py +399 -0
  95. wx/lib/agw/pycollapsiblepane.py +940 -0
  96. wx/lib/agw/pygauge.py +570 -0
  97. wx/lib/agw/pyprogress.py +916 -0
  98. wx/lib/agw/ribbon/__init__.py +198 -0
  99. wx/lib/agw/ribbon/art.py +219 -0
  100. wx/lib/agw/ribbon/art_aui.py +1283 -0
  101. wx/lib/agw/ribbon/art_default.py +81 -0
  102. wx/lib/agw/ribbon/art_internal.py +248 -0
  103. wx/lib/agw/ribbon/art_msw.py +2735 -0
  104. wx/lib/agw/ribbon/art_osx.py +52 -0
  105. wx/lib/agw/ribbon/bar.py +1259 -0
  106. wx/lib/agw/ribbon/buttonbar.py +1317 -0
  107. wx/lib/agw/ribbon/control.py +205 -0
  108. wx/lib/agw/ribbon/gallery.py +973 -0
  109. wx/lib/agw/ribbon/page.py +946 -0
  110. wx/lib/agw/ribbon/panel.py +1170 -0
  111. wx/lib/agw/ribbon/toolbar.py +1441 -0
  112. wx/lib/agw/rulerctrl.py +1885 -0
  113. wx/lib/agw/scrolledthumbnail.py +2116 -0
  114. wx/lib/agw/shapedbutton.py +1809 -0
  115. wx/lib/agw/shortcuteditor.py +2642 -0
  116. wx/lib/agw/speedmeter.py +1800 -0
  117. wx/lib/agw/supertooltip.py +1443 -0
  118. wx/lib/agw/thumbnailctrl.py +529 -0
  119. wx/lib/agw/toasterbox.py +1327 -0
  120. wx/lib/agw/ultimatelistctrl.py +13671 -0
  121. wx/lib/agw/xlsgrid.py +2111 -0
  122. wx/lib/agw/zoombar.py +1336 -0
  123. wx/lib/analogclock/__init__.py +140 -0
  124. wx/lib/analogclock/analogclock.py +630 -0
  125. wx/lib/analogclock/helpers.py +986 -0
  126. wx/lib/analogclock/lib_setup/__init__.py +0 -0
  127. wx/lib/analogclock/lib_setup/buttontreectrlpanel.py +297 -0
  128. wx/lib/analogclock/lib_setup/fontselect.py +57 -0
  129. wx/lib/analogclock/setup.py +490 -0
  130. wx/lib/analogclock/styles.py +47 -0
  131. wx/lib/anchors.py +103 -0
  132. wx/lib/art/__init__.py +4 -0
  133. wx/lib/art/flagart.py +1583 -0
  134. wx/lib/art/img2pyartprov.py +56 -0
  135. wx/lib/busy.py +152 -0
  136. wx/lib/buttons.py +1140 -0
  137. wx/lib/calendar.py +1596 -0
  138. wx/lib/checkbox.py +837 -0
  139. wx/lib/colourchooser/__init__.py +36 -0
  140. wx/lib/colourchooser/canvas.py +145 -0
  141. wx/lib/colourchooser/intl.py +24 -0
  142. wx/lib/colourchooser/pycolourbox.py +89 -0
  143. wx/lib/colourchooser/pycolourchooser.py +626 -0
  144. wx/lib/colourchooser/pycolourslider.py +98 -0
  145. wx/lib/colourchooser/pypalette.py +208 -0
  146. wx/lib/colourdb.py +740 -0
  147. wx/lib/colourselect.py +385 -0
  148. wx/lib/colourutils.py +118 -0
  149. wx/lib/combotreebox.py +944 -0
  150. wx/lib/delayedresult.py +420 -0
  151. wx/lib/dialogs.py +510 -0
  152. wx/lib/docview.py +3210 -0
  153. wx/lib/dragscroller.py +79 -0
  154. wx/lib/editor/README.txt +77 -0
  155. wx/lib/editor/__init__.py +24 -0
  156. wx/lib/editor/editor.py +974 -0
  157. wx/lib/editor/images.py +15 -0
  158. wx/lib/editor/selection.py +44 -0
  159. wx/lib/embeddedimage.py +76 -0
  160. wx/lib/eventStack.py +136 -0
  161. wx/lib/eventwatcher.py +440 -0
  162. wx/lib/evtmgr.py +521 -0
  163. wx/lib/expando.py +393 -0
  164. wx/lib/fancytext.py +494 -0
  165. wx/lib/filebrowsebutton.py +461 -0
  166. wx/lib/flashwin.py +262 -0
  167. wx/lib/flashwin_old.py +651 -0
  168. wx/lib/floatcanvas/FCEvents.py +53 -0
  169. wx/lib/floatcanvas/FCObjects.py +2910 -0
  170. wx/lib/floatcanvas/FloatCanvas.py +1025 -0
  171. wx/lib/floatcanvas/GUIMode.py +396 -0
  172. wx/lib/floatcanvas/NavCanvas.py +162 -0
  173. wx/lib/floatcanvas/Resources.py +319 -0
  174. wx/lib/floatcanvas/ScreenShot.py +1788 -0
  175. wx/lib/floatcanvas/Utilities/BBox.py +313 -0
  176. wx/lib/floatcanvas/Utilities/Colors.py +137 -0
  177. wx/lib/floatcanvas/Utilities/GUI.py +91 -0
  178. wx/lib/floatcanvas/Utilities/__init__.py +7 -0
  179. wx/lib/floatcanvas/__init__.py +124 -0
  180. wx/lib/foldmenu.py +89 -0
  181. wx/lib/gestures.py +310 -0
  182. wx/lib/gizmos/__init__.py +18 -0
  183. wx/lib/gizmos/dynamicsash.py +1202 -0
  184. wx/lib/gizmos/ledctrl.py +299 -0
  185. wx/lib/gizmos/treelistctrl.py +87 -0
  186. wx/lib/graphics.py +1942 -0
  187. wx/lib/gridmovers.py +516 -0
  188. wx/lib/iewin.py +249 -0
  189. wx/lib/iewin_old.py +894 -0
  190. wx/lib/imagebrowser.py +853 -0
  191. wx/lib/imageutils.py +163 -0
  192. wx/lib/infoframe.py +490 -0
  193. wx/lib/inspection.py +1254 -0
  194. wx/lib/intctrl.py +990 -0
  195. wx/lib/itemspicker.py +256 -0
  196. wx/lib/langlistctrl.py +480 -0
  197. wx/lib/layoutf.py +271 -0
  198. wx/lib/masked/__init__.py +27 -0
  199. wx/lib/masked/combobox.py +839 -0
  200. wx/lib/masked/ctrl.py +108 -0
  201. wx/lib/masked/ipaddrctrl.py +241 -0
  202. wx/lib/masked/maskededit.py +7262 -0
  203. wx/lib/masked/numctrl.py +2000 -0
  204. wx/lib/masked/textctrl.py +465 -0
  205. wx/lib/masked/timectrl.py +1465 -0
  206. wx/lib/mixins/__init__.py +17 -0
  207. wx/lib/mixins/grid.py +47 -0
  208. wx/lib/mixins/gridlabelrenderer.py +277 -0
  209. wx/lib/mixins/imagelist.py +77 -0
  210. wx/lib/mixins/inspection.py +184 -0
  211. wx/lib/mixins/listctrl.py +893 -0
  212. wx/lib/mixins/rubberband.py +403 -0
  213. wx/lib/mixins/treemixin.py +678 -0
  214. wx/lib/msgpanel.py +95 -0
  215. wx/lib/multisash.py +746 -0
  216. wx/lib/myole4ax.idl +178 -0
  217. wx/lib/myole4ax.tlb +0 -0
  218. wx/lib/newevent.py +229 -0
  219. wx/lib/newevent.pyi +25 -0
  220. wx/lib/nvdlg.py +156 -0
  221. wx/lib/ogl/__init__.py +13 -0
  222. wx/lib/ogl/basic.py +3989 -0
  223. wx/lib/ogl/bmpshape.py +86 -0
  224. wx/lib/ogl/canvas.py +467 -0
  225. wx/lib/ogl/composit.py +1576 -0
  226. wx/lib/ogl/diagram.py +230 -0
  227. wx/lib/ogl/divided.py +482 -0
  228. wx/lib/ogl/drawn.py +898 -0
  229. wx/lib/ogl/lines.py +1809 -0
  230. wx/lib/ogl/oglmisc.py +607 -0
  231. wx/lib/pdfviewer/__init__.py +113 -0
  232. wx/lib/pdfviewer/bitmaps/ArrowLeft.png +0 -0
  233. wx/lib/pdfviewer/bitmaps/ArrowRight.png +0 -0
  234. wx/lib/pdfviewer/bitmaps/DirectionH.png +0 -0
  235. wx/lib/pdfviewer/bitmaps/DirectionV.png +0 -0
  236. wx/lib/pdfviewer/bitmaps/PlayerFirst.png +0 -0
  237. wx/lib/pdfviewer/bitmaps/PlayerLast.png +0 -0
  238. wx/lib/pdfviewer/bitmaps/PlayerNext.png +0 -0
  239. wx/lib/pdfviewer/bitmaps/PlayerPrev.png +0 -0
  240. wx/lib/pdfviewer/bitmaps/Printer.png +0 -0
  241. wx/lib/pdfviewer/bitmaps/ReadMe.txt +28 -0
  242. wx/lib/pdfviewer/bitmaps/Save.png +0 -0
  243. wx/lib/pdfviewer/bitmaps/ZoomIn.png +0 -0
  244. wx/lib/pdfviewer/bitmaps/ZoomOut.png +0 -0
  245. wx/lib/pdfviewer/bitmaps/encode_bitmaps.py +37 -0
  246. wx/lib/pdfviewer/buttonpanel.py +285 -0
  247. wx/lib/pdfviewer/images.py +240 -0
  248. wx/lib/pdfviewer/viewer.py +1118 -0
  249. wx/lib/pdfwin.py +295 -0
  250. wx/lib/pdfwin_old.py +789 -0
  251. wx/lib/platebtn.py +789 -0
  252. wx/lib/plot/CHANGELOG.md +150 -0
  253. wx/lib/plot/README.md +16 -0
  254. wx/lib/plot/__init__.py +46 -0
  255. wx/lib/plot/__main__.py +5 -0
  256. wx/lib/plot/examples/__init__.py +0 -0
  257. wx/lib/plot/examples/demo.py +1010 -0
  258. wx/lib/plot/examples/simple_example.py +56 -0
  259. wx/lib/plot/plotcanvas.py +2985 -0
  260. wx/lib/plot/polyobjects.py +1524 -0
  261. wx/lib/plot/utils.py +334 -0
  262. wx/lib/popupctl.py +251 -0
  263. wx/lib/printout.py +1155 -0
  264. wx/lib/progressindicator.py +151 -0
  265. wx/lib/pubsub/LICENSE_BSD_Simple.txt +23 -0
  266. wx/lib/pubsub/README_WxPython.txt +22 -0
  267. wx/lib/pubsub/RELEASE_NOTES.txt +71 -0
  268. wx/lib/pubsub/__init__.py +25 -0
  269. wx/lib/pubsub/core/__init__.py +92 -0
  270. wx/lib/pubsub/core/arg1/__init__.py +16 -0
  271. wx/lib/pubsub/core/arg1/listenerimpl.py +97 -0
  272. wx/lib/pubsub/core/arg1/publisher.py +40 -0
  273. wx/lib/pubsub/core/arg1/publishermixin.py +34 -0
  274. wx/lib/pubsub/core/arg1/topicargspecimpl.py +66 -0
  275. wx/lib/pubsub/core/arg1/topicmgrimpl.py +19 -0
  276. wx/lib/pubsub/core/callables.py +198 -0
  277. wx/lib/pubsub/core/imp2.py +62 -0
  278. wx/lib/pubsub/core/itopicdefnprovider.py +0 -0
  279. wx/lib/pubsub/core/kwargs/__init__.py +16 -0
  280. wx/lib/pubsub/core/kwargs/datamsg.py +27 -0
  281. wx/lib/pubsub/core/kwargs/listenerimpl.py +93 -0
  282. wx/lib/pubsub/core/kwargs/publisher.py +77 -0
  283. wx/lib/pubsub/core/kwargs/publishermixin.py +65 -0
  284. wx/lib/pubsub/core/kwargs/topicargspecimpl.py +216 -0
  285. wx/lib/pubsub/core/kwargs/topicmgrimpl.py +13 -0
  286. wx/lib/pubsub/core/listener.py +40 -0
  287. wx/lib/pubsub/core/listenerbase.py +185 -0
  288. wx/lib/pubsub/core/notificationmgr.py +185 -0
  289. wx/lib/pubsub/core/publisherbase.py +189 -0
  290. wx/lib/pubsub/core/topicargspec.py +77 -0
  291. wx/lib/pubsub/core/topicdefnprovider.py +631 -0
  292. wx/lib/pubsub/core/topicexc.py +72 -0
  293. wx/lib/pubsub/core/topicmgr.py +454 -0
  294. wx/lib/pubsub/core/topicobj.py +472 -0
  295. wx/lib/pubsub/core/topictreetraverser.py +143 -0
  296. wx/lib/pubsub/core/topicutils.py +119 -0
  297. wx/lib/pubsub/core/treeconfig.py +21 -0
  298. wx/lib/pubsub/core/validatedefnargs.py +29 -0
  299. wx/lib/pubsub/core/weakmethod.py +102 -0
  300. wx/lib/pubsub/policies.py +24 -0
  301. wx/lib/pubsub/pub.py +199 -0
  302. wx/lib/pubsub/setuparg1.py +47 -0
  303. wx/lib/pubsub/setupkwargs.py +29 -0
  304. wx/lib/pubsub/utils/__init__.py +27 -0
  305. wx/lib/pubsub/utils/exchandling.py +100 -0
  306. wx/lib/pubsub/utils/misc.py +99 -0
  307. wx/lib/pubsub/utils/notification.py +331 -0
  308. wx/lib/pubsub/utils/topictreeprinter.py +195 -0
  309. wx/lib/pubsub/utils/xmltopicdefnprovider.py +286 -0
  310. wx/lib/pydocview.py +3300 -0
  311. wx/lib/rcsizer.py +227 -0
  312. wx/lib/resizewidget.py +357 -0
  313. wx/lib/scrolledpanel.py +243 -0
  314. wx/lib/sheet.py +350 -0
  315. wx/lib/sized_controls.py +691 -0
  316. wx/lib/softwareupdate.py +355 -0
  317. wx/lib/splitter.py +925 -0
  318. wx/lib/statbmp.py +199 -0
  319. wx/lib/stattext.py +321 -0
  320. wx/lib/throbber.py +424 -0
  321. wx/lib/ticker.py +306 -0
  322. wx/lib/ticker_xrc.py +48 -0
  323. wx/lib/utils.py +89 -0
  324. wx/lib/wordwrap.py +97 -0
  325. wx/lib/wxcairo/__init__.py +139 -0
  326. wx/lib/wxcairo/wx_cairocffi.py +200 -0
  327. wx/lib/wxcairo/wx_pycairo.py +455 -0
  328. wx/lib/wxpTag.py +274 -0
  329. wx/libcairo-2.dll +0 -0
  330. wx/locale/af/LC_MESSAGES/wxstd.mo +0 -0
  331. wx/locale/an/LC_MESSAGES/wxstd.mo +0 -0
  332. wx/locale/ar/LC_MESSAGES/wxstd.mo +0 -0
  333. wx/locale/ca/LC_MESSAGES/wxstd.mo +0 -0
  334. wx/locale/ca@valencia/LC_MESSAGES/wxstd.mo +0 -0
  335. wx/locale/co/LC_MESSAGES/wxstd.mo +0 -0
  336. wx/locale/cs/LC_MESSAGES/wxstd.mo +0 -0
  337. wx/locale/da/LC_MESSAGES/wxstd.mo +0 -0
  338. wx/locale/de/LC_MESSAGES/wxstd.mo +0 -0
  339. wx/locale/el/LC_MESSAGES/wxstd.mo +0 -0
  340. wx/locale/es/LC_MESSAGES/wxstd.mo +0 -0
  341. wx/locale/eu/LC_MESSAGES/wxstd.mo +0 -0
  342. wx/locale/fa_IR/LC_MESSAGES/wxstd.mo +0 -0
  343. wx/locale/fi/LC_MESSAGES/wxstd.mo +0 -0
  344. wx/locale/fr/LC_MESSAGES/wxstd.mo +0 -0
  345. wx/locale/gl_ES/LC_MESSAGES/wxstd.mo +0 -0
  346. wx/locale/hi/LC_MESSAGES/wxstd.mo +0 -0
  347. wx/locale/hr/LC_MESSAGES/wxstd.mo +0 -0
  348. wx/locale/hu/LC_MESSAGES/wxstd.mo +0 -0
  349. wx/locale/id/LC_MESSAGES/wxstd.mo +0 -0
  350. wx/locale/it/LC_MESSAGES/wxstd.mo +0 -0
  351. wx/locale/ja/LC_MESSAGES/wxstd.mo +0 -0
  352. wx/locale/ka/LC_MESSAGES/wxstd.mo +0 -0
  353. wx/locale/ko_KR/LC_MESSAGES/wxstd.mo +0 -0
  354. wx/locale/lt/LC_MESSAGES/wxstd.mo +0 -0
  355. wx/locale/lv/LC_MESSAGES/wxstd.mo +0 -0
  356. wx/locale/ms/LC_MESSAGES/wxstd.mo +0 -0
  357. wx/locale/nb/LC_MESSAGES/wxstd.mo +0 -0
  358. wx/locale/ne/LC_MESSAGES/wxstd.mo +0 -0
  359. wx/locale/nl/LC_MESSAGES/wxstd.mo +0 -0
  360. wx/locale/pl/LC_MESSAGES/wxstd.mo +0 -0
  361. wx/locale/pt/LC_MESSAGES/wxstd.mo +0 -0
  362. wx/locale/pt_BR/LC_MESSAGES/wxstd.mo +0 -0
  363. wx/locale/ro/LC_MESSAGES/wxstd.mo +0 -0
  364. wx/locale/ru/LC_MESSAGES/wxstd.mo +0 -0
  365. wx/locale/sk/LC_MESSAGES/wxstd.mo +0 -0
  366. wx/locale/sl/LC_MESSAGES/wxstd.mo +0 -0
  367. wx/locale/sq/LC_MESSAGES/wxstd.mo +0 -0
  368. wx/locale/sr/LC_MESSAGES/wxstd.mo +0 -0
  369. wx/locale/sv/LC_MESSAGES/wxstd.mo +0 -0
  370. wx/locale/ta/LC_MESSAGES/wxstd.mo +0 -0
  371. wx/locale/tr/LC_MESSAGES/wxstd.mo +0 -0
  372. wx/locale/uk/LC_MESSAGES/wxstd.mo +0 -0
  373. wx/locale/vi/LC_MESSAGES/wxstd.mo +0 -0
  374. wx/locale/zh_CN/LC_MESSAGES/wxstd.mo +0 -0
  375. wx/locale/zh_TW/LC_MESSAGES/wxstd.mo +0 -0
  376. wx/media.py +30 -0
  377. wx/media.pyi +272 -0
  378. wx/msw.py +16 -0
  379. wx/msw.pyi +91 -0
  380. wx/propgrid.py +498 -0
  381. wx/propgrid.pyi +7427 -0
  382. wx/py/CHANGES.txt +796 -0
  383. wx/py/Py.ico +0 -0
  384. wx/py/PyAlaCarte.py +34 -0
  385. wx/py/PyAlaMode.py +34 -0
  386. wx/py/PyAlaModeTest.py +33 -0
  387. wx/py/PyCrust.ico +0 -0
  388. wx/py/PyCrust.py +78 -0
  389. wx/py/PyCrust_16.png +0 -0
  390. wx/py/PyCrust_32.png +0 -0
  391. wx/py/PyFilling.py +35 -0
  392. wx/py/PyShell.py +78 -0
  393. wx/py/PySlices.ico +0 -0
  394. wx/py/PySlices.py +98 -0
  395. wx/py/PySlicesShell.py +94 -0
  396. wx/py/PySlices_16.png +0 -0
  397. wx/py/PySlices_32.png +0 -0
  398. wx/py/PyWrap.py +52 -0
  399. wx/py/README.txt +77 -0
  400. wx/py/__init__.py +20 -0
  401. wx/py/buffer.py +136 -0
  402. wx/py/crust.py +403 -0
  403. wx/py/crustslices.py +403 -0
  404. wx/py/dispatcher.py +259 -0
  405. wx/py/document.py +37 -0
  406. wx/py/editor.py +844 -0
  407. wx/py/editwindow.py +316 -0
  408. wx/py/filling.py +358 -0
  409. wx/py/frame.py +976 -0
  410. wx/py/images.py +212 -0
  411. wx/py/interpreter.py +161 -0
  412. wx/py/introspect.py +402 -0
  413. wx/py/magic.py +98 -0
  414. wx/py/parse.py +134 -0
  415. wx/py/path.py +36 -0
  416. wx/py/pseudo.py +99 -0
  417. wx/py/shell.py +1579 -0
  418. wx/py/sliceshell.py +3805 -0
  419. wx/py/tests/test_interpreter.py +71 -0
  420. wx/py/tests/test_introspect.py +810 -0
  421. wx/py/tests/test_pseudo.py +70 -0
  422. wx/py/tests/test_version.py +36 -0
  423. wx/py/tests/testall.py +22 -0
  424. wx/py/version.py +7 -0
  425. wx/py.typed +0 -0
  426. wx/ribbon.py +48 -0
  427. wx/ribbon.pyi +3099 -0
  428. wx/richtext.py +141 -0
  429. wx/richtext.pyi +13581 -0
  430. wx/siplib.cp315-win_amd64.pyd +0 -0
  431. wx/siplib.pyi +19 -0
  432. wx/stc.py +59 -0
  433. wx/stc.pyi +9918 -0
  434. wx/svg/__init__.py +363 -0
  435. wx/svg/_nanosvg.cp315-win_amd64.pyd +0 -0
  436. wx/tools/__init__.py +18 -0
  437. wx/tools/dbg.py +268 -0
  438. wx/tools/genaxmodule.py +50 -0
  439. wx/tools/helpviewer.py +92 -0
  440. wx/tools/img2img.py +85 -0
  441. wx/tools/img2png.py +54 -0
  442. wx/tools/img2py.py +306 -0
  443. wx/tools/img2xpm.py +54 -0
  444. wx/tools/pywxrc.py +951 -0
  445. wx/tools/wxget.py +254 -0
  446. wx/tools/wxget_docs_demo.py +183 -0
  447. wx/wxbase334u_net_vc140_x64.dll +0 -0
  448. wx/wxbase334u_vc140_x64.dll +0 -0
  449. wx/wxbase334u_xml_vc140_x64.dll +0 -0
  450. wx/wxmsw334u_adv_vc140_x64.dll +0 -0
  451. wx/wxmsw334u_aui_vc140_x64.dll +0 -0
  452. wx/wxmsw334u_core_vc140_x64.dll +0 -0
  453. wx/wxmsw334u_gl_vc140_x64.dll +0 -0
  454. wx/wxmsw334u_html_vc140_x64.dll +0 -0
  455. wx/wxmsw334u_media_vc140_x64.dll +0 -0
  456. wx/wxmsw334u_propgrid_vc140_x64.dll +0 -0
  457. wx/wxmsw334u_qa_vc140_x64.dll +0 -0
  458. wx/wxmsw334u_ribbon_vc140_x64.dll +0 -0
  459. wx/wxmsw334u_richtext_vc140_x64.dll +0 -0
  460. wx/wxmsw334u_stc_vc140_x64.dll +0 -0
  461. wx/wxmsw334u_webview_vc140_x64.dll +0 -0
  462. wx/wxmsw334u_xrc_vc140_x64.dll +0 -0
  463. wx/xml.py +18 -0
  464. wx/xml.pyi +728 -0
  465. wx/xrc.py +68 -0
  466. wx/xrc.pyi +896 -0
  467. wxpython-4.3.2.dist-info/METADATA +71 -0
  468. wxpython-4.3.2.dist-info/RECORD +472 -0
  469. wxpython-4.3.2.dist-info/WHEEL +5 -0
  470. wxpython-4.3.2.dist-info/entry_points.txt +13 -0
  471. wxpython-4.3.2.dist-info/licenses/LICENSE.txt +610 -0
  472. wxpython-4.3.2.dist-info/top_level.txt +1 -0
wx/lib/graphics.py ADDED
@@ -0,0 +1,1942 @@
1
+ #----------------------------------------------------------------------
2
+ # Name: wx.lib.graphics
3
+ # Purpose: A wx.GraphicsContext-like API implemented using cairo
4
+ # and wx.lib.wxcairo.
5
+ #
6
+ # Author: Robin Dunn
7
+ #
8
+ # Created: 15-Sept-2008
9
+ # Copyright: (c) 2008-2020 by Total Control Software
10
+ # Licence: wxWindows license
11
+ # Tags: phoenix-port
12
+ #----------------------------------------------------------------------
13
+
14
+ """
15
+ This module implements an API similar to :class:`wx.GraphicsContext` and its
16
+ related classes. In this case the implementation for all platforms is done
17
+ using Cairo, via the :mod:`wx.lib.wxcairo` glue module.
18
+
19
+ Why do this? Why not just use ``wx.GraphicsContext`` everywhere? Using Cairo
20
+ on every platform enables us to more easily be totally consistent on all
21
+ platforms. Implementing it in Python means that it is easy to fill in the
22
+ gaps in functionality with features of Cairo that ``wx.GraphicsContext`` may
23
+ not provide, like converting text to a path, using compositing operators, or
24
+ being able to provide an implementation for things like context.Clear().
25
+
26
+ Why not just use Cairo directly? There may be times when you do want to use
27
+ ``wx.GrpahicsContext``, so being able to share code between that and this
28
+ implementation is nice. Also, I like the class hierarchy and API exposed by
29
+ the ``wx.GraphicsContext`` classes a little better than Cairo's.
30
+
31
+ .. note:: It is possible to write code using this module that is **not**
32
+ compatible with :class:`wx.GraphicsContext` code, because, you know, this
33
+ is Python and it is lots more flexible and powerful. However the intent
34
+ is that the reverse will not be true, that code compatible with
35
+ ``wx.GraphicsContext`` will (mostly) work when using these classes instead.
36
+ Care should be taken when modifying this module so that the compatibility
37
+ is maintained.
38
+ """
39
+
40
+ import sys
41
+ import math
42
+
43
+ import wx
44
+ import wx.lib.wxcairo as wxcairo
45
+ import cairo
46
+
47
+ if sys.version_info >= (3, 11):
48
+ from typing import Self
49
+ else:
50
+ from typing_extensions import Self
51
+
52
+ # Other ideas:
53
+ # 1. TextToPath (or maybe make this part of the Path class
54
+ # 3. Relative moves, lines, curves, etc.
55
+ # 5. maybe expose cairo_paint, cairo_paint_with_alpha, cairo_mask?
56
+
57
+ #---------------------------------------------------------------------------
58
+ # Image surface formats
59
+
60
+ FORMAT_ARGB32 = cairo.FORMAT_ARGB32
61
+ FORMAT_RGB24 = cairo.FORMAT_RGB24
62
+ FORMAT_A8 = cairo.FORMAT_A8
63
+ FORMAT_A1 = cairo.FORMAT_A1
64
+
65
+
66
+ #---------------------------------------------------------------------------
67
+ # Compositing operators. See http://cairographics.org/operators
68
+
69
+ # clear destination layer (bounded)
70
+ OPERATOR_CLEAR = cairo.OPERATOR_CLEAR
71
+
72
+ # replace destination layer (bounded)
73
+ OPERATOR_SOURCE = cairo.OPERATOR_SOURCE
74
+
75
+ # draw source layer on top of destination layer (bounded)
76
+ OPERATOR_OVER = cairo.OPERATOR_OVER
77
+
78
+ # draw source where there was destination content (unbounded)
79
+ OPERATOR_IN = cairo.OPERATOR_IN
80
+
81
+ # draw source where there was no destination content (unbounded)
82
+ OPERATOR_OUT = cairo.OPERATOR_OUT
83
+
84
+ # draw source on top of destination content and only there
85
+ OPERATOR_ATOP = cairo.OPERATOR_ATOP
86
+
87
+ # ignore the source
88
+ OPERATOR_DEST = cairo.OPERATOR_DEST
89
+
90
+ # draw destination on top of source
91
+ OPERATOR_DEST_OVER = cairo.OPERATOR_DEST_OVER
92
+
93
+ # leave destination only where there was source content (unbounded)
94
+ OPERATOR_DEST_IN = cairo.OPERATOR_DEST_IN
95
+
96
+ # leave destination only where there was no source content
97
+ OPERATOR_DEST_OUT = cairo.OPERATOR_DEST_OUT
98
+
99
+ # leave destination on top of source content and only there (unbounded)
100
+ OPERATOR_DEST_ATOP = cairo.OPERATOR_DEST_ATOP
101
+
102
+ # source and destination are shown where there is only one of them
103
+ OPERATOR_XOR = cairo.OPERATOR_XOR
104
+
105
+ # source and destination layers are accumulated
106
+ OPERATOR_ADD = cairo.OPERATOR_ADD
107
+
108
+ # like over, but assuming source and dest are disjoint geometries
109
+ OPERATOR_SATURATE = cairo.OPERATOR_SATURATE
110
+
111
+
112
+
113
+ #---------------------------------------------------------------------------
114
+ # Anti-alias modes. Note that according to the Cairo docs none of the
115
+ # current backends support the the SUBPIXEL mode.
116
+
117
+ # Use the default antialiasing for the subsystem and target device
118
+ ANTIALIAS_DEFAULT = cairo.ANTIALIAS_DEFAULT
119
+
120
+ # Use a bilevel alpha mask
121
+ ANTIALIAS_NONE = cairo.ANTIALIAS_NONE
122
+
123
+ # Perform single-color antialiasing (using shades of gray for black
124
+ # text on a white background, for example).
125
+ ANTIALIAS_GRAY = cairo.ANTIALIAS_GRAY
126
+
127
+ # Perform antialiasing by taking advantage of the order of subpixel
128
+ # elements on devices such as LCD panels
129
+ ANTIALIAS_SUBPIXEL = cairo.ANTIALIAS_SUBPIXEL
130
+
131
+
132
+
133
+ #---------------------------------------------------------------------------
134
+ # A decorator that makes creating properties a little cleaner and simpler
135
+
136
+ def Property( function ):
137
+ return property( **function() )
138
+
139
+ #---------------------------------------------------------------------------
140
+
141
+ # We'll just use None instead of "Null (invalid) objects"
142
+ NullGraphicsPen = None
143
+ NullGraphicsBrush = None
144
+ NullGraphicsFont = None
145
+ NullGraphicsMatrix = None
146
+ NullGraphicsPath = None
147
+
148
+
149
+ # This class probably isn't needed at all anymore since we'll just use None
150
+ # instead of the Null objects, but we'll keep it anyway in case it's needed to
151
+ # help write compatible code.
152
+ class GraphicsObject(object):
153
+ """
154
+ Base class for the other ``Graphics*`` classes.
155
+
156
+ There should be no need to use this directly, it is just here for
157
+ compatibility with :class:`wx.GraphicsObject`.
158
+ """
159
+
160
+ def IsNull(self):
161
+ """
162
+ Returns whether the object is valid.
163
+ """
164
+ return False
165
+
166
+
167
+ #---------------------------------------------------------------------------
168
+
169
+ class GraphicsPen(GraphicsObject):
170
+ """
171
+ A ``GraphicsPen`` is used to define the properties of how a stroke is drawn.
172
+
173
+ The properties and features of this class are similar to :class:`wx.Pen`,
174
+ and a :class:`wx.Pen` can be used to initialize a ``GraphicsPen`` using the
175
+ :meth:`GraphicsPen.CreateFromPen` staticmethod.
176
+ """
177
+ _capMap = { wx.CAP_BUTT : cairo.LINE_CAP_BUTT,
178
+ wx.CAP_ROUND : cairo.LINE_CAP_ROUND,
179
+ wx.CAP_PROJECTING : cairo.LINE_CAP_SQUARE }
180
+
181
+ _joinMap = { wx.JOIN_BEVEL : cairo.LINE_JOIN_BEVEL,
182
+ wx.JOIN_MITER : cairo.LINE_JOIN_MITER,
183
+ wx.JOIN_ROUND : cairo.LINE_JOIN_ROUND }
184
+
185
+
186
+ def __init__(self, colour=wx.BLACK, width=1, style=wx.SOLID):
187
+ """
188
+ Create a new ``GraphicsPen``
189
+ """
190
+ GraphicsObject.__init__(self)
191
+ self._colour = _makeColour(colour)
192
+ self._width = width
193
+ self._style = style
194
+ self._cap = wx.CAP_ROUND
195
+ self._dashes = []
196
+ self._join = wx.JOIN_ROUND
197
+ self._stipple = None
198
+ self._pattern = None
199
+
200
+
201
+ @staticmethod
202
+ def CreateFromPen(pen):
203
+ """Convert a :class:`wx.Pen` or :class:`wx.GraphicsPenInfo` to a ``GraphicsPen``"""
204
+ assert isinstance(pen, (wx.Pen, wx.GraphicsPenInfo))
205
+ p = GraphicsPen(pen.GetColour(), pen.GetWidth(), pen.GetStyle())
206
+ p._cap = pen.GetCap()
207
+ p._join = pen.GetJoin()
208
+ if isinstance(pen, wx.Pen):
209
+ # TODO: GraphicsPenInfo still needs Dashes support added.
210
+ p._dashes = pen.GetDashes()
211
+ return p
212
+
213
+
214
+ @staticmethod
215
+ def CreateFromPattern(pattern, width=1):
216
+ """
217
+ Create a ``GraphicsPen`` directly from a Cairo Pattern object.
218
+ This is similar to using a stipple bitmap, but saves a step, and
219
+ patterns can include gradients, etc.
220
+ """
221
+ p = GraphicsPen(wx.BLACK, width, wx.STIPPLE)
222
+ p._pattern = pattern
223
+ return p
224
+
225
+
226
+ @Property
227
+ def Colour():
228
+ def fget(self):
229
+ """
230
+ The color associated with this pen, to be used when drawing the line.
231
+
232
+ :type: :class:`wx.Colour`
233
+ """
234
+ return self._colour
235
+ def fset(self, value):
236
+ self._colour = value
237
+ return locals()
238
+
239
+ @Property
240
+ def Width():
241
+ def fget(self):
242
+ """
243
+ The width of the line to be drawn with this pen.
244
+
245
+ :type: int or float
246
+ """
247
+ return self._width
248
+ def fset(self, value):
249
+ self._width = value
250
+ return locals()
251
+
252
+ @Property
253
+ def Style():
254
+ def fget(self):
255
+ """
256
+ Defines the type of pen, including things like solid, dashed, stipple, etc.
257
+
258
+ :type: :ref:`wx.PenStyle`
259
+ """
260
+ return self._style
261
+ def fset(self, value):
262
+ self._style = value
263
+ return locals()
264
+
265
+ @Property
266
+ def Cap():
267
+ def fget(self):
268
+ """
269
+ The style of the end cap used when drawing with the pen.
270
+
271
+ :type: :ref:`wx.PenCap`
272
+ """
273
+ return self._cap
274
+ def fset(self, value):
275
+ self._cap = value
276
+ return locals()
277
+
278
+ @Property
279
+ def Dashes():
280
+ def fget(self):
281
+ """
282
+ Dashes is a sequence of values defining the size of line segments and blanks
283
+ to use when drawing a line.
284
+ """
285
+ return self._dashes
286
+ def fset(self, value):
287
+ self._dashes = value
288
+ return locals()
289
+
290
+ @Property
291
+ def Join():
292
+ def fget(self):
293
+ """
294
+ The pen's join style, used when drawing connected lines.
295
+
296
+ The default is ``wx.JOIN_ROUND``.
297
+
298
+ :type: :ref:`wx.PenJoin`
299
+ """
300
+ return self._join
301
+ def fset(self, value):
302
+ self._join = value
303
+ return locals()
304
+
305
+ @Property
306
+ def Stipple():
307
+ def fget(self):
308
+ """
309
+ Stipple is a bitmap to use as a pattern when drawing a line with the pen.
310
+
311
+ This will be converted to a Cairo ``Pattern`` when applied to
312
+ a :class:`GraphicsContext`.
313
+
314
+ :type: :class:`wx.Bitmap`
315
+ """
316
+ return self._stipple
317
+ def fset(self, value):
318
+ self._stipple = value
319
+ self._pattern = None
320
+ return locals()
321
+
322
+ @Property
323
+ def Pattern():
324
+ def fget(self):
325
+ """
326
+ A pattern to be used when drawing a line with the pen.
327
+
328
+ :type: Cairo ``Pattern``
329
+ """
330
+ return self._pattern
331
+ def fset(self, value):
332
+ self._pattern = value
333
+ return locals()
334
+
335
+
336
+ def Apply(self, ctx):
337
+ """
338
+ Apply this pen's properties to the given context.
339
+ Called by :class:`GraphicsContext` as needed.
340
+ """
341
+
342
+ # set up the context with this pen's parameters
343
+ ctx = ctx.GetNativeContext()
344
+ ctx.set_line_width(self._width)
345
+ ctx.set_line_cap(self._capMap[self._cap])
346
+ ctx.set_line_join(self._joinMap[self._join])
347
+ ctx.set_dash([])
348
+
349
+ if self._style == wx.SOLID:
350
+ ctx.set_source_rgba( *_colourToValues(self._colour) )
351
+
352
+ elif self._style == wx.STIPPLE:
353
+ if not self._pattern and self._stipple:
354
+ # make a pattern from the stipple bitmap
355
+ img = wxcairo.ImageSurfaceFromBitmap(self._stipple)
356
+ self._pattern = cairo.SurfacePattern(img)
357
+ self._pattern.set_extend(cairo.EXTEND_REPEAT)
358
+ ctx.set_source(self._pattern)
359
+
360
+ elif self._style == wx.USER_DASH:
361
+ ctx.set_source_rgba( *_colourToValues(self._colour) )
362
+ ctx.set_dash(self._dashes)
363
+
364
+ elif self._style in [wx.DOT, wx.DOT_DASH, wx.LONG_DASH, wx.SHORT_DASH]:
365
+ ctx.set_source_rgba( *_colourToValues(self._colour) )
366
+ ctx.set_dash( _stdDashes(self._style, self._width) )
367
+
368
+ elif self._style in [wx.BDIAGONAL_HATCH, wx.CROSSDIAG_HATCH, wx.FDIAGONAL_HATCH,
369
+ wx.CROSS_HATCH, wx.HORIZONTAL_HATCH, wx.VERTICAL_HATCH]:
370
+ pass # TODO make a stock pattern...
371
+
372
+
373
+ #---------------------------------------------------------------------------
374
+
375
+ class GraphicsBrush(GraphicsObject):
376
+ """
377
+ A ``GraphicsBrush`` is used to define how fills are painted.
378
+ They can have either a solid fill (colors with or without alpha), a
379
+ stipple created from a :class:`wx.Bitmap`, or a Cairo ``Pattern``
380
+ object.
381
+ """
382
+
383
+ def __init__(self, colour=wx.BLACK, style=wx.BRUSHSTYLE_SOLID):
384
+ """
385
+ Create a new ``GraphicsBrush``.
386
+ """
387
+ self._colour = _makeColour(colour)
388
+ self._style = style
389
+ self._stipple = None
390
+ self._pattern = None
391
+
392
+
393
+ @staticmethod
394
+ def CreateFromBrush(brush):
395
+ """
396
+ Converts a :class:`wx.Brush` to a ``GraphicsBrush``.
397
+ """
398
+ assert isinstance(brush, wx.Brush)
399
+ b = GraphicsBrush(brush.Colour, brush.Style)
400
+ if brush.Style == wx.BRUSHSTYLE_STIPPLE:
401
+ b._stipple = brush.Stipple
402
+ else:
403
+ b._stipple = None
404
+ return b
405
+
406
+
407
+ @staticmethod
408
+ def CreateFromPattern(pattern):
409
+ """
410
+ Create a ``GraphicsBrush`` directly from a Cairo ``Pattern`` object.
411
+ This is similar to using a stipple bitmap, but saves a step, and
412
+ patterns can include gradients, etc.
413
+ """
414
+ b = GraphicsBrush(style=wx.BRUSHSTYLE_STIPPLE)
415
+ b._pattern = pattern
416
+ return b
417
+
418
+
419
+ @Property
420
+ def Colour():
421
+ def fget(self):
422
+ """
423
+ The color to use when filling with the brush.
424
+
425
+ :type: :class:`wx.Colour`
426
+ """
427
+ return self._colour
428
+ def fset(self, value):
429
+ self._colour = value
430
+ return locals()
431
+
432
+ @Property
433
+ def Style():
434
+ def fget(self):
435
+ """
436
+ The style of the brush to be used when filling.
437
+ Currently, ``wx.BRUSHSTYLE_SOLID`` and ``wx.BRUSHSTYLE_STIPPLE``
438
+ are supported.
439
+
440
+ :type: :ref:`wx.BrushStyle`
441
+ """
442
+ return self._style
443
+ def fset(self, value):
444
+ self._style = value
445
+ return locals()
446
+
447
+ @Property
448
+ def Stipple():
449
+ def fget(self):
450
+ """
451
+ The Stipple is a bitmap to be used as a pattern when filling with this brush.
452
+
453
+ This will be converted to a Cairo ``Pattern`` when applied to
454
+ a :class:`GraphicsContext`.
455
+
456
+ :type: :class:`wx.Bitmap`
457
+ """
458
+ return self._stipple
459
+ def fset(self, value):
460
+ self._stipple = value
461
+ self._pattern = None
462
+ return locals()
463
+
464
+
465
+ @Property
466
+ def Pattern():
467
+ def fget(self):
468
+ """
469
+ A pattern to be used when filling with this brush.
470
+
471
+ :type: Cairo ``Pattern``
472
+ """
473
+ return self._pattern
474
+ def fset(self, value):
475
+ self._pattern = value
476
+ return locals()
477
+
478
+
479
+ def Apply(self, ctx):
480
+ """
481
+ Apply this brush's properties to the given context.
482
+ Called by :class:`GraphicsContext` as needed.
483
+ """
484
+ ctx = ctx.GetNativeContext()
485
+
486
+ if self._style == wx.BRUSHSTYLE_SOLID:
487
+ ctx.set_source_rgba( *_colourToValues(self._colour) )
488
+
489
+ elif self._style == wx.STIPPLE:
490
+ if not self._pattern and self._stipple:
491
+ # make a pattern from the stipple bitmap
492
+ img = wxcairo.ImageSurfaceFromBitmap(self._stipple)
493
+ self._pattern = cairo.SurfacePattern(img)
494
+ self._pattern.set_extend(cairo.EXTEND_REPEAT)
495
+ ctx.set_source(self._pattern)
496
+
497
+ #---------------------------------------------------------------------------
498
+
499
+ class GraphicsFont(GraphicsObject):
500
+ """
501
+ A ``GraphicsFont`` is an adapter to allow using :class:`wx.Font` with a
502
+ :class:`GraphicsContext` when drawing text.
503
+ """
504
+ def __init__(self):
505
+ """
506
+ Constructs a new ``GraphicsFont``.
507
+
508
+ .. note:: Currently user code should be using
509
+ :meth:`CreateFromFont` instead of creating new ``GraphicsFont``
510
+ instances themselves.
511
+ """
512
+ # TODO: Should we be able to create a GraphicsFont from other
513
+ # properties, or will it always be via a wx.Font? What about
514
+ # creating from a cairo.FontFace or cairo.ScaledFont?
515
+ self._font = None
516
+ self._colour = None
517
+ self._pointSize = None
518
+ self._fontface = None
519
+ # To remain consistent with the GC API a color is associated
520
+ # with the font, and nothing else. Since this is Cairo and
521
+ # it's easy to do, we'll also allow a brush to be used...
522
+ self._brush = None
523
+
524
+
525
+ def IsNull(self):
526
+ return self._font is None
527
+
528
+
529
+ @staticmethod
530
+ def CreateFromFont(font, colour=None):
531
+ """
532
+ Create a ``GraphicsFont from a :class:`wx.Font`.
533
+ Currently this is the only way to construct a ``GraphicsFont``.
534
+
535
+ :param wx.Font `font`: A ``wx.Font`` to use as a source of properties
536
+ to be used when creating the Cairo font.
537
+ :param wx.Colour `colour`: An optional colour to associate with the font.
538
+ """
539
+ f = GraphicsFont()
540
+ f._font = font
541
+ f._colour = _makeColour(colour)
542
+ f._pointSize = font.GetPointSize()
543
+ f._fontface = wxcairo.FontFaceFromFont(font)
544
+ return f
545
+
546
+
547
+ @Property
548
+ def Colour():
549
+ def fget(self):
550
+ """
551
+ The color to be associated with this font. It will be used as the
552
+ fill when drawing text with this font.
553
+
554
+ :type: :class:`wx.Colour`
555
+ """
556
+ return self._colour
557
+ def fset(self, value):
558
+ self._colour = value
559
+ return locals()
560
+
561
+
562
+ @Property
563
+ def PointSize():
564
+ def fget(self):
565
+ """
566
+ The size in points of the font.
567
+
568
+ :type: int or float
569
+ """
570
+ return self._pointSize
571
+ def fset(self, value):
572
+ self._pointSize = value
573
+ return locals()
574
+
575
+
576
+ @Property
577
+ def Brush():
578
+ def fget(self):
579
+ """
580
+ A ``GraphicsBrush`` to use for filling the text when using this
581
+ font. An alternative to using a plain colour.
582
+
583
+ :type: :class:`GraphicsBrush`
584
+ """
585
+ return self._brush
586
+ def fset(self, value):
587
+ self._brush = value
588
+ return locals()
589
+
590
+
591
+ def Apply(self, ctx, colour):
592
+ """
593
+ Apply this font's properties to the given context.
594
+ Called by :class:`GraphicsContext` as needed.
595
+ """
596
+ nctx = ctx.GetNativeContext()
597
+ if self._brush is not None:
598
+ self._brush.Apply(ctx)
599
+ else:
600
+ if colour is None: colour = wx.BLACK
601
+ nctx.set_source_rgba( *_colourToValues(colour) )
602
+ nctx.set_font_face(self._fontface)
603
+ nctx.set_font_size(self._pointSize)
604
+
605
+
606
+ #---------------------------------------------------------------------------
607
+
608
+ class GraphicsBitmap(GraphicsObject):
609
+ """
610
+ A GraphicsBitmap is a wrapper around a cairo ImageSurface. It can
611
+ be used as a source for drawing images, or as a target of drawing
612
+ operations.
613
+ """
614
+ def __init__(self, width=-1, height=-1, format=FORMAT_ARGB32):
615
+ """Create either a NULL GraphicsBitmap or an empty one if a size is given"""
616
+ self._surface = None
617
+ if width > 0 and height > 0:
618
+ self._surface = cairo.ImageSurface(format, width, height)
619
+
620
+
621
+ def IsNull(self):
622
+ return self._surface is None
623
+
624
+
625
+ @staticmethod
626
+ def CreateFromBitmap(bitmap):
627
+ """Create a GraphicsBitmap from a wx.Bitmap"""
628
+ b = GraphicsBitmap()
629
+ b._surface = wxcairo.ImageSurfaceFromBitmap(bitmap)
630
+ return b
631
+
632
+
633
+ @staticmethod
634
+ def CreateFromPNG(filename):
635
+ """Create a GraphicsBitmap from a PNG file"""
636
+ b = GraphicsBitmap()
637
+ b._surface = cairo.ImageSurface.create_from_png(filename)
638
+ return b
639
+
640
+
641
+ @staticmethod
642
+ def CreateFromSurface(surface):
643
+ """Use an existing cairo ImageSurface as a GraphicsBitmap"""
644
+ b = GraphicsBitmap()
645
+ b._surface = surface
646
+ return b
647
+
648
+
649
+ @staticmethod
650
+ def CreateFromBuffer(buffer, width, height,
651
+ format=FORMAT_ARGB32, stride=-1):
652
+ """
653
+ Creates a GraphicsBitmap that uses the given buffer object as
654
+ the pixel storage. This means that the current contents of
655
+ the buffer will be the initial state of the bitmap, and
656
+ anything drawn to this surface will be stored in the given
657
+ buffer.
658
+ """
659
+ b = GraphicsBitmap()
660
+ if stride == -1:
661
+ try:
662
+ stride = cairo.ImageSurface.format_stride_for_width(format, width)
663
+ except AttributeError:
664
+ stride = width * 4
665
+ b._surface = cairo.ImageSurface.create_for_data(
666
+ buffer, format, width, height, stride)
667
+
668
+ # save a reference to the buffer to ensure that it lives as
669
+ # long as this object does
670
+ b._buffer = buffer
671
+ return b
672
+
673
+
674
+ @Property
675
+ def Width():
676
+ def fget(self):
677
+ """The width of the bitmap and surface"""
678
+ return self._surface.get_width()
679
+ return locals()
680
+
681
+
682
+ @Property
683
+ def Height():
684
+ def fget(self):
685
+ """The height of the bitmap and surface"""
686
+ return self._surface.get_height()
687
+ return locals()
688
+
689
+
690
+ @Property
691
+ def Size():
692
+ def fget(self):
693
+ """A tuple consisting of the Width and Height"""
694
+ return (self.Width, self.Height)
695
+ return locals()
696
+
697
+
698
+ @Property
699
+ def Format():
700
+ def fget(self):
701
+ """
702
+ The type or format of the Cairo ``Surface``.
703
+ Typically ``FORMAT_ARGB32`` or ``FORMAT_RGB24``
704
+ """
705
+ return self._surface.get_format()
706
+ return locals()
707
+
708
+
709
+ @Property
710
+ def Stride():
711
+ def fget(self):
712
+ """
713
+ The "stride" of the Cairo ``Surface``, in bytes.
714
+ The stride is the distance in bytes from the beginning of one row
715
+ of the image data to the beginning of the next row.
716
+ """
717
+ return self._surface.get_stride()
718
+ return locals()
719
+
720
+
721
+ @Property
722
+ def Surface():
723
+ def fget(self):
724
+ """A reference to the Cairo ``Surface`` used for this bitmap."""
725
+ return self._surface
726
+ return locals()
727
+
728
+
729
+ def ConvertToImage(self):
730
+ """
731
+ Return the contents of this ``GraphicsBitmap`` as a :class:`wx.Image`.
732
+
733
+ Currently not implemented...
734
+ """
735
+ # TODO: implement this
736
+ return None
737
+
738
+
739
+ #---------------------------------------------------------------------------
740
+
741
+ class GraphicsMatrix(GraphicsObject):
742
+ """
743
+ A matrix holds an affine transformations, such as a scale,
744
+ rotation, shear, or a combination of these, and is used to convert
745
+ between different coordinate spaces.
746
+ """
747
+ def __init__(self):
748
+ self._matrix = cairo.Matrix()
749
+
750
+
751
+ def Set(self, a=1.0, b=0.0, c=0.0, d=1.0, tx=0.0, ty=0.0):
752
+ """Set the components of the matrix by value, default values
753
+ are the identity matrix."""
754
+ self._matrix = cairo.Matrix(a, b, c, d, tx, ty)
755
+
756
+
757
+ def Get(self):
758
+ """Return the component values of the matrix as a tuple."""
759
+ return tuple(self._matrix)
760
+
761
+
762
+ def GetNativeMatrix(self):
763
+ return self._matrix
764
+
765
+
766
+ def Concat(self, matrix) -> Self:
767
+ """Concatenates the matrix passed with the current matrix."""
768
+ self._matrix = self._matrix * matrix._matrix
769
+ return self
770
+
771
+
772
+ def Invert(self) -> Self:
773
+ """Inverts the matrix."""
774
+ self._matrix.invert()
775
+ return self
776
+
777
+
778
+ def IsEqual(self, matrix):
779
+ """Returns True if the elements of the transformation matrices are equal."""
780
+ return self._matrix == matrix._matrix
781
+
782
+
783
+ def IsIdentity(self):
784
+ """Returns True if this is the identity matrix."""
785
+ return self._matrix == cairo.Matrix()
786
+
787
+
788
+ def Rotate(self, angle) -> Self:
789
+ """Rotates the matrix in radians"""
790
+ self._matrix.rotate(angle)
791
+ return self
792
+
793
+
794
+ def Scale(self, xScale, yScale) -> Self:
795
+ """Scale the matrix"""
796
+ self._matrix.scale(xScale, yScale)
797
+ return self
798
+
799
+
800
+ def Translate(self, dx, dy) -> Self:
801
+ """Translate the matrix. This shifts the origin."""
802
+ self._matrix.translate(dx, dy)
803
+ return self
804
+
805
+
806
+ def TransformPoint(self, x, y):
807
+ """Applies this matrix to a point and returns the result"""
808
+ return self._matrix.transform_point(x, y)
809
+
810
+
811
+ def TransformDistance(self, dx, dy):
812
+ """
813
+ Applies this matrix to a distance (ie. performs all transforms
814
+ except translations.)
815
+ """
816
+ return self._matrix.transform_distance(dx, dy)
817
+
818
+
819
+ def Clone(self):
820
+ m = GraphicsMatrix()
821
+ m.Set(*self.Get())
822
+ return m
823
+
824
+ #---------------------------------------------------------------------------
825
+
826
+ class GraphicsPath(GraphicsObject):
827
+ """
828
+ A GraphicsPath is a representation of a geometric path, essentially
829
+ a collection of lines and curves. Paths can be used to define
830
+ areas to be stroked and filled on a GraphicsContext.
831
+ """
832
+ def __init__(self):
833
+ # A path is essentially just a context that we use just for
834
+ # collecting path moves, lines, and curves in order to apply
835
+ # them to the real context. So we'll use a 1x1 image surface
836
+ # for the backend, since we won't ever actually use it for
837
+ # rendering in this context.
838
+ surface = cairo.ImageSurface(FORMAT_ARGB32, 1, 1)
839
+ self._pathContext = cairo.Context(surface)
840
+
841
+
842
+ def AddArc(self, x, y, radius, startAngle, endAngle, clockwise=True) -> Self:
843
+ """
844
+ Adds an arc of a circle centering at (x,y) with radius, from
845
+ startAngle to endAngle.
846
+ """
847
+ # clockwise means positive in our system (y pointing downwards)
848
+ if clockwise or endAngle-startAngle >= 2*math.pi:
849
+ self._pathContext.arc(x, y, radius, startAngle, endAngle)
850
+ else:
851
+ self._pathContext.arc_negative(x, y, radius, startAngle, endAngle)
852
+ return self
853
+
854
+
855
+ def AddArcToPoint(self, x1, y1 , x2, y2, radius ) -> Self:
856
+ """
857
+ Adds a an arc to two tangents connecting (current) to (x1,y1)
858
+ and (x1,y1) to (x2,y2), also a straight line from (current) to
859
+ (x1,y1)
860
+ """
861
+ current = wx.Point2D(*self.GetCurrentPoint())
862
+ p1 = wx.Point2D(x1, y1)
863
+ p2 = wx.Point2D(x2, y2)
864
+
865
+ v1 = current - p1
866
+ v1.Normalize()
867
+ v2 = p2 - p1
868
+ v2.Normalize()
869
+
870
+ alpha = v1.GetVectorAngle() - v2.GetVectorAngle()
871
+ if alpha < 0:
872
+ alpha = 360 + alpha
873
+ alpha = math.radians(alpha)
874
+
875
+ dist = radius / math.sin(alpha/2) * math.cos(alpha/2)
876
+
877
+ # calculate tangential points
878
+ t1 = (v1 * dist) + p1
879
+ t2 = (v2 * dist) + p1
880
+
881
+ nv1 = wx.Point2D(*v1.Get())
882
+ nv1.SetVectorAngle(v1.GetVectorAngle() - 90)
883
+ c = t1 + nv1 * radius
884
+
885
+ a1 = v1.GetVectorAngle() + 90
886
+ a2 = v2.GetVectorAngle() - 90
887
+
888
+ self.AddLineToPoint(t1.x, t1.y)
889
+ self.AddArc(c.x, c.y, radius, math.radians(a1), math.radians(a2), True)
890
+ self.AddLineToPoint(p2.x, p2.y)
891
+ return self
892
+
893
+
894
+ def AddCircle(self, x, y, radius) -> Self:
895
+ """
896
+ Appends a new closed sub-path as a circle around (x,y).
897
+ """
898
+ self.MoveToPoint(x + radius, y)
899
+ self.AddArc( x, y, radius, 0, 2*math.pi, False)
900
+ self.CloseSubpath()
901
+ return self
902
+
903
+
904
+ def AddCurveToPoint(self, cx1, cy1, cx2, cy2, x, y) -> Self:
905
+ """
906
+ Adds a cubic Bezier curve from the current point, using two
907
+ control points and an end point.
908
+ """
909
+ self._pathContext.curve_to(cx1, cy1, cx2, cy2, x, y)
910
+ return self
911
+
912
+
913
+ def AddEllipse(self, x, y, w, h) -> Self:
914
+ """
915
+ Appends an ellipse fitting into the given rectangle as a closed sub-path.
916
+ """
917
+ rw = w / 2.0
918
+ rh = h / 2.0
919
+ xc = x + rw
920
+ yc = y + rh
921
+ m = GraphicsMatrix()
922
+ m.Translate(xc, yc)
923
+ m.Scale(rw / rh, 1.0)
924
+ p = GraphicsPath()
925
+ p.AddCircle(0,0, rh)
926
+ p.Transform(m)
927
+ self.AddPath(p)
928
+ return self
929
+
930
+
931
+ def AddLineToPoint(self, x, y) -> Self:
932
+ """
933
+ Adds a straight line from the current point to (x,y)
934
+ """
935
+ self._pathContext.line_to(x, y)
936
+ return self
937
+
938
+
939
+ def AddPath(self, path) -> Self:
940
+ """
941
+ Appends the given path to this path.
942
+ """
943
+ self._pathContext.append_path(path.GetNativePath())
944
+ return self
945
+
946
+
947
+ def AddQuadCurveToPoint(self, cx, cy, x, y) -> Self:
948
+ """
949
+ Adds a quadratic Bezier curve from the current point, using a
950
+ control point and an end point.
951
+ """
952
+ # calculate using degree elevation to a cubic bezier
953
+ start = wx.Point2D()
954
+ start.x, start.y = self.GetCurrentPoint()
955
+ end = wx.Point2D(x, y)
956
+ c = wx.Point2D(cx, cy)
957
+ c1 = start * (1/3.0) + c * (2/3.0)
958
+ c2 = c * (2/3.0) + end * (1/3.0)
959
+ self.AddCurveToPoint(c1.x, c1.y, c2.x, c2.y, x, y);
960
+ return self
961
+
962
+
963
+ def AddRectangle(self, x, y, w, h) -> Self:
964
+ """
965
+ Adds a new rectangle as a closed sub-path.
966
+ """
967
+ self._pathContext.rectangle(x, y, w, h)
968
+ return self
969
+
970
+
971
+ def AddRoundedRectangle(self, x, y, w, h, radius) -> Self:
972
+ """
973
+ Adds a new rounded rectangle as a closed sub-path.
974
+ """
975
+ if radius == 0:
976
+ self.AddRectangle(x,y,w,h)
977
+ else:
978
+ self.MoveToPoint( x + w, y + h / 2.0)
979
+ self.AddArcToPoint(x + w, y + h, x + w / 2.0, y + h, radius)
980
+ self.AddArcToPoint(x, y + h, x, y + h / 2.0, radius)
981
+ self.AddArcToPoint(x, y , x + w / 2.0, y, radius)
982
+ self.AddArcToPoint(x + w, y, x + w, y + h / 2.0, radius)
983
+ self.CloseSubpath()
984
+ return self
985
+
986
+
987
+ def CloseSubpath(self) -> Self:
988
+ """
989
+ Adds a line segment to the path from the current point to the
990
+ beginning of the current sub-path, and closes this sub-path.
991
+ """
992
+ self._pathContext.close_path()
993
+ return self
994
+
995
+
996
+ def Contains(self, x, y, fillStyle=wx.ODDEVEN_RULE):
997
+ """
998
+ Returns True if the point lies within the path.
999
+ """
1000
+ d = { wx.WINDING_RULE : cairo.FILL_RULE_WINDING,
1001
+ wx.ODDEVEN_RULE : cairo.FILL_RULE_EVEN_ODD }
1002
+ rule = d[fillStyle]
1003
+ self._pathContext.set_fill_rule(rule)
1004
+ return self._pathContext.in_stroke(x,y) or self._pathContext.in_fill(x,y)
1005
+
1006
+
1007
+ def GetCurrentPoint(self):
1008
+ """
1009
+ Gets the current point of the path, which is conceptually the
1010
+ final point reached by the last path operation.
1011
+ """
1012
+ return self._pathContext.get_current_point()
1013
+
1014
+
1015
+ def GetNativePath(self):
1016
+ """
1017
+ Returns the path as a ``cairo.Path`` object.
1018
+ """
1019
+ return self._pathContext.copy_path()
1020
+
1021
+
1022
+ def MoveToPoint(self, x, y) -> Self:
1023
+ """
1024
+ Begins a new sub-path at (x,y) by moving the "current point" there.
1025
+ """
1026
+ self._pathContext.move_to(x, y)
1027
+ return self
1028
+
1029
+
1030
+ def Transform(self, matrix) -> Self:
1031
+ """
1032
+ Transforms each point in this path by the matrix
1033
+ """
1034
+ # as we don't have a true path object, we have to apply the
1035
+ # inverse matrix to the context
1036
+ # TODO: should we clone the matrix before inverting it?
1037
+ m = matrix.GetNativeMatrix()
1038
+ m.invert()
1039
+ self._pathContext.transform(m)
1040
+ return self
1041
+
1042
+
1043
+ def Clone(self):
1044
+ """
1045
+ Return a new path initialized with the current contents of this path.
1046
+ """
1047
+ p = GraphicsPath()
1048
+ p.AddPath(self)
1049
+ return p
1050
+
1051
+
1052
+ def GetBox(self):
1053
+ """
1054
+ Return the bounding box enclosing all points on this path.
1055
+ """
1056
+ x1,y1,x2,y2 = self._pathContext.stroke_extents()
1057
+ if x2 < x1:
1058
+ x = x2
1059
+ w = x1 - x2
1060
+ else:
1061
+ x = x1
1062
+ w = x2 - x1
1063
+
1064
+ if y2 < y1:
1065
+ y = y2
1066
+ h = y1 - y2
1067
+ else:
1068
+ y = y1
1069
+ h = y2 - y1
1070
+ return (x, y, w, h)
1071
+
1072
+
1073
+ #---------------------------------------------------------------------------
1074
+
1075
+ class GraphicsGradientStop(object):
1076
+ """
1077
+ This class represents a single color-stop in a gradient brush. The
1078
+ position is a floating point value between zero and 1.0 which represents
1079
+ the distance between the gradient's starting point and ending point.
1080
+ """
1081
+ def __init__(self, colour=wx.TransparentColour, pos=0.0):
1082
+ self.SetColour(colour)
1083
+ self.SetPosition(pos)
1084
+
1085
+ def GetColour(self):
1086
+ return self._colour
1087
+ def SetColour(self, value):
1088
+ value = _makeColour(value)
1089
+ assert isinstance(value, wx.Colour)
1090
+ self._colour = value
1091
+ Colour = property(GetColour, SetColour)
1092
+
1093
+
1094
+ def GetPosition(self):
1095
+ return self._pos
1096
+ def SetPosition(self, value):
1097
+ assert value >= 0.0 and value <= 1.0
1098
+ self._pos = value
1099
+ Position = property(GetPosition, SetPosition)
1100
+
1101
+
1102
+
1103
+ class GraphicsGradientStops(object):
1104
+ """
1105
+ An ordered collection of gradient color stops
1106
+ (i.e. a :class:`GraphicsGradientStop`) for a gradient brush. There is
1107
+ always at least the starting stop and the ending stop in the collection.
1108
+ """
1109
+ def __init__(self, startColour=wx.TransparentColour,
1110
+ endColour=wx.TransparentColour):
1111
+ self._stops = list()
1112
+ self.Add(startColour, 0.0)
1113
+ self.Add(endColour, 1.0)
1114
+
1115
+
1116
+ def Add(self, *args):
1117
+ """
1118
+ Add a new color to the collection. ``args`` may be either a gradient stop,
1119
+ or a colour and position.
1120
+ """
1121
+ if len(args) == 2:
1122
+ col, pos = args
1123
+ stop = GraphicsGradientStop(col, pos)
1124
+ elif len(args) == 1:
1125
+ stop = args[0]
1126
+ else:
1127
+ raise ValueError("Invalid parameters passed to Add")
1128
+ assert isinstance(stop, GraphicsGradientStop)
1129
+
1130
+ self._stops.append(stop)
1131
+ self._stops.sort(key=lambda x: x.Position)
1132
+
1133
+
1134
+ def GetCount(self):
1135
+ return len(self._stops)
1136
+ Count = property(GetCount)
1137
+ def __len__(self):
1138
+ return self.GetCount()
1139
+
1140
+
1141
+ def Item(self, n):
1142
+ return self._stops[n]
1143
+ def __getitem__(self, n):
1144
+ return self._stops[n]
1145
+
1146
+
1147
+ def GetStartColour(self):
1148
+ return self._stops[0].Colour
1149
+ def SetStartColour(self, col):
1150
+ self._stops[0].Colour = col
1151
+ StartColour = property(GetStartColour, SetStartColour)
1152
+
1153
+
1154
+ def GetEndColour(self):
1155
+ return self._stops[-1].Colour
1156
+ def SetEndColour(self, col):
1157
+ self._stops[-1].Colour = col
1158
+ EndColour = property(GetEndColour, SetEndColour)
1159
+
1160
+
1161
+ #---------------------------------------------------------------------------
1162
+
1163
+ class GraphicsContext(GraphicsObject):
1164
+ """
1165
+ The GraphicsContext is the object which facilitates drawing to a surface.
1166
+ """
1167
+ def __init__(self, context=None, size=None):
1168
+ """
1169
+ Create a new Context.
1170
+ Normally you should use one of the ``"Create"`` static methods.
1171
+ """
1172
+ self._context = context
1173
+ self._pen = None
1174
+ self._brush = None
1175
+ self._font = None
1176
+ self._fontColour = None
1177
+ self._layerOpacities = []
1178
+ self._width = 10000.0
1179
+ self._height = 10000.0
1180
+ if size is not None:
1181
+ self._width, self._height = size
1182
+
1183
+
1184
+ def IsNull(self):
1185
+ return self._context is None
1186
+
1187
+
1188
+ @staticmethod
1189
+ def Create(dc=None):
1190
+ """
1191
+ Create a new ``GraphicsContext``.
1192
+ Passing ``None`` will create a context suitable for measuring.
1193
+
1194
+ :param dc: ``None`` or a compatible :class:`wx.DC`
1195
+ """
1196
+ # TODO: Support creating directly from a wx.Window too.
1197
+ if dc is None:
1198
+ return GraphicsContext.CreateMeasuringContext()
1199
+
1200
+ assert isinstance(dc, wx.DC)
1201
+ ctx = wxcairo.ContextFromDC(dc)
1202
+ return GraphicsContext(ctx, dc.GetSize())
1203
+
1204
+
1205
+ @staticmethod
1206
+ def CreateFromNative(cairoContext):
1207
+ """Create a context from an existing cairo Context"""
1208
+ return GraphicsContext(cairoContext)
1209
+
1210
+
1211
+ @staticmethod
1212
+ def CreateMeasuringContext():
1213
+ """
1214
+ If you need a temporary context just to quickly measure some
1215
+ text extents, or etc. then using this function will be a
1216
+ little less expensive than creating a real DC for it.
1217
+ """
1218
+ surface = cairo.ImageSurface(FORMAT_ARGB32, 1, 1)
1219
+ ctx = cairo.Context(surface)
1220
+ return GraphicsContext(ctx,
1221
+ (surface.get_width(), surface.get_height()))
1222
+
1223
+
1224
+ @staticmethod
1225
+ def CreateFromSurface(surface):
1226
+ """
1227
+ Wrap a context around the given cairo Surface.
1228
+ Note that a :class:`GraphicsBitmap` contains a cairo ``ImageSurface``
1229
+ which is accessible via the ``Surface`` property.
1230
+ """
1231
+ return GraphicsContext(cairo.Context(surface),
1232
+ (surface.get_width(), surface.get_height()))
1233
+
1234
+ @staticmethod
1235
+ def CreateFromImage(image):
1236
+ """
1237
+ Create a GraphicsContext associated with a :class:`wx.Image`.
1238
+
1239
+ The image specifies the size of the context as well as whether alpha is
1240
+ supported (if :meth:`wx.Image.HasAlpha()`) or not and the initial contents of
1241
+ the context. The image object must have a life time greater than
1242
+ that of the new context as the context copies its contents back to the
1243
+ image when it is destroyed.
1244
+
1245
+ Not implemented yet...
1246
+ """
1247
+ # TODO: implement this
1248
+ raise NotImplementedError
1249
+
1250
+ @Property
1251
+ def Context():
1252
+ def fget(self):
1253
+ """A reference to the Cairo Context"""
1254
+ return self._context
1255
+ return locals()
1256
+
1257
+
1258
+ # Our implementation is able to create these things directly, but
1259
+ # we'll keep them here too for compatibility with wx.GraphicsContext.
1260
+
1261
+ def CreateBrush(self, brush):
1262
+ """
1263
+ Create a brush from a :class:`wx.Brush`.
1264
+ """
1265
+ return GraphicsBrush.CreateFromBrush(brush)
1266
+
1267
+ def CreateFont(self, font, colour=None):
1268
+ """
1269
+ Create a font from a :class:`wx.Font`
1270
+ """
1271
+ return GraphicsFont.CreateFromFont(font, colour)
1272
+
1273
+
1274
+ def CreateLinearGradientBrush(self, x1, y1, x2, y2, *args):
1275
+ """
1276
+ Creates a native brush having a linear gradient, starting at (x1,y1)
1277
+ to (x2,y2) with the given boundary colors or the specified stops.
1278
+
1279
+ The `*args` can be either a :class:`GraphicsGradientStops` or just
1280
+ two colours to be used as the starting and ending gradient colours.
1281
+ """
1282
+ if len(args) == 1:
1283
+ stops = args[0]
1284
+ elif len(args) == 2:
1285
+ c1 = _makeColour(c1)
1286
+ c2 = _makeColour(c2)
1287
+ stops = GraphicsGradientStops(c1, c2)
1288
+ else:
1289
+ raise ValueError("Invalid args passed to CreateLinearGradientBrush")
1290
+
1291
+ pattern = cairo.LinearGradient(x1, y1, x2, y2)
1292
+ for stop in stops:
1293
+ pattern.add_color_stop_rgba(stop.Position, *_colourToValues(stop.Colour))
1294
+ return GraphicsBrush.CreateFromPattern(pattern)
1295
+
1296
+
1297
+ def CreateRadialGradientBrush(self, xo, yo, xc, yc, radius, *args):
1298
+ """
1299
+ Creates a native brush, having a radial gradient originating at point
1300
+ (xo,yo) and ending on a circle around (xc,yc) with the given radius;
1301
+ the colours may be specified by just the two extremes or the full
1302
+ array of gradient stops.
1303
+
1304
+ The `*args` can be either a :class:`GraphicsGradientStops` or just two
1305
+ colours to be used as the starting and ending gradient colours.
1306
+ """
1307
+ if len(args) ==1:
1308
+ stops = args[0]
1309
+ elif len(args) == 2:
1310
+ oColour = _makeColour(oColour)
1311
+ cColour = _makeColour(cColour)
1312
+ stops = GraphicsGradientStops(oColour, cColour)
1313
+ else:
1314
+ raise ValueError("Invalid args passed to CreateLinearGradientBrush")
1315
+
1316
+ pattern = cairo.RadialGradient(xo, yo, 0.0, xc, yc, radius)
1317
+ for stop in stops:
1318
+ pattern.add_color_stop_rgba(stop.Position, *_colourToValues(stop.Colour))
1319
+ return GraphicsBrush.CreateFromPattern(pattern)
1320
+
1321
+
1322
+ def CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0):
1323
+ """
1324
+ Create a new matrix object.
1325
+ """
1326
+ m = GraphicsMatrix()
1327
+ m.Set(a, b, c, d, tx, ty)
1328
+ return m
1329
+
1330
+ def CreatePath(self):
1331
+ """
1332
+ Create a new path object.
1333
+ """
1334
+ return GraphicsPath()
1335
+
1336
+ def CreatePen(self, pen):
1337
+ """
1338
+ Create a new pen from a wx.Pen or a wx.GraphicsPenInfo.
1339
+ """
1340
+ return GraphicsPen.CreateFromPen(pen)
1341
+
1342
+
1343
+ def PushState(self):
1344
+ """
1345
+ Makes a copy of the current state of the context (ie the
1346
+ transformation matrix) and saves it on an internal stack of saved
1347
+ states. The saved state will be restored when meth:`PopState` is
1348
+ called.
1349
+ """
1350
+ self._context.save()
1351
+
1352
+
1353
+ def PopState(self):
1354
+ """
1355
+ Restore the most recently saved state which was saved with
1356
+ :meth:`PushState`.
1357
+ """
1358
+ self._context.restore()
1359
+
1360
+
1361
+ def Clip(self, x, y, w, h):
1362
+ """
1363
+ Adds the rectangle to the current clipping region. The
1364
+ clipping region causes drawing operations to be limited to the
1365
+ clipped areas of the context.
1366
+ """
1367
+ p = GraphicsPath()
1368
+ p.AddRectangle(x, y, w, h)
1369
+ self._context.append_path(p.GetNativePath())
1370
+ self._context.clip()
1371
+
1372
+
1373
+ def ClipRegion(self, region):
1374
+ """
1375
+ Adds the :class:`wx.Region` to the current clipping region.
1376
+ """
1377
+ p = GraphicsPath()
1378
+ ri = wx.RegionIterator(region)
1379
+ while ri:
1380
+ rect = ri.GetRect()
1381
+ p.AddRectangle( *rect )
1382
+ ri.Next()
1383
+ self._context.append_path(p.GetNativePath())
1384
+ self._context.clip()
1385
+
1386
+
1387
+ def ResetClip(self):
1388
+ """
1389
+ Resets the clipping region to the original shape of the context.
1390
+ """
1391
+ self._context.reset_clip()
1392
+
1393
+
1394
+ def GetNativeContext(self):
1395
+ return self._context
1396
+
1397
+
1398
+ def GetLogicalFunction(self):
1399
+ """
1400
+ Not implemented.
1401
+ Since DC logical functions are conceptually different than compositing
1402
+ operators don't pretend they are the same thing, or try to implement
1403
+ them using the compositing operators.
1404
+ """
1405
+ raise NotImplementedError("See GetCompositingOperator")
1406
+ def SetLogicalFunction(self, function):
1407
+ """Not implemented."""
1408
+ raise NotImplementedError("See SetCompositingOperator")
1409
+ LogicalFunction = property(GetLogicalFunction, SetLogicalFunction)
1410
+
1411
+
1412
+ def Translate(self, dx, dy):
1413
+ """
1414
+ Modifies the current transformation matrix by translating the
1415
+ user-space origin by (dx, dy).
1416
+ """
1417
+ self._context.translate(dx, dy)
1418
+
1419
+
1420
+ def Scale(self, xScale, yScale):
1421
+ """
1422
+ Modifies the current transformation matrix by translating the
1423
+ user-space axes by xScale and yScale.
1424
+ """
1425
+ self._context.scale(xScale, yScale)
1426
+
1427
+
1428
+ def Rotate(self, angle):
1429
+ """
1430
+ Modifies the current transformation matrix by rotating the
1431
+ user-space axes by angle radians.
1432
+ """
1433
+ self._context.rotate(angle)
1434
+
1435
+
1436
+ def ConcatTransform(self, matrix):
1437
+ """
1438
+ Modifies the current transformation matrix by applying matrix
1439
+ as an additional transformation.
1440
+ """
1441
+ self._context.transform(matrix.GetNativeMatrix())
1442
+
1443
+
1444
+ def SetTransform(self, matrix):
1445
+ """
1446
+ Set the context's current transformation matrix to matrix.
1447
+ """
1448
+ self._context.set_matrix(matrix.GetNativeMatrix())
1449
+
1450
+
1451
+ def GetTransform(self):
1452
+ """
1453
+ Returns the context's current transformation matrix.
1454
+ """
1455
+ gm = GraphicsMatrix()
1456
+ gm.Set( *tuple(self._context.get_matrix()) )
1457
+ return gm
1458
+ Transform = property(GetTransform, SetTransform)
1459
+
1460
+
1461
+ def SetPen(self, pen):
1462
+ """
1463
+ Set the pen to be used for stroking lines in future drawing
1464
+ operations. Either a :class:`wx.Pen` or a :class:`GraphicsPen`
1465
+ object may be used.
1466
+ """
1467
+ if isinstance(pen, wx.Pen):
1468
+ if not pen.IsOk() or pen.Style == wx.TRANSPARENT:
1469
+ pen = None
1470
+ else:
1471
+ pen = GraphicsPen.CreateFromPen(pen)
1472
+ self._pen = pen
1473
+
1474
+ def GetPen(self):
1475
+ """Returns the current pen."""
1476
+ return self._pen
1477
+ Pen = property(GetPen, SetPen)
1478
+
1479
+
1480
+ def SetBrush(self, brush):
1481
+ """
1482
+ Set the brush to be used for filling shapes in future drawing
1483
+ operations. Either a :class:`wx.Brush` or a :class:`GraphicsBrush`
1484
+ object may be used.
1485
+ """
1486
+ if isinstance(brush, wx.Brush):
1487
+ if not brush.IsOk() or brush.Style == wx.TRANSPARENT:
1488
+ brush = None
1489
+ else:
1490
+ brush = GraphicsBrush.CreateFromBrush(brush)
1491
+ self._brush = brush
1492
+
1493
+ def GetBrush(self):
1494
+ """Returns the current brush"""
1495
+ return self._brush
1496
+ Brush = property(GetBrush, SetBrush)
1497
+
1498
+
1499
+ def SetFont(self, font, colour=None):
1500
+ """
1501
+ Sets the font to be used for drawing text. Either a :class:`wx.Font`
1502
+ or a :class:`GraphicsFont` may be used.
1503
+ """
1504
+ if isinstance(font, wx.Font):
1505
+ font = GraphicsFont.CreateFromFont(font, colour)
1506
+ self._font = font
1507
+ if colour is not None:
1508
+ self._fontColour = _makeColour(colour)
1509
+ else:
1510
+ self._fontColour = font._colour
1511
+
1512
+ def GetFont(self): return (self._font, self._fontColour)
1513
+ def _SetFont(self, *both): self.SetFont(*both)
1514
+ Font = property(GetFont, _SetFont)
1515
+
1516
+
1517
+ def StrokePath(self, path):
1518
+ """
1519
+ Strokes the path (draws the lines) using the current pen.
1520
+ """
1521
+ if self._pen:
1522
+ offset = _OffsetHelper(self)
1523
+ self._context.append_path(path.GetNativePath())
1524
+ self._pen.Apply(self)
1525
+ self._context.stroke()
1526
+
1527
+
1528
+ def FillPath(self, path, fillStyle=wx.ODDEVEN_RULE):
1529
+ """
1530
+ Fills the path using the current brush.
1531
+ """
1532
+ if self._brush:
1533
+ offset = _OffsetHelper(self)
1534
+ self._context.append_path(path.GetNativePath())
1535
+ self._brush.Apply(self)
1536
+ d = { wx.WINDING_RULE : cairo.FILL_RULE_WINDING,
1537
+ wx.ODDEVEN_RULE : cairo.FILL_RULE_EVEN_ODD }
1538
+ rule = d[fillStyle]
1539
+ self._context.set_fill_rule(rule)
1540
+ self._context.fill()
1541
+
1542
+
1543
+ def DrawPath(self, path, fillStyle=wx.ODDEVEN_RULE):
1544
+ """
1545
+ Draws the path by first filling it and then stroking it.
1546
+ """
1547
+ # TODO: this could be optimized by moving the stroke and fill
1548
+ # code here and only loading the path once.
1549
+ self.FillPath(path, fillStyle)
1550
+ self.StrokePath(path)
1551
+
1552
+
1553
+ def DrawText(self, text, x, y, backgroundBrush=None):
1554
+ """
1555
+ Draw the text at (x,y) using the current font. If
1556
+ backgroundBrush is set then it is used to fill the rectangle
1557
+ behind the text.
1558
+ """
1559
+ if backgroundBrush:
1560
+ formerBrush = self._brush
1561
+ formerPen = self._pen
1562
+ self.SetBrush(backgroundBrush)
1563
+ self.SetPen(None)
1564
+ width, height = self.GetTextExtent(text)
1565
+ path = GraphicsPath()
1566
+ path.AddRectangle(x, y, width, height)
1567
+ self.FillPath(path)
1568
+ self._DrawText(text, x, y)
1569
+ self.SetBrush(formerBrush)
1570
+ self.SetPen(formerPen)
1571
+
1572
+ else:
1573
+ self._DrawText(text, x, y)
1574
+
1575
+
1576
+ def _DrawText(self, text, x, y, angle=None):
1577
+ """helper used by DrawText and DrawRotatedText"""
1578
+ if angle is not None:
1579
+ self.PushState()
1580
+ self.Translate(x, y)
1581
+ self.Rotate(-angle)
1582
+ x = y = 0
1583
+
1584
+ self._font.Apply(self, self._fontColour)
1585
+ # Cairo's x,y for drawing text is at the baseline, so we need to adjust
1586
+ # the position we move to by the ascent.
1587
+ fe = self._context.font_extents()
1588
+ ascent = fe[0]
1589
+ self._context.move_to( x, y + ascent )
1590
+ self._context.show_text(text)
1591
+
1592
+ if angle is not None:
1593
+ self.PopState()
1594
+
1595
+
1596
+ def DrawRotatedText(self, text, x, y, angle, backgroundBrush=None):
1597
+ """
1598
+ Draw the text at (x,y) using the current font and rotated
1599
+ angle radians. If backgroundBrush is set then it is used to
1600
+ fill the rectangle behind the text.
1601
+ """
1602
+ if backgroundBrush:
1603
+ formerBrush = self._brush
1604
+ formerPen = self._pen
1605
+ self.SetBrush(backgroundBrush)
1606
+ self.SetPen(None)
1607
+ width, height = self.GetTextExtent(text)
1608
+ path = GraphicsPath()
1609
+ path.AddRectangle(0, 0, width, height)
1610
+ self.PushState()
1611
+ self.Translate(x, y)
1612
+ self.Rotate(-angle)
1613
+ self.FillPath(path)
1614
+ self.PopState()
1615
+ self._DrawText(text, x, y, angle)
1616
+ self.SetBrush(formerBrush)
1617
+ self.SetPen(formerPen)
1618
+
1619
+ else:
1620
+ self._DrawText(text, x, y, angle)
1621
+
1622
+
1623
+ def GetFullTextExtent(self, text):
1624
+ """
1625
+ Returns the (width, height, descent, externalLeading) of the
1626
+ text using the current font.
1627
+ """
1628
+ if not text:
1629
+ return (0,0,0,0)
1630
+
1631
+ self._font.Apply(self, self._fontColour)
1632
+
1633
+ te = self._context.text_extents(text)
1634
+ width = te[2]
1635
+
1636
+ fe = self._context.font_extents()
1637
+ height = fe[2]
1638
+ descent = fe[1]
1639
+ ascent = fe[0]
1640
+ externalLeading = max(0, height - (ascent + descent))
1641
+
1642
+ return (width, height, descent, externalLeading)
1643
+
1644
+
1645
+ def GetTextExtent(self, text):
1646
+ """
1647
+ Returns the (width, height) of the text using the current
1648
+ font.
1649
+ """
1650
+ (width, height, descent, externalLeading) = self.GetFullTextExtent(text)
1651
+ return (width, height)
1652
+
1653
+
1654
+ def GetPartialTextExtents(self, text):
1655
+ raise NotImplementedError("TODO")
1656
+
1657
+
1658
+ def DrawBitmap(self, bmp, x, y, w=-1, h=-1):
1659
+ """
1660
+ Draw the bitmap at (x,y). If the width and height parameters
1661
+ are passed then the bitmap is scaled to fit that size. Either
1662
+ a :class:`wx.Bitmap` or a :class:`GraphicsBitmap` may be used.
1663
+ """
1664
+ if isinstance(bmp, wx.Bitmap):
1665
+ bmp = GraphicsBitmap.CreateFromBitmap(bmp)
1666
+
1667
+ # In case we're scaling the image by using a width and height
1668
+ # different than the bitmap's size, create a pattern
1669
+ # transformation on the surface and draw the transformed
1670
+ # pattern.
1671
+ self.PushState()
1672
+ pattern = cairo.SurfacePattern(bmp.Surface)
1673
+
1674
+ bw, bh = bmp.Size
1675
+ if w == -1: w = bw
1676
+ if h == -1: h = bh
1677
+ scaleX = w / float(bw)
1678
+ scaleY = h / float(bh)
1679
+
1680
+ self._context.translate(x, y)
1681
+ self._context.scale(scaleX, scaleY)
1682
+ self._context.set_source(pattern)
1683
+
1684
+ # use the original size here since the context is scaled already...
1685
+ self._context.rectangle(0, 0, bw, bh)
1686
+ # fill the rectangle with the pattern
1687
+ self._context.fill()
1688
+
1689
+ self.PopState()
1690
+
1691
+
1692
+ def DrawIcon(self, icon, x, y, w=-1, h=-1):
1693
+ raise NotImplementedError("TODO")
1694
+
1695
+
1696
+ def StrokeLine(self, x1, y1, x2, y2):
1697
+ """
1698
+ Strokes a single line using the current pen.
1699
+ """
1700
+ path = GraphicsPath()
1701
+ path.MoveToPoint(x1, y1)
1702
+ path.AddLineToPoint(x2, y2)
1703
+ self.StrokePath(path)
1704
+
1705
+
1706
+ def StrokeLines(self, points):
1707
+ """
1708
+ Stroke a series of connected lines using the current pen.
1709
+ Points is a sequence of points or 2-tuples, and lines are
1710
+ drawn from point to point through the end of the sequence.
1711
+ """
1712
+ path = GraphicsPath()
1713
+ x, y = points[0]
1714
+ path.MoveToPoint(x, y)
1715
+ for point in points[1:]:
1716
+ x, y = point
1717
+ path.AddLineToPoint(x, y)
1718
+ self.StrokePath(path)
1719
+
1720
+
1721
+ def StrokeLineSegments(self, beginPoints, endPoints):
1722
+ """
1723
+ Stroke a series of lines using the current pen. For each line
1724
+ the begin point is taken from the beginPoints sequence and the
1725
+ ending point is taken from the endPoints sequence.
1726
+ """
1727
+ path = GraphicsPath()
1728
+ for begin, end in zip(beginPoints, endPoints):
1729
+ path.MoveToPoint(begin[0], begin[1])
1730
+ path.AddLineToPoint(end[0], end[1])
1731
+ self.StrokePath(path)
1732
+
1733
+
1734
+ def DrawLines(self, points, fillStyle=wx.ODDEVEN_RULE):
1735
+ """
1736
+ Stroke and fill a series of connected lines using the current
1737
+ pen and current brush.
1738
+ """
1739
+ path = GraphicsPath()
1740
+ x, y = points[0]
1741
+ path.MoveToPoint(x, y)
1742
+ for point in points[1:]:
1743
+ x, y = point
1744
+ path.AddLineToPoint(x, y)
1745
+ self.DrawPath(path, fillStyle)
1746
+
1747
+
1748
+ def DrawRectangle(self, x, y, w, h):
1749
+ """
1750
+ Stroke and fill a rectangle using the current pen and current
1751
+ brush.
1752
+ """
1753
+ path = GraphicsPath()
1754
+ path.AddRectangle(x, y, w, h)
1755
+ self.DrawPath(path)
1756
+
1757
+
1758
+ def DrawEllipse(self, x, y, w, h):
1759
+ """
1760
+ Stroke and fill an ellipse that fits in the given rectangle,
1761
+ using the current pen and current brush.
1762
+ """
1763
+ path = GraphicsPath()
1764
+ path.AddEllipse(x, y, w, h)
1765
+ self.DrawPath(path)
1766
+
1767
+
1768
+ def DrawRoundedRectangle(self, x, y, w, h, radius):
1769
+ """
1770
+ Stroke and fill a rounded rectangle using the current pen and
1771
+ current brush.
1772
+ """
1773
+ path = GraphicsPath()
1774
+ path.AddRoundedRectangle(x, y, w, h, radius)
1775
+ self.DrawPath(path)
1776
+
1777
+
1778
+
1779
+ def GetCompositingOperator(self):
1780
+ """
1781
+ Returns the current compositing operator for the context.
1782
+ """
1783
+ return self._context.get_operator()
1784
+
1785
+
1786
+ def SetCompositingOperator(self, op):
1787
+ """
1788
+ Sets the compositing operator to be used for all drawing
1789
+ operations. The default operator is OPERATOR_OVER.
1790
+ """
1791
+ return self._context.set_operator(op)
1792
+
1793
+ CompositingOperator = property(GetCompositingOperator, SetCompositingOperator)
1794
+
1795
+
1796
+ def GetAntialiasMode(self):
1797
+ """
1798
+ Returns the current antialias mode.
1799
+ """
1800
+ return self._context.get_antialias()
1801
+
1802
+ def SetAntialiasMode(self, mode=ANTIALIAS_DEFAULT):
1803
+ """
1804
+ Set the antialiasing mode of the rasterizer used for drawing
1805
+ shapes. This value is a hint, and a particular backend may or
1806
+ may not support a particular value.
1807
+ """
1808
+ self._context.set_antialias(mode)
1809
+
1810
+ AntialiasMode = property(GetAntialiasMode, GetAntialiasMode)
1811
+
1812
+
1813
+ def BeginLayer(self, opacity):
1814
+ """
1815
+ Redirects future rendering to a temporary context. See :meth:`EndLayer`.
1816
+ """
1817
+ self._layerOpacities.append(opacity)
1818
+ self._context.push_group()
1819
+
1820
+
1821
+ def EndLayer(self):
1822
+ """
1823
+ Composites the drawing done on the temporary context created
1824
+ in :meth:`BeginLayer` back into the main context, using the opacity
1825
+ specified for the layer.
1826
+ """
1827
+ opacity = self._layerOpacities.pop()
1828
+ self._context.pop_group_to_source()
1829
+ self._context.paint_with_alpha(opacity)
1830
+
1831
+
1832
+ def Flush(self):
1833
+ pass
1834
+
1835
+
1836
+ def GetSize(self):
1837
+ return (self._width, self._height)
1838
+ Size = property(GetSize)
1839
+
1840
+
1841
+ # Some things not in wx.GraphicsContext (yet)
1842
+
1843
+ def DrawCircle(self, x, y, radius):
1844
+ """
1845
+ Stroke and fill a circle centered at (x,y) with the given
1846
+ radius, using the current pen and brush.
1847
+ """
1848
+ path = GraphicsPath()
1849
+ path.AddCircle(x, y, radius)
1850
+ self.DrawPath(path)
1851
+
1852
+
1853
+ def ClipPath(self, path):
1854
+ """
1855
+ Set the clip region to the path.
1856
+ """
1857
+ self._context.append_path(path.GetNativePath())
1858
+ self._context.clip()
1859
+
1860
+
1861
+ def Clear(self, colour=None):
1862
+ """
1863
+ Clear the context using the given color or the currently set brush.
1864
+ """
1865
+ if colour is not None:
1866
+ brush = GraphicsBrush(colour)
1867
+ elif self._brush is None:
1868
+ brush = GraphicsBrush(wx.WHITE)
1869
+ else:
1870
+ brush = self._brush
1871
+
1872
+ self.PushState()
1873
+ op = self._context.get_operator()
1874
+ self._context.set_operator(cairo.OPERATOR_SOURCE)
1875
+ self._context.reset_clip()
1876
+
1877
+ brush.Apply(self)
1878
+ self._context.paint()
1879
+
1880
+ self._context.set_operator(op)
1881
+ self.PopState()
1882
+
1883
+
1884
+ #---------------------------------------------------------------------------
1885
+ # Utility functions
1886
+
1887
+ def _makeColour(colour):
1888
+ """
1889
+ Helper which makes a wx.Colour from any of the allowed typemaps (string,
1890
+ tuple, etc.)
1891
+ """
1892
+ if isinstance(colour, (str, tuple)):
1893
+ return wx.NamedColour(colour)
1894
+ else:
1895
+ return colour
1896
+
1897
+
1898
+ def _colourToValues(c):
1899
+ """
1900
+ Helper which converts wx.Colour components to a set of values between 0 and 1
1901
+ """
1902
+ return tuple( [x/255.0 for x in c.Get(True)] )
1903
+
1904
+
1905
+ class _OffsetHelper(object):
1906
+ """A helper used by the context class."""
1907
+ def __init__(self, ctx):
1908
+ self.ctx = ctx
1909
+ self.offset = 0
1910
+ if ctx._pen:
1911
+ penwidth = ctx._pen.Width
1912
+ if penwidth == 0:
1913
+ penwidth = 1
1914
+ self.offset = (penwidth % 2) == 1;
1915
+ if self.offset:
1916
+ ctx.Translate(0.5, 0.5)
1917
+
1918
+ def __del__(self):
1919
+ if self.offset:
1920
+ self.ctx.Translate(-0.5, -0.5)
1921
+
1922
+
1923
+ def _stdDashes(style, width):
1924
+ """
1925
+ Helper which defines the dash patterns for the standard dash styles.
1926
+ """
1927
+ if width < 1.0:
1928
+ width = 1.0
1929
+
1930
+ if style == wx.DOT:
1931
+ dashes = [ width, width + 2.0]
1932
+ elif style == wx.DOT_DASH:
1933
+ dashes = [ 9.0, 6.0, 3.0, 3.0 ]
1934
+ elif style == wx.LONG_DASH:
1935
+ dashes = [ 19.0, 9.0 ]
1936
+ elif style == wx.SHORT_DASH:
1937
+ dashes = [ 9.0, 6.0 ]
1938
+
1939
+ return dashes
1940
+
1941
+
1942
+ #---------------------------------------------------------------------------