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
@@ -0,0 +1,2910 @@
1
+ #----------------------------------------------------------------------------
2
+ # Name: FCObjects.py
3
+ # Purpose: Contains all the drawing objects FloatCanvas supports
4
+ #
5
+ # Author:
6
+ #
7
+ # Created:
8
+ # Version:
9
+ # Date:
10
+ # Licence:
11
+ # Tags: phoenix-port, unittest, documented, py3-port
12
+ #----------------------------------------------------------------------------
13
+ """
14
+ This is where FloatCanvas defines its drawing objects.
15
+ """
16
+
17
+ import sys
18
+
19
+ import wx
20
+
21
+ import numpy as np
22
+
23
+ from .Utilities import BBox
24
+ from wx.lib.floatcanvas.Utilities import Colors
25
+
26
+ mac = sys.platform.startswith("darwin")
27
+
28
+ ## A global variable to hold the Pixels per inch that wxWindows thinks is in use
29
+ ## This is used for scaling fonts.
30
+ ## This can't be computed on module __init__, because a wx.App might not have initialized yet.
31
+ global FontScale
32
+
33
+
34
+ def ComputeFontScale():
35
+ """
36
+ Compute the font scale.
37
+
38
+ A global variable to hold the scaling from pixel size to point size.
39
+ """
40
+ global FontScale
41
+ dc = wx.ScreenDC()
42
+ dc.SetFont(wx.Font(16, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
43
+ E = dc.GetTextExtent("X")
44
+ FontScale = 16/E[1]
45
+ del dc
46
+
47
+ # why do we do this here, causes a Sphinx build crash
48
+ #ComputeFontScale()
49
+
50
+ ## fixme: This should probably be re-factored into a class
51
+ _testBitmap = None
52
+
53
+ def _cycleidxs(indexcount, maxvalue, step):
54
+
55
+ """
56
+ Utility function used by _colorGenerator
57
+ """
58
+ def colormatch(color):
59
+ """Return True if the color comes back from the bitmap identically."""
60
+ if len(color) < 3:
61
+ return True
62
+ global _testBitmap
63
+ dc = wx.MemoryDC()
64
+ if not _testBitmap:
65
+ _testBitmap = wx.Bitmap(1, 1)
66
+ dc.SelectObject(_testBitmap)
67
+ dc.SetBackground(wx.BLACK_BRUSH)
68
+ dc.Clear()
69
+ dc.SetPen(wx.Pen(wx.Colour(*color), 4))
70
+ dc.DrawPoint(0,0)
71
+ if mac: # NOTE: can the Mac not just use the DC?
72
+ del dc # Mac can't work with bitmap when selected into a DC.
73
+ pdata = wx.AlphaPixelData(_testBitmap)
74
+ pacc = pdata.GetPixels()
75
+ pacc.MoveTo(pdata, 0, 0)
76
+ outcolor = pacc.Get()[:3]
77
+ else:
78
+ outcolor = dc.GetPixel(0,0)
79
+ return outcolor == color
80
+
81
+ if indexcount == 0:
82
+ yield ()
83
+ else:
84
+ for idx in range(0, maxvalue, step):
85
+ for tail in _cycleidxs(indexcount - 1, maxvalue, step):
86
+ color = (idx, ) + tail
87
+ if not colormatch(color):
88
+ continue
89
+ yield color
90
+
91
+
92
+ def _colorGenerator():
93
+
94
+ """
95
+ Generates a series of unique colors used to do hit-tests with the Hit
96
+ Test bitmap
97
+ """
98
+ return _cycleidxs(indexcount=3, maxvalue=256, step=1)
99
+
100
+
101
+ class DrawObject:
102
+ """
103
+ This is the base class for all the objects that can be drawn.
104
+
105
+ One must subclass from this (and an assortment of Mixins) to create
106
+ a new DrawObject, see for example :class:`~lib.floatcanvas.FloatCanvas.Circle`.
107
+
108
+ """
109
+ #This class contains a series of static dictionaries:
110
+
111
+ #* BrushList
112
+ #* PenList
113
+ #* FillStyleList
114
+ #* LineStyleList
115
+
116
+
117
+ def __init__(self, InForeground = False, IsVisible = True):
118
+ """
119
+ Default class constructor.
120
+
121
+ :param boolean `InForeground`: Define if object should be in foreground
122
+ or not
123
+ :param boolean `IsVisible`: Define if object should be visible
124
+
125
+ """
126
+ self.InForeground = InForeground
127
+
128
+ self._Canvas = None
129
+
130
+ self.HitColor = None
131
+ self.CallBackFuncs = {}
132
+
133
+ ## these are the defaults
134
+ self.HitAble = False
135
+ self.HitLine = True
136
+ self.HitFill = True
137
+ self.MinHitLineWidth = 3
138
+ self.HitLineWidth = 3 ## this gets re-set by the subclasses if necessary
139
+
140
+ self.Brush = None
141
+ self.Pen = None
142
+
143
+ self.FillStyle = "Solid"
144
+
145
+ self.Visible = IsVisible
146
+
147
+ # I pre-define all these as class variables to provide an easier
148
+ # interface, and perhaps speed things up by caching all the Pens
149
+ # and Brushes, although that may not help, as I think wx now
150
+ # does that on it's own. Send me a note if you know!
151
+
152
+ BrushList = {
153
+ ( None, "Transparent") : wx.TRANSPARENT_BRUSH,
154
+ ("Blue", "Solid") : wx.BLUE_BRUSH,
155
+ ("Green", "Solid") : wx.GREEN_BRUSH,
156
+ ("White", "Solid") : wx.WHITE_BRUSH,
157
+ ("Black", "Solid") : wx.BLACK_BRUSH,
158
+ ("Grey", "Solid") : wx.GREY_BRUSH,
159
+ ("MediumGrey", "Solid") : wx.MEDIUM_GREY_BRUSH,
160
+ ("LightGrey", "Solid") : wx.LIGHT_GREY_BRUSH,
161
+ ("Cyan", "Solid") : wx.CYAN_BRUSH,
162
+ ("Red", "Solid") : wx.RED_BRUSH
163
+ }
164
+ PenList = {
165
+ (None, "Transparent", 1) : wx.TRANSPARENT_PEN,
166
+ ("Green", "Solid", 1) : wx.GREEN_PEN,
167
+ ("White", "Solid", 1) : wx.WHITE_PEN,
168
+ ("Black", "Solid", 1) : wx.BLACK_PEN,
169
+ ("Grey", "Solid", 1) : wx.GREY_PEN,
170
+ ("MediumGrey", "Solid", 1) : wx.MEDIUM_GREY_PEN,
171
+ ("LightGrey", "Solid", 1) : wx.LIGHT_GREY_PEN,
172
+ ("Cyan", "Solid", 1) : wx.CYAN_PEN,
173
+ ("Red", "Solid", 1) : wx.RED_PEN
174
+ }
175
+
176
+ FillStyleList = {
177
+ "Transparent" : wx.BRUSHSTYLE_TRANSPARENT,
178
+ "Solid" : wx.BRUSHSTYLE_SOLID,
179
+ "BiDiagonalHatch": wx.BRUSHSTYLE_BDIAGONAL_HATCH,
180
+ "CrossDiagHatch" : wx.BRUSHSTYLE_CROSSDIAG_HATCH,
181
+ "FDiagonal_Hatch": wx.BRUSHSTYLE_FDIAGONAL_HATCH,
182
+ "CrossHatch" : wx.BRUSHSTYLE_CROSS_HATCH,
183
+ "HorizontalHatch": wx.BRUSHSTYLE_HORIZONTAL_HATCH,
184
+ "VerticalHatch" : wx.BRUSHSTYLE_VERTICAL_HATCH
185
+ }
186
+
187
+ LineStyleList = {
188
+ "Solid" : wx.PENSTYLE_SOLID,
189
+ "Transparent": wx.PENSTYLE_TRANSPARENT,
190
+ "Dot" : wx.PENSTYLE_DOT,
191
+ "LongDash" : wx.PENSTYLE_LONG_DASH,
192
+ "ShortDash" : wx.PENSTYLE_SHORT_DASH,
193
+ "DotDash" : wx.PENSTYLE_DOT_DASH,
194
+ }
195
+
196
+ def Bind(self, Event, CallBackFun):
197
+ """
198
+ Bind an event to the DrawObject
199
+
200
+ :param `Event`: see below for supported event types
201
+
202
+ - EVT_FC_LEFT_DOWN
203
+ - EVT_FC_LEFT_UP
204
+ - EVT_FC_LEFT_DCLICK
205
+ - EVT_FC_MIDDLE_DOWN
206
+ - EVT_FC_MIDDLE_UP
207
+ - EVT_FC_MIDDLE_DCLICK
208
+ - EVT_FC_RIGHT_DOWN
209
+ - EVT_FC_RIGHT_UP
210
+ - EVT_FC_RIGHT_DCLICK
211
+ - EVT_FC_ENTER_OBJECT
212
+ - EVT_FC_LEAVE_OBJECT
213
+
214
+ :param `CallBackFun`: the call back function for the event
215
+
216
+
217
+ """
218
+ ##fixme: Way too much Canvas Manipulation here!
219
+ self.CallBackFuncs[Event] = CallBackFun
220
+ self.HitAble = True
221
+ self._Canvas.UseHitTest = True
222
+ if self.InForeground and self._Canvas._ForegroundHTBitmap is None:
223
+ self._Canvas.MakeNewForegroundHTBitmap()
224
+ elif self._Canvas._HTBitmap is None:
225
+ self._Canvas.MakeNewHTBitmap()
226
+ if not self.HitColor:
227
+ if not self._Canvas.HitColorGenerator:
228
+ # first call to prevent the background color from being used.
229
+ self._Canvas.HitColorGenerator = _colorGenerator()
230
+ next(self._Canvas.HitColorGenerator)
231
+ self.HitColor = next(self._Canvas.HitColorGenerator)
232
+ self.SetHitPen(self.HitColor,self.HitLineWidth)
233
+ self.SetHitBrush(self.HitColor)
234
+ # put the object in the hit dict, indexed by it's color
235
+ if not self._Canvas.HitDict:
236
+ self._Canvas.MakeHitDict()
237
+ self._Canvas.HitDict[Event][self.HitColor] = (self) # put the object in the hit dict, indexed by its color
238
+
239
+ def UnBindAll(self):
240
+ """
241
+ Unbind all events
242
+
243
+ .. note:: Currently only removes one from each list
244
+
245
+ """
246
+ ## fixme: this only removes one from each list, there could be more.
247
+ ## + patch by Tim Ansel
248
+ if self._Canvas.HitDict:
249
+ for Event in self._Canvas.HitDict.itervalues():
250
+ try:
251
+ del Event[self.HitColor]
252
+ except KeyError:
253
+ pass
254
+ self.HitAble = False
255
+
256
+
257
+ def SetBrush(self, FillColor, FillStyle):
258
+ """
259
+ Set the brush for this DrawObject
260
+
261
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
262
+ for valid entries
263
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
264
+ for valid entries
265
+ """
266
+ if FillColor is None or FillStyle is None:
267
+ self.Brush = wx.TRANSPARENT_BRUSH
268
+ ##fixme: should I really re-set the style?
269
+ self.FillStyle = "Transparent"
270
+ else:
271
+ self.Brush = self.BrushList.setdefault(
272
+ (FillColor, FillStyle),
273
+ wx.Brush(FillColor, self.FillStyleList[FillStyle]))
274
+ #print("Setting Brush, BrushList length:", len(self.BrushList))
275
+
276
+ def SetPen(self, LineColor, LineStyle, LineWidth):
277
+ """
278
+ Set the Pen for this DrawObject
279
+
280
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
281
+ for valid entries
282
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
283
+ for valid entries
284
+ :param integer `LineWidth`: the width in pixels
285
+ """
286
+ if (LineColor is None) or (LineStyle is None):
287
+ self.Pen = wx.TRANSPARENT_PEN
288
+ self.LineStyle = 'Transparent'
289
+ else:
290
+ self.Pen = self.PenList.setdefault(
291
+ (LineColor, LineStyle, LineWidth),
292
+ wx.Pen(LineColor, int(LineWidth), self.LineStyleList[LineStyle]))
293
+
294
+ def SetHitBrush(self, HitColor):
295
+ """
296
+ Set the brush used for hit test, do not call directly.
297
+
298
+ :param `HitColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
299
+
300
+ """
301
+ if not self.HitFill:
302
+ self.HitBrush = wx.TRANSPARENT_BRUSH
303
+ else:
304
+ self.HitBrush = self.BrushList.setdefault(
305
+ (HitColor,"solid"),
306
+ wx.Brush(HitColor, self.FillStyleList["Solid"]))
307
+
308
+ def SetHitPen(self, HitColor, LineWidth):
309
+ """
310
+ Set the pen used for hit test, do not call directly.
311
+
312
+ :param `HitColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
313
+ :param integer `LineWidth`: the line width in pixels
314
+
315
+ """
316
+ if not self.HitLine:
317
+ self.HitPen = wx.TRANSPARENT_PEN
318
+ else:
319
+ self.HitPen = self.PenList.setdefault( (HitColor, "solid", self.HitLineWidth), wx.Pen(HitColor, self.HitLineWidth, self.LineStyleList["Solid"]) )
320
+
321
+ ## Just to make sure that they will always be there
322
+ ## the appropriate ones should be overridden in the subclasses
323
+ def SetColor(self, Color):
324
+ """
325
+ Set the Color - this method is overridden in the subclasses
326
+
327
+ :param `Color`: use one of the following values any valid entry from
328
+ :class:`wx.ColourDatabase`
329
+
330
+ - ``Green``
331
+ - ``White``
332
+ - ``Black``
333
+ - ``Grey``
334
+ - ``MediumGrey``
335
+ - ``LightGrey``
336
+ - ``Cyan``
337
+ - ``Red``
338
+
339
+ """
340
+
341
+ pass
342
+
343
+ def SetLineColor(self, LineColor):
344
+ """
345
+ Set the LineColor - this method is overridden in the subclasses
346
+
347
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
348
+ for valid values
349
+
350
+ """
351
+ pass
352
+
353
+ def SetLineStyle(self, LineStyle):
354
+ """
355
+ Set the LineStyle - this method is overridden in the subclasses
356
+
357
+ :param `LineStyle`: Use one of the following values or ``None`` :
358
+
359
+ ===================== =============================
360
+ Style Description
361
+ ===================== =============================
362
+ ``Solid`` Solid line
363
+ ``Transparent`` A transparent line
364
+ ``Dot`` Dotted line
365
+ ``LongDash`` Dashed line (long)
366
+ ``ShortDash`` Dashed line (short)
367
+ ``DotDash`` Dash-dot-dash line
368
+ ===================== =============================
369
+
370
+ """
371
+ pass
372
+
373
+ def SetLineWidth(self, LineWidth):
374
+ """
375
+ Set the LineWidth
376
+
377
+ :param integer `LineWidth`: sets the line width in pixel
378
+
379
+ """
380
+ pass
381
+
382
+ def SetFillColor(self, FillColor):
383
+ """
384
+ Set the FillColor - this method is overridden in the subclasses
385
+
386
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
387
+ for valid values
388
+
389
+ """
390
+ pass
391
+
392
+ def SetFillStyle(self, FillStyle):
393
+ """
394
+ Set the FillStyle - this method is overridden in the subclasses
395
+
396
+ :param string `FillStyle`: following is a list of valid values:
397
+
398
+ ===================== =========================================
399
+ Style Description
400
+ ===================== =========================================
401
+ ``Transparent`` Transparent fill
402
+ ``Solid`` Solid fill
403
+ ``BiDiagonalHatch`` Bi Diagonal hatch fill
404
+ ``CrossDiagHatch`` Cross Diagonal hatch fill
405
+ ``FDiagonal_Hatch`` F Diagonal hatch fill
406
+ ``CrossHatch`` Cross hatch fill
407
+ ``HorizontalHatch`` Horizontal hatch fill
408
+ ``VerticalHatch`` Vertical hatch fill
409
+ ===================== =========================================
410
+
411
+ """
412
+ pass
413
+
414
+ def PutInBackground(self):
415
+ """Put the object in the background."""
416
+ if self._Canvas and self.InForeground:
417
+ self._Canvas._ForeDrawList.remove(self)
418
+ self._Canvas._DrawList.append(self)
419
+ self._Canvas._BackgroundDirty = True
420
+ self.InForeground = False
421
+
422
+ def PutInForeground(self):
423
+ """Put the object in the foreground."""
424
+ if self._Canvas and (not self.InForeground):
425
+ self._Canvas._ForeDrawList.append(self)
426
+ self._Canvas._DrawList.remove(self)
427
+ self._Canvas._BackgroundDirty = True
428
+ self.InForeground = True
429
+
430
+ def Hide(self):
431
+ """Hide the object."""
432
+ self.Visible = False
433
+
434
+ def Show(self):
435
+ """Show the object."""
436
+ self.Visible = True
437
+
438
+
439
+ class ColorOnlyMixin:
440
+ """
441
+ Mixin class for objects that have just one color, rather than a fill
442
+ color and line color
443
+
444
+ """
445
+
446
+ def SetColor(self, Color):
447
+ """
448
+ Set the Color
449
+
450
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
451
+ for valid values
452
+
453
+ """
454
+ self.SetPen(Color,"Solid",1)
455
+ self.SetBrush(Color,"Solid")
456
+
457
+ SetFillColor = SetColor # Just to provide a consistent interface
458
+
459
+
460
+ class LineOnlyMixin:
461
+ """
462
+ Mixin class for objects that have just a line, rather than a fill
463
+ color and line color
464
+
465
+ """
466
+
467
+ def SetLineColor(self, LineColor):
468
+ """
469
+ Set the LineColor
470
+
471
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
472
+ for valid values
473
+
474
+ """
475
+ self.LineColor = LineColor
476
+ self.SetPen(LineColor,self.LineStyle,self.LineWidth)
477
+ SetColor = SetLineColor# so that it will do something reasonable
478
+
479
+ def SetLineStyle(self, LineStyle):
480
+ """
481
+ Set the LineStyle
482
+
483
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
484
+ for valid values
485
+
486
+ """
487
+ self.LineStyle = LineStyle
488
+ self.SetPen(self.LineColor,LineStyle,self.LineWidth)
489
+
490
+ def SetLineWidth(self, LineWidth):
491
+ """
492
+ Set the LineWidth
493
+
494
+ :param integer `LineWidth`: line width in pixels
495
+
496
+ """
497
+ self.LineWidth = LineWidth
498
+ self.SetPen(self.LineColor,self.LineStyle,LineWidth)
499
+
500
+
501
+ class LineAndFillMixin(LineOnlyMixin):
502
+ """
503
+ Mixin class for objects that have both a line and a fill color and
504
+ style.
505
+
506
+ """
507
+ def SetFillColor(self, FillColor):
508
+ """
509
+ Set the FillColor
510
+
511
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
512
+ for valid values
513
+
514
+ """
515
+ self.FillColor = FillColor
516
+ self.SetBrush(FillColor, self.FillStyle)
517
+
518
+ def SetFillStyle(self, FillStyle):
519
+ """
520
+ Set the FillStyle
521
+
522
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
523
+ for valid values
524
+
525
+ """
526
+ self.FillStyle = FillStyle
527
+ self.SetBrush(self.FillColor,FillStyle)
528
+
529
+ def SetUpDraw(self, dc, WorldToPixel, ScaleWorldToPixel, HTdc):
530
+ """
531
+ Setup for draw
532
+
533
+ :param `dc`: the dc to draw ???
534
+ :param `WorldToPixel`: ???
535
+ :param `ScaleWorldToPixel`: ???
536
+ :param `HTdc`: ???
537
+
538
+ """
539
+ dc.SetPen(self.Pen)
540
+ dc.SetBrush(self.Brush)
541
+ if HTdc and self.HitAble:
542
+ HTdc.SetPen(self.HitPen)
543
+ HTdc.SetBrush(self.HitBrush)
544
+ return ( WorldToPixel(self.XY),
545
+ ScaleWorldToPixel(self.WH) )
546
+
547
+
548
+ class XYObjectMixin:
549
+ """
550
+ This is a mixin class that provides some methods suitable for use
551
+ with objects that have a single (x,y) coordinate pair.
552
+ """
553
+
554
+ def Move(self, Delta):
555
+ """
556
+ Moves the object by delta, where delta is a (dx, dy) pair.
557
+
558
+ :param `Delta`: is a (dx, dy) pair ideally a `NumPy <http://www.numpy.org/>`_
559
+ array of shape (2, )
560
+
561
+ """
562
+ Delta = np.asarray(Delta, float)
563
+ self.XY += Delta
564
+ self.BoundingBox += Delta
565
+
566
+ if self._Canvas:
567
+ self._Canvas.BoundingBoxDirty = True
568
+
569
+ def CalcBoundingBox(self):
570
+ """Calculate the bounding box."""
571
+ ## This may get overwritten in some subclasses
572
+ self.BoundingBox = BBox.asBBox((self.XY, self.XY))
573
+
574
+ def SetPoint(self, xy):
575
+ xy = np.array(xy, float)
576
+ xy = xy.reshape((2,))
577
+
578
+ self.XY = xy
579
+ self.CalcBoundingBox()
580
+
581
+ if self._Canvas:
582
+ self._Canvas.BoundingBoxDirty = True
583
+
584
+ class PointsObjectMixin:
585
+ """
586
+ A mixin class that provides some methods suitable for use
587
+ with objects that have a set of (x, y) coordinate pairs.
588
+
589
+ """
590
+
591
+ def Move(self, Delta):
592
+ """
593
+ Moves the object by delta, where delta is a (dx, dy) pair.
594
+
595
+ :param `Delta`: is a (dx, dy) pair ideally a `NumPy <http://www.numpy.org/>`_
596
+ array of shape (2, )
597
+
598
+ """
599
+ Delta = np.asarray(Delta, float)
600
+ Delta = Delta.reshape((2,))
601
+ self.Points += Delta
602
+ self.BoundingBox += Delta
603
+ if self._Canvas:
604
+ self._Canvas.BoundingBoxDirty = True
605
+
606
+ def CalcBoundingBox(self):
607
+ """Calculate the bounding box."""
608
+ self.BoundingBox = BBox.fromPoints(self.Points)
609
+ if self._Canvas:
610
+ self._Canvas.BoundingBoxDirty = True
611
+
612
+ def SetPoints(self, Points, copy=True):
613
+ """
614
+ Sets the coordinates of the points of the object to Points (NX2 array).
615
+
616
+ :param `Points`: takes a 2-tuple, or a (2,)
617
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
618
+ :param boolean `copy`: By default, a copy is made, if copy is set to
619
+ ``False``, a reference is used, if Points is a NumPy array of Floats.
620
+ This allows you to change some or all of the points without making
621
+ any copies.
622
+
623
+ For example::
624
+
625
+ Points = Object.Points
626
+ # shifts the points 5 in the x dir, and 10 in the y dir.
627
+ Points += (5, 10)
628
+ # Sets the points to the same array as it was
629
+ Object.SetPoints(Points, False)
630
+
631
+ """
632
+ if copy:
633
+ self.Points = np.array(Points, float)
634
+ self.Points = self.Points.reshape((-1, 2)) # Make sure it is a NX2 array, even if there is only one point
635
+ else:
636
+ self.Points = np.asarray(Points, float)
637
+ self.CalcBoundingBox()
638
+
639
+
640
+ class Polygon(PointsObjectMixin, LineAndFillMixin, DrawObject):
641
+ """
642
+ Draws a polygon
643
+
644
+ Points is a list of 2-tuples, or a NX2 NumPy array of
645
+ point coordinates. so that Points[N][0] is the x-coordinate of
646
+ point N and Points[N][1] is the y-coordinate or Points[N,0] is the
647
+ x-coordinate of point N and Points[N,1] is the y-coordinate for
648
+ arrays.
649
+
650
+ """
651
+ def __init__(self,
652
+ Points,
653
+ LineColor = "Black",
654
+ LineStyle = "Solid",
655
+ LineWidth = 1,
656
+ FillColor = None,
657
+ FillStyle = "Solid",
658
+ InForeground = False):
659
+ """
660
+ Default class constructor.
661
+
662
+ :param `Points`: start point, takes a 2-tuple, or a (2,)
663
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
664
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
665
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
666
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
667
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
668
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
669
+ :param boolean `InForeground`: should object be in foreground
670
+
671
+ """
672
+ DrawObject.__init__(self, InForeground)
673
+ self.Points = np.array(Points ,float) # this DOES need to make a copy
674
+ self.CalcBoundingBox()
675
+
676
+ self.LineColor = LineColor
677
+ self.LineStyle = LineStyle
678
+ self.LineWidth = LineWidth
679
+ self.FillColor = FillColor
680
+ self.FillStyle = FillStyle
681
+
682
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
683
+
684
+ self.SetPen(LineColor,LineStyle,LineWidth)
685
+ self.SetBrush(FillColor,FillStyle)
686
+
687
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel = None, HTdc=None):
688
+ Points = WorldToPixel(self.Points)
689
+ dc.SetPen(self.Pen)
690
+ dc.SetBrush(self.Brush)
691
+ dc.DrawPolygon(Points)
692
+ if HTdc and self.HitAble:
693
+ HTdc.SetPen(self.HitPen)
694
+ HTdc.SetBrush(self.HitBrush)
695
+ HTdc.DrawPolygon(Points)
696
+
697
+ class Line(PointsObjectMixin, LineOnlyMixin, DrawObject):
698
+ """
699
+ Draws a line
700
+
701
+ It will draw a straight line if there are two points, and a polyline
702
+ if there are more than two.
703
+
704
+ """
705
+ def __init__(self, Points,
706
+ LineColor = "Black",
707
+ LineStyle = "Solid",
708
+ LineWidth = 1,
709
+ InForeground = False):
710
+ """
711
+ Default class constructor.
712
+
713
+ :param `Points`: takes a 2-tuple, or a (2,)
714
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
715
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
716
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
717
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
718
+ :param boolean `InForeground`: should object be in foreground
719
+
720
+ """
721
+ DrawObject.__init__(self, InForeground)
722
+
723
+
724
+ self.Points = np.array(Points,float)
725
+ self.CalcBoundingBox()
726
+
727
+ self.LineColor = LineColor
728
+ self.LineStyle = LineStyle
729
+ self.LineWidth = LineWidth
730
+
731
+ self.SetPen(LineColor,LineStyle,LineWidth)
732
+
733
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
734
+
735
+
736
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
737
+ Points = WorldToPixel(self.Points)
738
+ dc.SetPen(self.Pen)
739
+ dc.DrawLines(Points)
740
+ if HTdc and self.HitAble:
741
+ HTdc.SetPen(self.HitPen)
742
+ HTdc.DrawLines(Points)
743
+
744
+ class Spline(Line):
745
+ """Draws a spline"""
746
+ def __init__(self, *args, **kwargs):
747
+ """
748
+ Default class constructor.
749
+
750
+ see :class:`~lib.floatcanvas.FloatCanvas.Line`
751
+
752
+ """
753
+ Line.__init__(self, *args, **kwargs)
754
+
755
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
756
+ Points = WorldToPixel(self.Points)
757
+ dc.SetPen(self.Pen)
758
+ dc.DrawSpline(Points)
759
+ if HTdc and self.HitAble:
760
+ HTdc.SetPen(self.HitPen)
761
+ HTdc.DrawSpline(Points)
762
+
763
+
764
+ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject):
765
+ """
766
+ Draws an arrow
767
+
768
+ It will draw an arrow , starting at the point ``XY`` points at an angle
769
+ defined by ``Direction``.
770
+
771
+ """
772
+ def __init__(self,
773
+ XY,
774
+ Length,
775
+ Direction,
776
+ LineColor = "Black",
777
+ LineStyle = "Solid",
778
+ LineWidth = 2,
779
+ ArrowHeadSize = 8,
780
+ ArrowHeadAngle = 30,
781
+ InForeground = False):
782
+ """
783
+ Default class constructor.
784
+
785
+ :param `XY`: the (x, y) coordinate of the starting point, or a 2-tuple,
786
+ or a (2,) `NumPy <http://www.numpy.org/>`_ array
787
+ :param integer `Length`: length of arrow in pixels
788
+ :param integer `Direction`: angle of arrow in degrees, zero is straight
789
+ up `+` angle is to the right
790
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
791
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
792
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
793
+ :param `ArrowHeadSize`: size of arrow head in pixels
794
+ :param `ArrowHeadAngle`: angle of arrow head in degrees
795
+ :param boolean `InForeground`: should object be in foreground
796
+
797
+ """
798
+
799
+ DrawObject.__init__(self, InForeground)
800
+
801
+ self.XY = np.array(XY, float)
802
+ self.XY = self.XY.reshape((2,)) # Make sure it is a length 2 vector
803
+ self.Length = Length
804
+ self.Direction = float(Direction)
805
+ self.ArrowHeadSize = ArrowHeadSize
806
+ self.ArrowHeadAngle = float(ArrowHeadAngle)
807
+
808
+ self.CalcArrowPoints()
809
+ self.CalcBoundingBox()
810
+
811
+ self.LineColor = LineColor
812
+ self.LineStyle = LineStyle
813
+ self.LineWidth = LineWidth
814
+
815
+ self.SetPen(LineColor,LineStyle,LineWidth)
816
+
817
+ ##fixme: How should the HitTest be drawn?
818
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
819
+
820
+ def SetDirection(self, Direction):
821
+ """
822
+ Set the direction
823
+
824
+ :param integer `Direction`: angle of arrow in degrees, zero is straight
825
+ up `+` angle is to the right
826
+
827
+ """
828
+ self.Direction = float(Direction)
829
+ self.CalcArrowPoints()
830
+
831
+ def SetLength(self, Length):
832
+ """
833
+ Set the length
834
+
835
+ :param integer `Length`: length of arrow in pixels
836
+
837
+ """
838
+ self.Length = Length
839
+ self.CalcArrowPoints()
840
+
841
+ def SetLengthDirection(self, Length, Direction):
842
+ """
843
+ Set the length and direction
844
+
845
+ :param integer `Length`: length of arrow in pixels
846
+ :param integer `Direction`: angle of arrow in degrees, zero is straight
847
+ up `+` angle is to the right
848
+
849
+ """
850
+ self.Direction = float(Direction)
851
+ self.Length = Length
852
+ self.CalcArrowPoints()
853
+
854
+ ## def CalcArrowPoints(self):
855
+ ## L = self.Length
856
+ ## S = self.ArrowHeadSize
857
+ ## phi = self.ArrowHeadAngle * N.pi / 360
858
+ ## theta = (self.Direction-90.0) * N.pi / 180
859
+ ## ArrowPoints = N.array( ( (0, L, L - S*N.cos(phi),L, L - S*N.cos(phi) ),
860
+ ## (0, 0, S*N.sin(phi), 0, -S*N.sin(phi) ) ),
861
+ ## float )
862
+ ## RotationMatrix = N.array( ( ( N.cos(theta), -N.sin(theta) ),
863
+ ## ( N.sin(theta), N.cos(theta) ) ),
864
+ ## float
865
+ ## )
866
+ ## ArrowPoints = N.matrixmultiply(RotationMatrix, ArrowPoints)
867
+ ## self.ArrowPoints = N.transpose(ArrowPoints)
868
+
869
+ def CalcArrowPoints(self):
870
+ """Calculate the arrow points."""
871
+ L = self.Length
872
+ S = self.ArrowHeadSize
873
+ phi = self.ArrowHeadAngle * np.pi / 360
874
+ theta = (270 - self.Direction) * np.pi / 180
875
+ AP = np.array( ( (0,0),
876
+ (0,0),
877
+ (np.cos(theta - phi), -np.sin(theta - phi) ),
878
+ (0,0),
879
+ (np.cos(theta + phi), -np.sin(theta + phi) ),
880
+ ), float )
881
+ AP *= S
882
+ shift = (-L*np.cos(theta), L*np.sin(theta) )
883
+ AP[1:,:] += shift
884
+ self.ArrowPoints = AP
885
+
886
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
887
+ dc.SetPen(self.Pen)
888
+ xy = WorldToPixel(self.XY)
889
+ ArrowPoints = (xy + self.ArrowPoints).astype(int)
890
+ dc.DrawLines(ArrowPoints)
891
+ if HTdc and self.HitAble:
892
+ HTdc.SetPen(self.HitPen)
893
+ HTdc.DrawLines(ArrowPoints)
894
+
895
+
896
+ class ArrowLine(PointsObjectMixin, LineOnlyMixin, DrawObject):
897
+ """
898
+ Draws an arrow line.
899
+
900
+ It will draw a set of arrows from point to point.
901
+
902
+ It takes a list of 2-tuples, or a NX2 NumPy Float array of point coordinates.
903
+
904
+ """
905
+
906
+ def __init__(self,
907
+ Points,
908
+ LineColor = "Black",
909
+ LineStyle = "Solid",
910
+ LineWidth = 1,
911
+ ArrowHeadSize = 8,
912
+ ArrowHeadAngle = 30,
913
+ InForeground = False):
914
+ """
915
+ Default class constructor.
916
+
917
+ :param `Points`: takes a 2-tuple, or a (2,)
918
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
919
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
920
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
921
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
922
+ :param `ArrowHeadSize`: size of arrow head in pixels
923
+ :param `ArrowHeadAngle`: angle of arrow head in degrees
924
+ :param boolean `InForeground`: should object be in foreground
925
+
926
+ """
927
+
928
+ DrawObject.__init__(self, InForeground)
929
+
930
+ self.Points = np.asarray(Points,float)
931
+ self.Points = self.Points.reshape((-1,2)) # Make sure it is a NX2 array, even if there is only one point
932
+ self.ArrowHeadSize = ArrowHeadSize
933
+ self.ArrowHeadAngle = float(ArrowHeadAngle)
934
+
935
+ self.CalcArrowPoints()
936
+ self.CalcBoundingBox()
937
+
938
+ self.LineColor = LineColor
939
+ self.LineStyle = LineStyle
940
+ self.LineWidth = LineWidth
941
+
942
+ self.SetPen(LineColor,LineStyle,LineWidth)
943
+
944
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
945
+
946
+ def CalcArrowPoints(self):
947
+ """Calculate the arrow points."""
948
+ S = self.ArrowHeadSize
949
+ phi = self.ArrowHeadAngle * np.pi / 360
950
+ Points = self.Points
951
+ n = Points.shape[0]
952
+ self.ArrowPoints = np.zeros((n-1, 3, 2), float)
953
+ for i in range(n-1):
954
+ dx, dy = self.Points[i] - self.Points[i+1]
955
+ theta = np.arctan2(dy, dx)
956
+ AP = np.array( (
957
+ (np.cos(theta - phi), -np.sin(theta-phi)),
958
+ (0,0),
959
+ (np.cos(theta + phi), -np.sin(theta + phi))
960
+ ),
961
+ float )
962
+ self.ArrowPoints[i,:,:] = AP
963
+ self.ArrowPoints *= S
964
+
965
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
966
+ Points = WorldToPixel(self.Points)
967
+ ArrowPoints = (Points[1:,np.newaxis,:] + self.ArrowPoints).astype(int)
968
+ dc.SetPen(self.Pen)
969
+ dc.DrawLines(Points)
970
+ for arrow in ArrowPoints:
971
+ dc.DrawLines(arrow)
972
+ if HTdc and self.HitAble:
973
+ HTdc.SetPen(self.HitPen)
974
+ HTdc.DrawLines(Points)
975
+ for arrow in ArrowPoints:
976
+ HTdc.DrawLines(arrow)
977
+
978
+
979
+ class PointSet(PointsObjectMixin, ColorOnlyMixin, DrawObject):
980
+ """
981
+ Draws a set of points
982
+
983
+ If Points is a sequence of tuples: Points[N][0] is the x-coordinate of
984
+ point N and Points[N][1] is the y-coordinate.
985
+
986
+ If Points is a NumPy array: Points[N,0] is the x-coordinate of point
987
+ N and Points[N,1] is the y-coordinate for arrays.
988
+
989
+ Each point will be drawn the same color and Diameter. The Diameter
990
+ is in screen pixels, not world coordinates.
991
+
992
+ The hit-test code does not distinguish between the points, you will
993
+ only know that one of the points got hit, not which one. You can use
994
+ PointSet.FindClosestPoint(WorldPoint) to find out which one
995
+
996
+ In the case of points, the HitLineWidth is used as diameter.
997
+
998
+ """
999
+ def __init__(self, Points, Color="Black", Diameter=1, InForeground=False):
1000
+ """
1001
+ Default class constructor.
1002
+
1003
+ :param `Points`: takes a 2-tuple, or a (2,)
1004
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
1005
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1006
+ :param integer `Diameter`: the points diameter
1007
+ :param boolean `InForeground`: should object be in foreground
1008
+
1009
+ """
1010
+ DrawObject.__init__(self, InForeground)
1011
+
1012
+ self.Points = np.array(Points,float)
1013
+ self.Points = self.Points.reshape((-1,2)) # Make sure it is a NX2 array, even if there is only one point
1014
+ self.CalcBoundingBox()
1015
+ self.Diameter = Diameter
1016
+
1017
+ self.HitLineWidth = min(self.MinHitLineWidth, Diameter)
1018
+ self.SetColor(Color)
1019
+
1020
+ def SetDiameter(self, Diameter):
1021
+ """
1022
+ Sets the diameter
1023
+
1024
+ :param integer `Diameter`: the points diameter
1025
+
1026
+ """
1027
+ self.Diameter = Diameter
1028
+
1029
+ def FindClosestPoint(self, XY):
1030
+ """
1031
+ Returns the index of the closest point to the point, XY, given
1032
+ in World coordinates. It's essentially random which you get if
1033
+ there are more than one that are the same.
1034
+
1035
+ This can be used to figure out which point got hit in a mouse
1036
+ binding callback, for instance. It's a lot faster that using a
1037
+ lot of separate points.
1038
+
1039
+ :param `XY`: the (x,y) coordinates of the point to look for, it takes a
1040
+ 2-tuple or (2,) numpy array in World coordinates
1041
+
1042
+ """
1043
+ d = self.Points - XY
1044
+ return np.argmin(np.hypot(d[:,0],d[:,1]))
1045
+
1046
+
1047
+ def DrawD2(self, dc, Points):
1048
+ # A Little optimization for a diameter2 - point
1049
+ dc.DrawPointList(Points)
1050
+ dc.DrawPointList(Points + (1,0))
1051
+ dc.DrawPointList(Points + (0,1))
1052
+ dc.DrawPointList(Points + (1,1))
1053
+
1054
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1055
+ dc.SetPen(self.Pen)
1056
+ Points = WorldToPixel(self.Points)
1057
+ if self.Diameter <= 1:
1058
+ dc.DrawPointList(Points)
1059
+ elif self.Diameter <= 2:
1060
+ self.DrawD2(dc, Points)
1061
+ else:
1062
+ dc.SetBrush(self.Brush)
1063
+ radius = int(round(self.Diameter/2))
1064
+ ##fixme: I really should add a DrawCircleList to wxPython
1065
+ if len(Points) > 100:
1066
+ xy = Points
1067
+ xywh = np.concatenate((xy-radius, np.ones(xy.shape) * self.Diameter ), 1 )
1068
+ dc.DrawEllipseList(xywh.astype(int))
1069
+ else:
1070
+ for xy in Points:
1071
+ dc.DrawCircle(xy[0],xy[1], radius)
1072
+ if HTdc and self.HitAble:
1073
+ HTdc.SetPen(self.HitPen)
1074
+ HTdc.SetBrush(self.HitBrush)
1075
+ if self.Diameter <= 1:
1076
+ HTdc.DrawPointList(Points)
1077
+ elif self.Diameter <= 2:
1078
+ self.DrawD2(HTdc, Points)
1079
+ else:
1080
+ if len(Points) > 100:
1081
+ xy = Points
1082
+ xywh = np.concatenate((xy-radius, np.ones(xy.shape) * self.Diameter ), 1 )
1083
+ HTdc.DrawEllipseList(xywh.astype(int))
1084
+ else:
1085
+ for xy in Points:
1086
+ HTdc.DrawCircle(xy[0],xy[1], radius)
1087
+
1088
+ class Point(XYObjectMixin, ColorOnlyMixin, DrawObject):
1089
+ """
1090
+ A point DrawObject
1091
+
1092
+ .. note::
1093
+
1094
+ The Bounding box is just the point, and doesn't include the Diameter.
1095
+
1096
+ The HitLineWidth is used as diameter for the Hit Test.
1097
+
1098
+ """
1099
+ def __init__(self, XY, Color="Black", Diameter=1, InForeground=False):
1100
+ """
1101
+ Default class constructor.
1102
+
1103
+ :param `XY`: the (x, y) coordinate of the center of the point, or a
1104
+ 2-tuple, or a (2,) `NumPy <http://www.numpy.org/>`_ array
1105
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1106
+ :param integer `Diameter`: in screen points
1107
+ :param `InForeground`: define if object is in foreground
1108
+
1109
+ """
1110
+
1111
+ DrawObject.__init__(self, InForeground)
1112
+
1113
+ self.XY = np.array(XY, float)
1114
+ self.XY = self.XY.reshape((2,)) # Make sure it is a length 2 vector
1115
+ self.CalcBoundingBox()
1116
+ self.SetColor(Color)
1117
+ self.Diameter = Diameter
1118
+
1119
+ self.HitLineWidth = self.MinHitLineWidth
1120
+
1121
+ def SetDiameter(self, Diameter):
1122
+ """
1123
+ Set the diameter of the object.
1124
+
1125
+ :param integer `Diameter`: in screen points
1126
+
1127
+ """
1128
+ self.Diameter = Diameter
1129
+
1130
+ def _Draw(self, dc, WorldToPixel, ScaleWorldToPixel, HTdc=None):
1131
+ dc.SetPen(self.Pen)
1132
+ xy = WorldToPixel(self.XY)
1133
+ if self.Diameter <= 1:
1134
+ dc.DrawPoint(xy[0], xy[1])
1135
+ else:
1136
+ dc.SetBrush(self.Brush)
1137
+ radius = int(round(self.Diameter/2))
1138
+ dc.DrawCircle(xy[0],xy[1], radius)
1139
+ if HTdc and self.HitAble:
1140
+ HTdc.SetPen(self.HitPen)
1141
+ if self.Diameter <= 1:
1142
+ HTdc.DrawPoint(xy[0], xy[1])
1143
+ else:
1144
+ HTdc.SetBrush(self.HitBrush)
1145
+ HTdc.DrawCircle(xy[0],xy[1], radius)
1146
+
1147
+ class SquarePoint(XYObjectMixin, ColorOnlyMixin, DrawObject):
1148
+ """
1149
+ Draws a square point
1150
+
1151
+ The Size is in screen points, not world coordinates, so the
1152
+ Bounding box is just the point, and doesn't include the Size.
1153
+
1154
+ The HitLineWidth is used as diameter for the Hit Test.
1155
+
1156
+ """
1157
+ def __init__(self, Point, Color="Black", Size=4, InForeground=False):
1158
+ """
1159
+ Default class constructor.
1160
+
1161
+ :param `Point`: takes a 2-tuple, or a (2,)
1162
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
1163
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1164
+ :param integer `Size`: the size of the square point
1165
+ :param boolean `InForeground`: should object be in foreground
1166
+
1167
+ """
1168
+ DrawObject.__init__(self, InForeground)
1169
+
1170
+ self.XY = np.array(Point, float)
1171
+ self.XY = self.XY.reshape((2,)) # Make sure it is a length 2 vector
1172
+ self.CalcBoundingBox()
1173
+ self.SetColor(Color)
1174
+ self.Size = Size
1175
+
1176
+ self.HitLineWidth = self.MinHitLineWidth
1177
+
1178
+ def SetSize(self, Size):
1179
+ """
1180
+ Sets the size
1181
+
1182
+ :param integer `Size`: the size of the square point
1183
+
1184
+ """
1185
+ self.Size = Size
1186
+
1187
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1188
+ Size = self.Size
1189
+ dc.SetPen(self.Pen)
1190
+ xc,yc = WorldToPixel(self.XY)
1191
+
1192
+ if self.Size <= 1:
1193
+ dc.DrawPoint(xc, yc)
1194
+ else:
1195
+ x = xc - Size/2.0
1196
+ y = yc - Size/2.0
1197
+ dc.SetBrush(self.Brush)
1198
+ dc.DrawRectangle(int(x), int(y), Size, Size)
1199
+ if HTdc and self.HitAble:
1200
+ HTdc.SetPen(self.HitPen)
1201
+ if self.Size <= 1:
1202
+ HTdc.DrawPoint(xc, xc)
1203
+ else:
1204
+ HTdc.SetBrush(self.HitBrush)
1205
+ HTdc.DrawRectangle(int(x), int(y), Size, Size)
1206
+
1207
+ class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject):
1208
+ """A RectEllipse draw object."""
1209
+ def __init__(self, XY, WH,
1210
+ LineColor = "Black",
1211
+ LineStyle = "Solid",
1212
+ LineWidth = 1,
1213
+ FillColor = None,
1214
+ FillStyle = "Solid",
1215
+ InForeground = False):
1216
+ """
1217
+ Default class constructor.
1218
+
1219
+ :param `XY`: the (x, y) coordinate of the corner of RectEllipse, or a 2-tuple,
1220
+ or a (2,) `NumPy <http://www.numpy.org/>`_ array
1221
+ :param `WH`: a tuple with the Width and Height for the object
1222
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1223
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
1224
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
1225
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1226
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
1227
+ :param `InForeground`: put object in foreground
1228
+
1229
+ """
1230
+
1231
+ DrawObject.__init__(self,InForeground)
1232
+
1233
+ self.SetShape(XY, WH)
1234
+ self.LineColor = LineColor
1235
+ self.LineStyle = LineStyle
1236
+ self.LineWidth = LineWidth
1237
+ self.FillColor = FillColor
1238
+ self.FillStyle = FillStyle
1239
+
1240
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
1241
+
1242
+ # these define the behaviour when zooming makes the objects really small.
1243
+ self.MinSize = 1
1244
+ self.DisappearWhenSmall = True
1245
+
1246
+ self.SetPen(LineColor,LineStyle,LineWidth)
1247
+ self.SetBrush(FillColor,FillStyle)
1248
+
1249
+ def SetShape(self, XY, WH):
1250
+ """
1251
+ Set the shape of the object.
1252
+
1253
+ :param `XY`: takes a 2-tuple, or a (2,) `NumPy <http://www.numpy.org/>`_
1254
+ array of point coordinates
1255
+ :param `WH`: a tuple with the Width and Height for the object
1256
+
1257
+ """
1258
+ self.XY = np.array( XY, float)
1259
+ self.XY = self.XY.reshape((2,))
1260
+ self.WH = np.array( WH, float)
1261
+ self.WH = self.WH.reshape((2,))
1262
+ self.CalcBoundingBox()
1263
+
1264
+ def CalcBoundingBox(self):
1265
+ """Calculate the bounding box."""
1266
+ # you need this in case Width or Height are negative
1267
+ corners = np.array((self.XY, (self.XY + self.WH) ), float)
1268
+ self.BoundingBox = BBox.fromPoints(corners)
1269
+ if self._Canvas:
1270
+ self._Canvas.BoundingBoxDirty = True
1271
+
1272
+
1273
+ class Rectangle(RectEllipse):
1274
+ """Draws a rectangle see :class:`~lib.floatcanvas.FloatCanvas.RectEllipse`"""
1275
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1276
+ ( XY, WH ) = self.SetUpDraw(dc,
1277
+ WorldToPixel,
1278
+ ScaleWorldToPixel,
1279
+ HTdc)
1280
+ WH[np.abs(WH) < self.MinSize] = self.MinSize
1281
+ if not( self.DisappearWhenSmall and np.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny
1282
+ dc.DrawRectangle(XY, WH)
1283
+ if HTdc and self.HitAble:
1284
+ HTdc.DrawRectangle(XY, WH)
1285
+
1286
+
1287
+ class Ellipse(RectEllipse):
1288
+ """Draws an ellipse see :class:`~lib.floatcanvas.FloatCanvas.RectEllipse`"""
1289
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1290
+ ( XY, WH ) = self.SetUpDraw(dc,
1291
+ WorldToPixel,
1292
+ ScaleWorldToPixel,
1293
+ HTdc)
1294
+ WH[np.abs(WH) < self.MinSize] = self.MinSize
1295
+ if not( self.DisappearWhenSmall and np.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny
1296
+ dc.DrawEllipse(XY, WH)
1297
+ if HTdc and self.HitAble:
1298
+ HTdc.DrawEllipse(XY, WH)
1299
+
1300
+ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject):
1301
+ """Draws a circle"""
1302
+ def __init__(self, XY, Diameter,
1303
+ LineColor = "Black",
1304
+ LineStyle = "Solid",
1305
+ LineWidth = 1,
1306
+ FillColor = None,
1307
+ FillStyle = "Solid",
1308
+ InForeground = False):
1309
+ """
1310
+ Default class constructor.
1311
+
1312
+ :param `XY`: the (x, y) coordinate of the center of the circle, or a 2-tuple,
1313
+ or a (2,) `NumPy <http://www.numpy.org/>`_ array
1314
+ :param integer `Diameter`: the diameter for the object
1315
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1316
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
1317
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
1318
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1319
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
1320
+ :param boolean `InForeground`: should object be in foreground
1321
+
1322
+ """
1323
+ DrawObject.__init__(self, InForeground)
1324
+
1325
+ self.XY = np.array(XY, float)
1326
+ self.WH = np.array((Diameter/2, Diameter/2), float) # just to keep it compatible with others
1327
+ self.CalcBoundingBox()
1328
+
1329
+ self.LineColor = LineColor
1330
+ self.LineStyle = LineStyle
1331
+ self.LineWidth = LineWidth
1332
+ self.FillColor = FillColor
1333
+ self.FillStyle = FillStyle
1334
+
1335
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
1336
+
1337
+ # these define the behaviour when zooming makes the objects really small.
1338
+ self.MinSize = 1
1339
+ self.DisappearWhenSmall = True
1340
+
1341
+ self.SetPen(LineColor,LineStyle,LineWidth)
1342
+ self.SetBrush(FillColor,FillStyle)
1343
+
1344
+ def SetDiameter(self, Diameter):
1345
+ """
1346
+ Set the diameter of the object
1347
+
1348
+ :param integer `Diameter`: the diameter for the object
1349
+
1350
+ """
1351
+ self.WH = np.array((Diameter/2, Diameter/2), float) # just to keep it compatible with others
1352
+
1353
+ def CalcBoundingBox(self):
1354
+ """Calculate the bounding box of the object."""
1355
+ # you need this in case Width or Height are negative
1356
+ self.BoundingBox = BBox.fromPoints( (self.XY+self.WH, self.XY-self.WH) )
1357
+ if self._Canvas:
1358
+ self._Canvas.BoundingBoxDirty = True
1359
+
1360
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1361
+ ( XY, WH ) = self.SetUpDraw(dc,
1362
+ WorldToPixel,
1363
+ ScaleWorldToPixel,
1364
+ HTdc)
1365
+
1366
+ WH[np.abs(WH) < self.MinSize] = self.MinSize
1367
+ if not( self.DisappearWhenSmall and np.abs(WH).min() <= self.MinSize) : # don't try to draw it too tiny
1368
+ dc.DrawCircle(XY, WH[0])
1369
+ if HTdc and self.HitAble:
1370
+ HTdc.DrawCircle(XY, WH[0])
1371
+
1372
+
1373
+ class TextObjectMixin(XYObjectMixin):
1374
+ """
1375
+ A mix in class that holds attributes and methods that are needed by
1376
+ the Text objects
1377
+
1378
+ """
1379
+
1380
+ ## I'm caching fonts, because on GTK, getting a new font can take a
1381
+ ## while. However, it gets cleared after every full draw as hanging
1382
+ ## on to a bunch of large fonts takes a massive amount of memory.
1383
+
1384
+ FontList = {}
1385
+
1386
+ LayoutFontSize = 16 # font size used for calculating layout
1387
+
1388
+ def SetFont(self, Size, Family, Style, Weight, Underlined, FaceName):
1389
+ self.Font = self.FontList.setdefault( (Size,
1390
+ Family,
1391
+ Style,
1392
+ Weight,
1393
+ Underlined,
1394
+ FaceName),
1395
+ #wx.FontFromPixelSize((0.45*Size,Size), # this seemed to give a decent height/width ratio on Windows
1396
+ wx.Font(Size,
1397
+ Family,
1398
+ Style,
1399
+ Weight,
1400
+ Underlined,
1401
+ FaceName) )
1402
+
1403
+ def SetColor(self, Color):
1404
+ self.Color = Color
1405
+
1406
+ def SetBackgroundColor(self, BackgroundColor):
1407
+ self.BackgroundColor = BackgroundColor
1408
+
1409
+ def SetText(self, String):
1410
+ """
1411
+ Re-sets the text displayed by the object
1412
+
1413
+ In the case of the ScaledTextBox, it will re-do the layout as appropriate
1414
+
1415
+ Note: only tested with the ScaledTextBox
1416
+
1417
+ """
1418
+
1419
+ self.String = String
1420
+ self.LayoutText()
1421
+
1422
+ def LayoutText(self):
1423
+ """
1424
+ A dummy method to re-do the layout of the text.
1425
+
1426
+ A derived object needs to override this if required.
1427
+
1428
+ """
1429
+ pass
1430
+
1431
+ ## store the function that shift the coords for drawing text. The
1432
+ ## "c" parameter is the correction for world coordinates, rather
1433
+ ## than pixel coords as the y axis is reversed
1434
+ ## pad is the extra space around the text
1435
+ ## if world = 1, the vertical shift is done in y-up coordinates
1436
+ ShiftFunDict = {'tl': lambda x, y, w, h, world=0, pad=0: (x + pad, y + pad - 2*world*pad),
1437
+ 'tc': lambda x, y, w, h, world=0, pad=0: (x - w//2, y + pad - 2*world*pad),
1438
+ 'tr': lambda x, y, w, h, world=0, pad=0: (x - w - pad, y + pad - 2*world*pad),
1439
+ 'cl': lambda x, y, w, h, world=0, pad=0: (x + pad, y - h//2 + world*h),
1440
+ 'cc': lambda x, y, w, h, world=0, pad=0: (x - w//2, y - h//2 + world*h),
1441
+ 'cr': lambda x, y, w, h, world=0, pad=0: (x - w - pad, y - h//2 + world*h),
1442
+ 'bl': lambda x, y, w, h, world=0, pad=0: (x + pad, y - h + 2*world*h - pad + world*2*pad) ,
1443
+ 'bc': lambda x, y, w, h, world=0, pad=0: (x - w//2, y - h + 2*world*h - pad + world*2*pad) ,
1444
+ 'br': lambda x, y, w, h, world=0, pad=0: (x - w - pad, y - h + 2*world*h - pad + world*2*pad)}
1445
+
1446
+ class Text(TextObjectMixin, DrawObject):
1447
+ """
1448
+ Draws a text object
1449
+
1450
+ The size is fixed, and does not scale with the drawing.
1451
+
1452
+ The hit-test is done on the entire text extent
1453
+
1454
+ """
1455
+
1456
+ def __init__(self, String, xy,
1457
+ Size = 14,
1458
+ Color = "Black",
1459
+ BackgroundColor = None,
1460
+ Family = wx.FONTFAMILY_MODERN,
1461
+ Style = wx.FONTSTYLE_NORMAL,
1462
+ Weight = wx.FONTWEIGHT_NORMAL,
1463
+ Underlined = False,
1464
+ Position = 'tl',
1465
+ InForeground = False,
1466
+ Font = None):
1467
+ """
1468
+ Default class constructor.
1469
+
1470
+ :param string `string`: the text to draw
1471
+ :param `XY`: the (x, y) coordinate of the corner of the text, or a 2-tuple,
1472
+ or a (2,) `NumPy <http://www.numpy.org/>`_ array
1473
+ :param `Size`: the font size
1474
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1475
+ :param `BackgroundColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1476
+ :param wx.FontFamily `Family`: a valid :ref:`wx.FontFamily`
1477
+ :param wx.FontStyle `Style`: a valid :ref:`wx.FontStyle`
1478
+ :param wx.FontWeight `Weight`: a valid :ref:`wx.FontWeight`
1479
+ :param boolean `Underlined`: underline the text
1480
+ :param string `Position`: a two character string indicating where in
1481
+ relation to the coordinates the box should be oriented
1482
+ :param boolean `InForeground`: should object be in foreground
1483
+ :param wx.Font `Font`: alternatively you can define :ref:`wx.Font` and the
1484
+ above will be ignored.
1485
+
1486
+ ============== ==========================
1487
+ 1st character Meaning
1488
+ ============== ==========================
1489
+ ``t`` top
1490
+ ``c`` center
1491
+ ``b`` bottom
1492
+ ============== ==========================
1493
+
1494
+ ============== ==========================
1495
+ 2nd character Meaning
1496
+ ============== ==========================
1497
+ ``l`` left
1498
+ ``c`` center
1499
+ ``r`` right
1500
+ ============== ==========================
1501
+
1502
+ :param wx.Font `Font`: a valid :class:`wx.Font`
1503
+ :param boolean `InForeground`: should object be in foreground
1504
+
1505
+ """
1506
+ DrawObject.__init__(self,InForeground)
1507
+
1508
+ self.String = String
1509
+ # Input size in in Pixels, compute points size from FontScaleinfo.
1510
+ # fixme: for printing, we'll have to do something a little different
1511
+ self.Size = Size * FontScale
1512
+
1513
+ self.Color = Color
1514
+ self.BackgroundColor = BackgroundColor
1515
+
1516
+ if not Font:
1517
+ FaceName = ''
1518
+ else:
1519
+ FaceName = Font.GetFaceName()
1520
+ Family = Font.GetFamily()
1521
+ Size = Font.GetPointSize()
1522
+ Style = Font.GetStyle()
1523
+ Underlined = Font.GetUnderlined()
1524
+ Weight = Font.GetWeight()
1525
+ self.SetFont(Size, Family, Style, Weight, Underlined, FaceName)
1526
+
1527
+ self.BoundingBox = BBox.asBBox((xy, xy))
1528
+
1529
+ self.XY = np.asarray(xy)
1530
+ self.XY = self.XY.reshape((2,))
1531
+
1532
+ (self.TextWidth, self.TextHeight) = (None, None)
1533
+ self.ShiftFun = self.ShiftFunDict[Position]
1534
+
1535
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1536
+ XY = WorldToPixel(self.XY)
1537
+ dc.SetFont(self.Font)
1538
+ dc.SetTextForeground(self.Color)
1539
+ if self.BackgroundColor:
1540
+ dc.SetBackgroundMode(wx.SOLID)
1541
+ dc.SetTextBackground(self.BackgroundColor)
1542
+ else:
1543
+ dc.SetBackgroundMode(wx.TRANSPARENT)
1544
+ if self.TextWidth is None or self.TextHeight is None:
1545
+ (self.TextWidth, self.TextHeight) = dc.GetTextExtent(self.String)
1546
+ XY = self.ShiftFun(XY[0], XY[1], self.TextWidth, self.TextHeight)
1547
+ dc.DrawText(self.String, XY)
1548
+ if HTdc and self.HitAble:
1549
+ HTdc.SetPen(self.HitPen)
1550
+ HTdc.SetBrush(self.HitBrush)
1551
+ HTdc.DrawRectangle(XY, (self.TextWidth, self.TextHeight) )
1552
+
1553
+ class ScaledText(TextObjectMixin, DrawObject):
1554
+ """
1555
+ ##fixme: this can be deprecated and just use ScaledTextBox with different defaults.
1556
+
1557
+ This class creates a text object that is scaled when zoomed. It is
1558
+ placed at the coordinates, x,y. the "Position" argument is a two
1559
+ character string, indicating where in relation to the coordinates
1560
+ the string should be oriented.
1561
+
1562
+ The first letter is: t, c, or b, for top, center and bottom The
1563
+ second letter is: l, c, or r, for left, center and right The
1564
+ position refers to the position relative to the text itself. It
1565
+ defaults to "tl" (top left).
1566
+
1567
+ Size is the size of the font in world coordinates.
1568
+
1569
+ * Family: Font family, a generic way of referring to fonts without
1570
+ specifying actual facename. One of:
1571
+
1572
+ * wx.FONTFAMILY_DEFAULT: Chooses a default font.
1573
+ * wx.FONTFAMILY_DECORATIVE: A decorative font.
1574
+ * wx.FONTFAMILY_ROMAN: A formal, serif font.
1575
+ * wx.FONTFAMILY_SCRIPT: A handwriting font.
1576
+ * wx.FONTFAMILY_SWISS: A sans-serif font.
1577
+ * wx.FONTFAMILY_MODERN: A fixed pitch font.
1578
+
1579
+ .. note:: these are only as good as the wxWindows defaults, which aren't so good.
1580
+
1581
+ * Style: One of wx.FONTSTYLE_NORMAL, wx.FONTSTYLE_SLANT and wx.FONTSTYLE_ITALIC.
1582
+ * Weight: One of wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_LIGHT and wx.FONTWEIGHT_BOLD.
1583
+ * Underlined: The value can be True or False. At present this may have an an
1584
+ effect on Windows only.
1585
+
1586
+
1587
+ Alternatively, you can set the kw arg: Font, to a wx.Font, and the
1588
+ above will be ignored. The size of the font you specify will be
1589
+ ignored, but the rest of its attributes will be preserved.
1590
+
1591
+ The size will scale as the drawing is zoomed.
1592
+
1593
+ Bugs/Limitations:
1594
+
1595
+ As fonts are scaled, the do end up a little different, so you don't
1596
+ get exactly the same picture as you scale up and done, but it's
1597
+ pretty darn close.
1598
+
1599
+ On wxGTK1 on my Linux system, at least, using a font of over about
1600
+ 3000 pts. brings the system to a halt. It's the Font Server using
1601
+ huge amounts of memory. My work around is to max the font size to
1602
+ 3000 points, so it won't scale past there. GTK2 uses smarter font
1603
+ drawing, so that may not be an issue in future versions, so feel
1604
+ free to test. Another smarter way to do it would be to set a global
1605
+ zoom limit at that point.
1606
+
1607
+ The hit-test is done on the entire text extent. This could be made
1608
+ optional, but I haven't gotten around to it.
1609
+
1610
+ """
1611
+
1612
+ def __init__(self,
1613
+ String,
1614
+ XY,
1615
+ Size,
1616
+ Color = "Black",
1617
+ BackgroundColor = None,
1618
+ Family = wx.FONTFAMILY_MODERN,
1619
+ Style = wx.FONTSTYLE_NORMAL,
1620
+ Weight = wx.FONTWEIGHT_NORMAL,
1621
+ Underlined = False,
1622
+ Position = 'tl',
1623
+ Font = None,
1624
+ InForeground = False):
1625
+
1626
+ DrawObject.__init__(self,InForeground)
1627
+
1628
+ self.String = String
1629
+ self.XY = np.array( XY, float)
1630
+ self.XY = self.XY.reshape((2,))
1631
+ self.Size = Size
1632
+ self.Color = Color
1633
+ self.BackgroundColor = BackgroundColor
1634
+ self.Family = Family
1635
+ self.Style = Style
1636
+ self.Weight = Weight
1637
+ self.Underlined = Underlined
1638
+ if not Font:
1639
+ self.FaceName = ''
1640
+ else:
1641
+ self.FaceName = Font.GetFaceName()
1642
+ self.Family = Font.GetFamily()
1643
+ self.Style = Font.GetStyle()
1644
+ self.Underlined = Font.GetUnderlined()
1645
+ self.Weight = Font.GetWeight()
1646
+
1647
+ # Experimental max font size value on wxGTK2: this works OK on
1648
+ # my system. If it's a lot larger, there is a crash, with the
1649
+ # message:
1650
+ #
1651
+ # The application 'FloatCanvasDemo.py' lost its
1652
+ # connection to the display :0.0; most likely the X server was
1653
+ # shut down or you killed/destroyed the application.
1654
+ #
1655
+ # Windows and OS-X seem to be better behaved in this regard.
1656
+ # They may not draw it, but they don't crash either!
1657
+ self.MaxFontSize = 1000
1658
+ self.MinFontSize = 1 # this can be changed to set a minimum size
1659
+ self.DisappearWhenSmall = True
1660
+ self.ShiftFun = self.ShiftFunDict[Position]
1661
+
1662
+ self.CalcBoundingBox()
1663
+
1664
+ def LayoutText(self):
1665
+ # This will be called when the text is re-set
1666
+ # nothing much to be done here
1667
+ self.CalcBoundingBox()
1668
+
1669
+ def CalcBoundingBox(self):
1670
+ ## this isn't exact, as fonts don't scale exactly.
1671
+ dc = wx.MemoryDC()
1672
+ bitmap = wx.Bitmap(1, 1)
1673
+ dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work.
1674
+ DrawingSize = 40 # pts This effectively determines the resolution that the BB is computed to.
1675
+ ScaleFactor = float(self.Size) / DrawingSize
1676
+ self.SetFont(DrawingSize, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName)
1677
+ dc.SetFont(self.Font)
1678
+ (w,h) = dc.GetTextExtent(self.String)
1679
+ w = w * ScaleFactor
1680
+ h = h * ScaleFactor
1681
+ x, y = self.ShiftFun(self.XY[0], self.XY[1], w, h, world = 1)
1682
+ self.BoundingBox = BBox.asBBox(((x, y-h ),(x + w, y)))
1683
+
1684
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1685
+ (X,Y) = WorldToPixel( (self.XY) )
1686
+
1687
+ # compute the font size:
1688
+ Size = abs( ScaleWorldToPixel( (self.Size, self.Size) )[1] ) # only need a y coordinate length
1689
+ ## Check to see if the font size is large enough to blow up the X font server
1690
+ ## If so, limit it. Would it be better just to not draw it?
1691
+ ## note that this limit is dependent on how much memory you have, etc.
1692
+ Size = min(Size, self.MaxFontSize)
1693
+ Size = max(Size, self.MinFontSize) # smallest size you want - default to 0
1694
+
1695
+ # Draw the Text
1696
+ if not( self.DisappearWhenSmall and Size <= self.MinFontSize) : # don't try to draw a zero sized font!
1697
+ self.SetFont(Size, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName)
1698
+ dc.SetFont(self.Font)
1699
+ dc.SetTextForeground(self.Color)
1700
+ if self.BackgroundColor:
1701
+ dc.SetBackgroundMode(wx.SOLID)
1702
+ dc.SetTextBackground(self.BackgroundColor)
1703
+ else:
1704
+ dc.SetBackgroundMode(wx.TRANSPARENT)
1705
+ (w,h) = dc.GetTextExtent(self.String)
1706
+ # compute the shift, and adjust the coordinates, if necessary
1707
+ # This had to be put in here, because it changes with Zoom, as
1708
+ # fonts don't scale exactly.
1709
+ xy = self.ShiftFun(X, Y, w, h)
1710
+ dc.DrawText(self.String, xy)
1711
+
1712
+ if HTdc and self.HitAble:
1713
+ HTdc.SetPen(self.HitPen)
1714
+ HTdc.SetBrush(self.HitBrush)
1715
+ HTdc.DrawRectangle(xy, (w, h))
1716
+
1717
+ class ScaledTextBox(TextObjectMixin, DrawObject):
1718
+ """
1719
+ Draws a text object
1720
+
1721
+ The object is scaled when zoomed.
1722
+
1723
+ The hit-test is done on the entire text extent
1724
+
1725
+ Bugs/Limitations:
1726
+
1727
+ As fonts are scaled, they do end up a little different, so you don't
1728
+ get exactly the same picture as you scale up and down, but it's
1729
+ pretty darn close.
1730
+
1731
+ On wxGTK1 on my Linux system, at least, using a font of over about
1732
+ 1000 pts. brings the system to a halt. It's the Font Server using
1733
+ huge amounts of memory. My work around is to max the font size to
1734
+ 1000 points, so it won't scale past there. GTK2 uses smarter font
1735
+ drawing, so that may not be an issue in future versions, so feel
1736
+ free to test. Another smarter way to do it would be to set a global
1737
+ zoom limit at that point.
1738
+
1739
+ """
1740
+
1741
+ def __init__(self, String,
1742
+ Point,
1743
+ Size,
1744
+ Color = "Black",
1745
+ BackgroundColor = None,
1746
+ LineColor = 'Black',
1747
+ LineStyle = 'Solid',
1748
+ LineWidth = 1,
1749
+ Width = None,
1750
+ PadSize = None,
1751
+ Family = wx.FONTFAMILY_MODERN,
1752
+ Style = wx.FONTSTYLE_NORMAL,
1753
+ Weight = wx.FONTWEIGHT_NORMAL,
1754
+ Underlined = False,
1755
+ Position = 'tl',
1756
+ Alignment = "left",
1757
+ Font = None,
1758
+ LineSpacing = 1.0,
1759
+ InForeground = False):
1760
+ """
1761
+ Default class constructor.
1762
+
1763
+ :param `Point`: takes a 2-tuple, or a (2,) `NumPy <http://www.numpy.org/>`_
1764
+ array of point coordinates
1765
+ :param integer `Size`: size in World units
1766
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1767
+ :param `BackgroundColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1768
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
1769
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
1770
+ :param `Width`: width in pixels or ``None``, text will be wrapped to
1771
+ the given width.
1772
+ :param `PadSize`: padding in world units or ``None``, if specified it
1773
+ will creating a space (margin) around the text
1774
+ :param wx.FontFamily `Family`: a valid :ref:`wx.FontFamily`
1775
+ :param wx.FontStyle `Style`: a valid :ref:`wx.FontStyle`
1776
+ :param wx.FontWeight `Weight`: a valid :ref:`wx.FontWeight`
1777
+ :param boolean `Underlined`: underline the text
1778
+ :param string `Position`: a two character string indicating where in
1779
+ relation to the coordinates the box should be oriented
1780
+
1781
+ ============== ==========================
1782
+ 1st character Meaning
1783
+ ============== ==========================
1784
+ ``t`` top
1785
+ ``c`` center
1786
+ ``b`` bottom
1787
+ ============== ==========================
1788
+
1789
+ ============== ==========================
1790
+ 2nd character Meaning
1791
+ ============== ==========================
1792
+ ``l`` left
1793
+ ``c`` center
1794
+ ``r`` right
1795
+ ============== ==========================
1796
+
1797
+ :param `Alignment`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
1798
+ :param wx.Font `Font`: alternatively a valid :class:`wx.Font` can be defined
1799
+ in which case the above will be ignored
1800
+ :param float `LineSpacing`: the line space to be used
1801
+ :param boolean `InForeground`: should object be in foreground
1802
+
1803
+ """
1804
+ DrawObject.__init__(self,InForeground)
1805
+
1806
+ self.XY = np.array(Point, float)
1807
+ self.Size = Size
1808
+ self.Color = Color
1809
+ self.BackgroundColor = BackgroundColor
1810
+ self.LineColor = LineColor
1811
+ self.LineStyle = LineStyle
1812
+ self.LineWidth = LineWidth
1813
+ self.Width = Width
1814
+ if PadSize is None: # the default is just a little bit of padding
1815
+ self.PadSize = Size/10.0
1816
+ else:
1817
+ self.PadSize = float(PadSize)
1818
+ self.Family = Family
1819
+ self.Style = Style
1820
+ self.Weight = Weight
1821
+ self.Underlined = Underlined
1822
+ self.Alignment = Alignment.lower()
1823
+ self.LineSpacing = float(LineSpacing)
1824
+ self.Position = Position
1825
+
1826
+ if not Font:
1827
+ self.FaceName = ''
1828
+ else:
1829
+ self.FaceName = Font.GetFaceName()
1830
+ self.Family = Font.GetFamily()
1831
+ self.Style = Font.GetStyle()
1832
+ self.Underlined = Font.GetUnderlined()
1833
+ self.Weight = Font.GetWeight()
1834
+
1835
+ # Experimental max font size value on wxGTK2: this works OK on
1836
+ # my system. If it's a lot larger, there is a crash, with the
1837
+ # message:
1838
+ #
1839
+ # The application 'FloatCanvasDemo.py' lost its
1840
+ # connection to the display :0.0; most likely the X server was
1841
+ # shut down or you killed/destroyed the application.
1842
+ #
1843
+ # Windows and OS-X seem to be better behaved in this regard.
1844
+ # They may not draw it, but they don't crash either!
1845
+
1846
+ self.MaxFontSize = 1000
1847
+ self.MinFontSize = 1 # this can be changed to set a larger minimum size
1848
+ self.DisappearWhenSmall = True
1849
+
1850
+ self.ShiftFun = self.ShiftFunDict[Position]
1851
+
1852
+ self.String = String
1853
+ self.LayoutText()
1854
+ self.CalcBoundingBox()
1855
+
1856
+ self.SetPen(LineColor,LineStyle,LineWidth)
1857
+ self.SetBrush(BackgroundColor, "Solid")
1858
+
1859
+
1860
+ def WrapToWidth(self):
1861
+ dc = wx.MemoryDC()
1862
+ bitmap = wx.Bitmap(1, 1)
1863
+ dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work.
1864
+ DrawingSize = self.LayoutFontSize # pts This effectively determines the resolution that the BB is computed to.
1865
+ ScaleFactor = float(self.Size) / DrawingSize
1866
+ Width = (self.Width - 2*self.PadSize) / ScaleFactor #Width to wrap to
1867
+ self.SetFont(DrawingSize, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName)
1868
+ dc.SetFont(self.Font)
1869
+ NewStrings = []
1870
+ for s in self.Strings:
1871
+ #beginning = True
1872
+ text = s.split(" ")
1873
+ text.reverse()
1874
+ LineLength = 0
1875
+ NewText = text[-1]
1876
+ del text[-1]
1877
+ while text:
1878
+ w = dc.GetTextExtent(' ' + text[-1])[0]
1879
+ if LineLength + w <= Width:
1880
+ NewText += ' '
1881
+ NewText += text[-1]
1882
+ LineLength = dc.GetTextExtent(NewText)[0]
1883
+ else:
1884
+ NewStrings.append(NewText)
1885
+ NewText = text[-1]
1886
+ LineLength = dc.GetTextExtent(text[-1])[0]
1887
+ del text[-1]
1888
+ NewStrings.append(NewText)
1889
+ self.Strings = NewStrings
1890
+
1891
+ def ReWrap(self, Width):
1892
+ self.Width = Width
1893
+ self.LayoutText()
1894
+
1895
+ def LayoutText(self):
1896
+ """
1897
+ Calculates the positions of the words of text.
1898
+
1899
+ This isn't exact, as fonts don't scale exactly.
1900
+ To help this, the position of each individual word
1901
+ is stored separately, so that the general layout stays
1902
+ the same in world coordinates, as the fonts scale.
1903
+
1904
+ """
1905
+ self.Strings = self.String.split("\n")
1906
+ if self.Width:
1907
+ self.WrapToWidth()
1908
+
1909
+ dc = wx.MemoryDC()
1910
+ bitmap = wx.Bitmap(1, 1)
1911
+ dc.SelectObject(bitmap) #wxMac needs a Bitmap selected for GetTextExtent to work.
1912
+
1913
+ DrawingSize = self.LayoutFontSize # pts This effectively determines the resolution that the BB is computed to.
1914
+ ScaleFactor = float(self.Size) / DrawingSize
1915
+
1916
+ self.SetFont(DrawingSize, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName)
1917
+ dc.SetFont(self.Font)
1918
+ TextHeight = dc.GetTextExtent("X")[1]
1919
+ SpaceWidth = dc.GetTextExtent(" ")[0]
1920
+ LineHeight = TextHeight * self.LineSpacing
1921
+
1922
+ LineWidths = np.zeros((len(self.Strings),), float)
1923
+ y = 0
1924
+ Words = []
1925
+ AllLinePoints = []
1926
+
1927
+ for i, s in enumerate(self.Strings):
1928
+ LineWidths[i] = 0
1929
+ LineWords = s.split(" ")
1930
+ LinePoints = np.zeros((len(LineWords),2), float)
1931
+ for j, word in enumerate(LineWords):
1932
+ if j > 0:
1933
+ LineWidths[i] += SpaceWidth
1934
+ Words.append(word)
1935
+ LinePoints[j] = (LineWidths[i], y)
1936
+ w = dc.GetTextExtent(word)[0]
1937
+ LineWidths[i] += w
1938
+ y -= LineHeight
1939
+ AllLinePoints.append(LinePoints)
1940
+ TextWidth = np.maximum.reduce(LineWidths)
1941
+ self.Words = Words
1942
+
1943
+ if self.Width is None:
1944
+ BoxWidth = TextWidth * ScaleFactor + 2*self.PadSize
1945
+ else: # use the defined Width
1946
+ BoxWidth = self.Width
1947
+ Points = np.zeros((0,2), float)
1948
+
1949
+ for i, LinePoints in enumerate(AllLinePoints):
1950
+ ## Scale to World Coords.
1951
+ LinePoints *= (ScaleFactor, ScaleFactor)
1952
+ if self.Alignment == 'left':
1953
+ LinePoints[:,0] += self.PadSize
1954
+ elif self.Alignment == 'center':
1955
+ LinePoints[:,0] += (BoxWidth - LineWidths[i]*ScaleFactor)/2.0
1956
+ elif self.Alignment == 'right':
1957
+ LinePoints[:,0] += (BoxWidth - LineWidths[i]*ScaleFactor-self.PadSize)
1958
+ Points = np.concatenate((Points, LinePoints))
1959
+
1960
+ BoxHeight = -(Points[-1,1] - (TextHeight * ScaleFactor)) + 2*self.PadSize
1961
+ #(x,y) = self.ShiftFun(self.XY[0], self.XY[1], BoxWidth, BoxHeight, world=1)
1962
+ Points += (0, -self.PadSize)
1963
+ self.Points = Points
1964
+ self.BoxWidth = BoxWidth
1965
+ self.BoxHeight = BoxHeight
1966
+ self.CalcBoundingBox()
1967
+
1968
+ def CalcBoundingBox(self):
1969
+ """Calculates the Bounding Box"""
1970
+ w, h = self.BoxWidth, self.BoxHeight
1971
+ x, y = self.ShiftFun(self.XY[0], self.XY[1], w, h, world=1)
1972
+ self.BoundingBox = BBox.asBBox(((x, y-h ),(x + w, y)))
1973
+
1974
+ def GetBoxRect(self):
1975
+ wh = (self.BoxWidth, self.BoxHeight)
1976
+ xy = (self.BoundingBox[0,0], self.BoundingBox[1,1])
1977
+
1978
+ return (xy, wh)
1979
+
1980
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
1981
+ xy, wh = self.GetBoxRect()
1982
+
1983
+ Points = self.Points + xy
1984
+ Points = WorldToPixel(Points)
1985
+ xy = WorldToPixel(xy)
1986
+ wh = ScaleWorldToPixel(wh) * (1,-1)
1987
+
1988
+ # compute the font size:
1989
+ Size = abs( ScaleWorldToPixel( (self.Size, self.Size) )[1] ) # only need a y coordinate length
1990
+ ## Check to see if the font size is large enough to blow up the X font server
1991
+ ## If so, limit it. Would it be better just to not draw it?
1992
+ ## note that this limit is dependent on how much memory you have, etc.
1993
+ Size = min(Size, self.MaxFontSize)
1994
+
1995
+ Size = max(Size, self.MinFontSize) # smallest size you want - default to 1
1996
+
1997
+ # Draw The Box
1998
+ if (self.LineStyle and self.LineColor) or self.BackgroundColor:
1999
+ dc.SetBrush(self.Brush)
2000
+ dc.SetPen(self.Pen)
2001
+ dc.DrawRectangle(xy , wh)
2002
+
2003
+ # Draw the Text
2004
+ if not( self.DisappearWhenSmall and Size <= self.MinFontSize) : # don't try to draw a zero sized font!
2005
+ self.SetFont(Size, self.Family, self.Style, self.Weight, self.Underlined, self.FaceName)
2006
+ dc.SetFont(self.Font)
2007
+ dc.SetTextForeground(self.Color)
2008
+ dc.SetBackgroundMode(wx.TRANSPARENT)
2009
+ dc.DrawTextList(self.Words, Points)
2010
+
2011
+ # Draw the hit box.
2012
+ if HTdc and self.HitAble:
2013
+ HTdc.SetPen(self.HitPen)
2014
+ HTdc.SetBrush(self.HitBrush)
2015
+ HTdc.DrawRectangle(xy, wh)
2016
+
2017
+ class Bitmap(TextObjectMixin, DrawObject):
2018
+ """
2019
+ Draws a bitmap
2020
+
2021
+ The size is fixed, and does not scale with the drawing.
2022
+
2023
+ """
2024
+
2025
+ def __init__(self, Bitmap, XY,
2026
+ Position='tl',
2027
+ InForeground=False):
2028
+ """
2029
+ Default class constructor.
2030
+
2031
+ :param wx.Bitmap `Bitmap`: the bitmap to be drawn
2032
+ :param `XY`: the (x, y) coordinate of the corner of the bitmap, or a 2-tuple,
2033
+ or a (2,) `NumPy <http://www.numpy.org/>`_ array
2034
+ :param string `Position`: a two character string indicating where in relation to the coordinates
2035
+ the bitmap should be oriented
2036
+
2037
+ ============== ==========================
2038
+ 1st character Meaning
2039
+ ============== ==========================
2040
+ ``t`` top
2041
+ ``c`` center
2042
+ ``b`` bottom
2043
+ ============== ==========================
2044
+
2045
+ ============== ==========================
2046
+ 2nd character Meaning
2047
+ ============== ==========================
2048
+ ``l`` left
2049
+ ``c`` center
2050
+ ``r`` right
2051
+ ============== ==========================
2052
+
2053
+ :param boolean `InForeground`: should object be in foreground
2054
+
2055
+ """
2056
+
2057
+ DrawObject.__init__(self,InForeground)
2058
+
2059
+ if type(Bitmap) == wx.Bitmap:
2060
+ self.Bitmap = Bitmap
2061
+ elif type(Bitmap) == wx.Image:
2062
+ self.Bitmap = wx.Bitmap(Bitmap)
2063
+
2064
+ # Note the BB is just the point, as the size in World coordinates is not fixed
2065
+ self.BoundingBox = BBox.asBBox( (XY,XY) )
2066
+
2067
+ self.XY = XY
2068
+
2069
+ (self.Width, self.Height) = self.Bitmap.GetWidth(), self.Bitmap.GetHeight()
2070
+ self.ShiftFun = self.ShiftFunDict[Position]
2071
+
2072
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
2073
+ XY = WorldToPixel(self.XY)
2074
+ XY = self.ShiftFun(XY[0], XY[1], self.Width, self.Height)
2075
+ dc.DrawBitmap(self.Bitmap, XY, True)
2076
+ if HTdc and self.HitAble:
2077
+ HTdc.SetPen(self.HitPen)
2078
+ HTdc.SetBrush(self.HitBrush)
2079
+ HTdc.DrawRectangle(XY, (self.Width, self.Height) )
2080
+
2081
+ class ScaledBitmap(TextObjectMixin, DrawObject):
2082
+ """
2083
+ Draws a scaled bitmap
2084
+
2085
+ The size scales with the drawing
2086
+
2087
+ """
2088
+
2089
+ def __init__(self,
2090
+ Bitmap,
2091
+ XY,
2092
+ Height,
2093
+ Position = 'tl',
2094
+ InForeground = False):
2095
+ """
2096
+ Default class constructor.
2097
+
2098
+ :param wx.Bitmap `Bitmap`: the bitmap to be drawn
2099
+ :param `XY`: the (x, y) coordinate of the corner of the scaled bitmap,
2100
+ or a 2-tuple, or a (2,) `NumPy <http://www.numpy.org/>`_ array
2101
+ :param `Height`: height to be used, width is calculated from the aspect ratio of the bitmap
2102
+ :param string `Position`: a two character string indicating where in relation to the coordinates
2103
+ the bitmap should be oriented
2104
+
2105
+ ============== ==========================
2106
+ 1st character Meaning
2107
+ ============== ==========================
2108
+ ``t`` top
2109
+ ``c`` center
2110
+ ``b`` bottom
2111
+ ============== ==========================
2112
+
2113
+ ============== ==========================
2114
+ 2nd character Meaning
2115
+ ============== ==========================
2116
+ ``l`` left
2117
+ ``c`` center
2118
+ ``r`` right
2119
+ ============== ==========================
2120
+
2121
+ :param boolean `InForeground`: should object be in foreground
2122
+
2123
+ """
2124
+
2125
+ DrawObject.__init__(self,InForeground)
2126
+
2127
+ if type(Bitmap) == wx.Bitmap:
2128
+ self.Image = Bitmap.ConvertToImage()
2129
+ elif type(Bitmap) == wx.Image:
2130
+ self.Image = Bitmap
2131
+ else:
2132
+ raise ValueError("'Bitmap' must be a wx.Bitmap or wx.Image object not %s" % type(Bitmap))
2133
+
2134
+ self.XY = XY
2135
+ self.Height = Height
2136
+ (self.bmpWidth, self.bmpHeight) = float(self.Image.GetWidth()), float(self.Image.GetHeight())
2137
+ self.Width = self.bmpWidth / self.bmpHeight * Height
2138
+ self.ShiftFun = self.ShiftFunDict[Position]
2139
+ self.CalcBoundingBox()
2140
+ self.ScaledBitmap = None
2141
+ self.ScaledHeight = None
2142
+ self.MaxSize = 20e6 # cf. FHD 1,920 x 1,080
2143
+
2144
+ def CalcBoundingBox(self):
2145
+ """Calculate the bounding box."""
2146
+ ## this isn't exact, as fonts don't scale exactly.
2147
+ w, h = self.Width, self.Height
2148
+ x, y = self.ShiftFun(self.XY[0], self.XY[1], w, h, world = 1)
2149
+ self.BoundingBox = BBox.asBBox( ( (x, y-h ), (x + w, y) ) )
2150
+
2151
+
2152
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
2153
+ XY = WorldToPixel(self.XY)
2154
+ H = ScaleWorldToPixel(self.Height)[0]
2155
+ W = int(H * (self.bmpWidth / self.bmpHeight))
2156
+ XY = self.ShiftFun(XY[0], XY[1], W, H)
2157
+ if 0 < H * float(W) < self.MaxSize:
2158
+ if (self.ScaledBitmap is None) or (H != self.ScaledHeight):
2159
+ Img = self.Image.Scale(W, H)
2160
+ self.ScaledHeight = H
2161
+ self.ScaledBitmap = wx.Bitmap(Img)
2162
+ dc.DrawBitmap(self.ScaledBitmap, XY, True)
2163
+ else:
2164
+ gc = wx.GraphicsContext.Create(dc)
2165
+ gc.DrawBitmap(self.ScaledBitmap, *XY, W, H)
2166
+ if HTdc and self.HitAble:
2167
+ HTdc.SetPen(self.HitPen)
2168
+ HTdc.SetBrush(self.HitBrush)
2169
+ HTdc.DrawRectangle(XY, (W, H) )
2170
+
2171
+ class ScaledBitmap2(TextObjectMixin, DrawObject, ):
2172
+ """
2173
+ Draws a scaled bitmap
2174
+
2175
+ An alternative scaled bitmap that only scaled the required amount of
2176
+ the main bitmap when zoomed in: EXPERIMENTAL!
2177
+
2178
+ """
2179
+
2180
+ def __init__(self,
2181
+ Bitmap,
2182
+ XY,
2183
+ Height,
2184
+ Width=None,
2185
+ Position = 'tl',
2186
+ InForeground = False):
2187
+ """
2188
+ Default class constructor.
2189
+
2190
+ :param wx.Bitmap `Bitmap`: the bitmap to be drawn
2191
+ :param `XY`: the (x, y) coordinate of the corner of the scaled bitmap,
2192
+ or a 2-tuple, or a (2,) `NumPy <http://www.numpy.org/>`_ array
2193
+ :param `Height`: height to be used
2194
+ :param `Width`: width to be used, if ``None`` width is calculated from the aspect ratio of the bitmap
2195
+ :param string `Position`: a two character string indicating where in relation to the coordinates
2196
+ the bitmap should be oriented
2197
+
2198
+ ============== ==========================
2199
+ 1st character Meaning
2200
+ ============== ==========================
2201
+ ``t`` top
2202
+ ``c`` center
2203
+ ``b`` bottom
2204
+ ============== ==========================
2205
+
2206
+ ============== ==========================
2207
+ 2nd character Meaning
2208
+ ============== ==========================
2209
+ ``l`` left
2210
+ ``c`` center
2211
+ ``r`` right
2212
+ ============== ==========================
2213
+
2214
+ :param boolean `InForeground`: should object be in foreground
2215
+
2216
+ """
2217
+
2218
+ DrawObject.__init__(self,InForeground)
2219
+
2220
+ if type(Bitmap) == wx.Bitmap:
2221
+ self.Image = Bitmap.ConvertToImage()
2222
+ elif type(Bitmap) == wx.Image:
2223
+ self.Image = Bitmap
2224
+
2225
+ self.XY = np.array(XY, float)
2226
+ self.Height = Height
2227
+ (self.bmpWidth, self.bmpHeight) = float(self.Image.GetWidth()), float(self.Image.GetHeight())
2228
+ self.bmpWH = np.array((self.bmpWidth, self.bmpHeight), np.int32)
2229
+ ## fixme: this should all accommodate different scales for X and Y
2230
+ if Width is None:
2231
+ self.BmpScale = float(self.bmpHeight) / Height
2232
+ self.Width = self.bmpWidth / self.BmpScale
2233
+ self.WH = np.array((self.Width, Height), float)
2234
+ ##fixme: should this have a y = -1 to shift to y-up?
2235
+ self.BmpScale = self.bmpWH / self.WH
2236
+
2237
+ #print("bmpWH:", self.bmpWH)
2238
+ #print("Width, Height:", self.WH)
2239
+ #print("self.BmpScale", self.BmpScale)
2240
+ self.ShiftFun = self.ShiftFunDict[Position]
2241
+ self.CalcBoundingBox()
2242
+ self.ScaledBitmap = None # cache of the last existing scaled bitmap
2243
+
2244
+ def CalcBoundingBox(self):
2245
+ """Calculate the bounding box."""
2246
+ ## this isn't exact, as fonts don't scale exactly.
2247
+ w,h = self.Width, self.Height
2248
+ x, y = self.ShiftFun(self.XY[0], self.XY[1], w, h, world = 1)
2249
+ self.BoundingBox = BBox.asBBox( ((x, y-h ), (x + w, y)) )
2250
+
2251
+ def WorldToBitmap(self, Pw):
2252
+ """Computes the bitmap coords from World coords."""
2253
+ delta = Pw - self.XY
2254
+ Pb = delta * self.BmpScale
2255
+ Pb *= (1, -1) ##fixme: this may only works for Yup projection!
2256
+ ## and may only work for top left position
2257
+
2258
+ return Pb.astype(np.int_)
2259
+
2260
+ def _DrawEntireBitmap(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc):
2261
+ """
2262
+ this is pretty much the old code
2263
+
2264
+ Scales and Draws the entire bitmap.
2265
+
2266
+ """
2267
+ XY = WorldToPixel(self.XY)
2268
+ H = ScaleWorldToPixel(self.Height)[0]
2269
+ W = int(H * (self.bmpWidth / self.bmpHeight))
2270
+ if (self.ScaledBitmap is None) or (self.ScaledBitmap[0] != (0, 0, self.bmpWidth, self.bmpHeight, W, H) ):
2271
+ #if True: #fixme: (self.ScaledBitmap is None) or (H != self.ScaledHeight) :
2272
+ self.ScaledHeight = H
2273
+ #print("Scaling to:", W, H)
2274
+ Img = self.Image.Scale(W, H)
2275
+ bmp = wx.Bitmap(Img)
2276
+ self.ScaledBitmap = ((0, 0, self.bmpWidth, self.bmpHeight , W, H), bmp)# this defines the cached bitmap
2277
+ else:
2278
+ #print("Using Cached bitmap")
2279
+ bmp = self.ScaledBitmap[1]
2280
+ XY = self.ShiftFun(XY[0], XY[1], W, H)
2281
+ dc.DrawBitmap(bmp, XY, True)
2282
+ if HTdc and self.HitAble:
2283
+ HTdc.SetPen(self.HitPen)
2284
+ HTdc.SetBrush(self.HitBrush)
2285
+ HTdc.DrawRectangle(XY, (W, H) )
2286
+
2287
+ def _DrawSubBitmap(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc):
2288
+ """
2289
+ Subsets just the part of the bitmap that is visible
2290
+ then scales and draws that.
2291
+
2292
+ """
2293
+ BBworld = BBox.asBBox(self._Canvas.ViewPortBB)
2294
+ BBbitmap = BBox.fromPoints(self.WorldToBitmap(BBworld))
2295
+
2296
+ XYs = WorldToPixel(self.XY)
2297
+ # figure out subimage:
2298
+ # fixme: this should be able to be done more succinctly!
2299
+
2300
+ if BBbitmap[0,0] < 0:
2301
+ Xb = 0
2302
+ elif BBbitmap[0,0] > self.bmpWH[0]: # off the bitmap
2303
+ Xb = 0
2304
+ else:
2305
+ Xb = BBbitmap[0,0]
2306
+ XYs[0] = 0 # draw at origin
2307
+
2308
+ if BBbitmap[0,1] < 0:
2309
+ Yb = 0
2310
+ elif BBbitmap[0,1] > self.bmpWH[1]: # off the bitmap
2311
+ Yb = 0
2312
+ ShouldDraw = False
2313
+ else:
2314
+ Yb = BBbitmap[0,1]
2315
+ XYs[1] = 0 # draw at origin
2316
+
2317
+ if BBbitmap[1,0] < 0:
2318
+ #off the screen -- This should never happen!
2319
+ Wb = 0
2320
+ elif BBbitmap[1,0] > self.bmpWH[0]:
2321
+ Wb = self.bmpWH[0] - Xb
2322
+ else:
2323
+ Wb = BBbitmap[1,0] - Xb
2324
+
2325
+ if BBbitmap[1,1] < 0:
2326
+ # off the screen -- This should never happen!
2327
+ Hb = 0
2328
+ ShouldDraw = False
2329
+ elif BBbitmap[1,1] > self.bmpWH[1]:
2330
+ Hb = self.bmpWH[1] - Yb
2331
+ else:
2332
+ Hb = BBbitmap[1,1] - Yb
2333
+
2334
+ FullHeight = ScaleWorldToPixel(self.Height)[0]
2335
+ scale = float(FullHeight) / float(self.bmpWH[1])
2336
+ Ws = int(scale * Wb + 0.5) # add the 0.5 to round
2337
+ Hs = int(scale * Hb + 0.5)
2338
+ if (self.ScaledBitmap is None) or (self.ScaledBitmap[0] != (Xb, Yb, Wb, Hb, Ws, Ws) ):
2339
+ Img = self.Image.GetSubImage(wx.Rect(Xb, Yb, Wb, Hb))
2340
+ #print("rescaling with High quality")
2341
+ Img.Rescale(Ws, Hs, quality=wx.IMAGE_QUALITY_HIGH)
2342
+ bmp = wx.Bitmap(Img)
2343
+ self.ScaledBitmap = ((Xb, Yb, Wb, Hb, Ws, Ws), bmp)# this defines the cached bitmap
2344
+ #XY = self.ShiftFun(XY[0], XY[1], W, H)
2345
+ #fixme: get the shiftfun working!
2346
+ else:
2347
+ #print("Using cached bitmap")
2348
+ ##fixme: The cached bitmap could be used if the one needed is the same scale, but
2349
+ ## a subset of the cached one.
2350
+ bmp = self.ScaledBitmap[1]
2351
+ dc.DrawBitmap(bmp, XYs, True)
2352
+
2353
+ if HTdc and self.HitAble:
2354
+ HTdc.SetPen(self.HitPen)
2355
+ HTdc.SetBrush(self.HitBrush)
2356
+ HTdc.DrawRectangle(XYs, (Ws, Hs) )
2357
+
2358
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
2359
+ BBworld = BBox.asBBox(self._Canvas.ViewPortBB)
2360
+ ## first see if entire bitmap is displayed:
2361
+ if BBworld.Inside(self.BoundingBox):
2362
+ #print("Drawing entire bitmap with old code")
2363
+ self._DrawEntireBitmap(dc , WorldToPixel, ScaleWorldToPixel, HTdc)
2364
+ return None
2365
+ elif BBworld.Overlaps(self.BoundingBox):
2366
+ #BBbitmap = BBox.fromPoints(self.WorldToBitmap(BBworld))
2367
+ #print("Drawing a sub-bitmap")
2368
+ self._DrawSubBitmap(dc , WorldToPixel, ScaleWorldToPixel, HTdc)
2369
+ else:
2370
+ #print("Not Drawing -- no part of image is showing")
2371
+ pass
2372
+
2373
+ class DotGrid:
2374
+ """
2375
+ An example of a Grid Object -- it is set on the FloatCanvas with one of::
2376
+
2377
+ FloatCanvas.GridUnder = Grid
2378
+ FloatCanvas.GridOver = Grid
2379
+
2380
+ It will be drawn every time, regardless of the viewport.
2381
+
2382
+ In its _Draw method, it computes what to draw, given the ViewPortBB
2383
+ of the Canvas it's being drawn on.
2384
+
2385
+ """
2386
+ def __init__(self, Spacing, Size = 2, Color = "Black", Cross=False, CrossThickness = 1):
2387
+
2388
+ self.Spacing = np.array(Spacing, float)
2389
+ self.Spacing = self.Spacing.reshape((2,))
2390
+ self.Size = Size
2391
+ self.Color = Color
2392
+ self.Cross = Cross
2393
+ self.CrossThickness = CrossThickness
2394
+
2395
+ def CalcPoints(self, Canvas):
2396
+ ViewPortBB = Canvas.ViewPortBB
2397
+
2398
+ Spacing = self.Spacing
2399
+
2400
+ minx, miny = np.floor(ViewPortBB[0] / Spacing) * Spacing
2401
+ maxx, maxy = np.ceil(ViewPortBB[1] / Spacing) * Spacing
2402
+
2403
+ ##fixme: this could use vstack or something with numpy
2404
+ x = np.arange(minx, maxx+Spacing[0], Spacing[0]) # making sure to get the last point
2405
+ y = np.arange(miny, maxy+Spacing[1], Spacing[1]) # an extra is OK
2406
+ Points = np.zeros((len(y), len(x), 2), float)
2407
+ x = x.reshape((1,-1))
2408
+ y = y.reshape((-1,1))
2409
+ Points[:,:,0] += x
2410
+ Points[:,:,1] += y
2411
+ Points = Points.reshape((-1,2))
2412
+
2413
+ return Points
2414
+
2415
+ def _Draw(self, dc, Canvas):
2416
+ Points = self.CalcPoints(Canvas)
2417
+
2418
+ Points = Canvas.WorldToPixel(Points)
2419
+
2420
+ dc.SetPen(wx.Pen(self.Color,self.CrossThickness))
2421
+
2422
+ if self.Cross: # Use cross shaped markers
2423
+ #Horizontal lines
2424
+ LinePoints = np.concatenate((Points + (self.Size,0),Points + (-self.Size,0)),1)
2425
+ dc.DrawLineList(LinePoints)
2426
+ # Vertical Lines
2427
+ LinePoints = np.concatenate((Points + (0,self.Size),Points + (0,-self.Size)),1)
2428
+ dc.DrawLineList(LinePoints)
2429
+ pass
2430
+ else: # use dots
2431
+ ## Note: this code borrowed from Pointset -- it really shouldn't be repeated here!.
2432
+ if self.Size <= 1:
2433
+ dc.DrawPointList(Points)
2434
+ elif self.Size <= 2:
2435
+ dc.DrawPointList(Points + (0,-1))
2436
+ dc.DrawPointList(Points + (0, 1))
2437
+ dc.DrawPointList(Points + (1, 0))
2438
+ dc.DrawPointList(Points + (-1,0))
2439
+ else:
2440
+ dc.SetBrush(wx.Brush(self.Color))
2441
+ radius = int(round(self.Size/2))
2442
+ ##fixme: I really should add a DrawCircleList to wxPython
2443
+ if len(Points) > 100:
2444
+ xy = Points
2445
+ xywh = np.concatenate((xy-radius, np.ones(xy.shape) * self.Size ), 1 )
2446
+ dc.DrawEllipseList(xywh.astype(int))
2447
+ else:
2448
+ for xy in Points:
2449
+ dc.DrawCircle(xy[0],xy[1], radius)
2450
+
2451
+ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject):
2452
+ """
2453
+ Draws an arc of a circle, centered on point ``CenterXY``, from
2454
+ the first point ``StartXY`` to the second ``EndXY``.
2455
+
2456
+ The arc is drawn in an anticlockwise direction from the start point to
2457
+ the end point.
2458
+
2459
+ """
2460
+ def __init__(self,
2461
+ StartXY,
2462
+ EndXY,
2463
+ CenterXY,
2464
+ LineColor = "Black",
2465
+ LineStyle = "Solid",
2466
+ LineWidth = 1,
2467
+ FillColor = None,
2468
+ FillStyle = "Solid",
2469
+ InForeground = False):
2470
+ """
2471
+ Default class constructor.
2472
+
2473
+ :param `StartXY`: start point, takes a 2-tuple, or a (2,)
2474
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
2475
+ :param `EndXY`: end point, takes a 2-tuple, or a (2,)
2476
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
2477
+ :param `CenterXY`: center point, takes a 2-tuple, or a (2,)
2478
+ `NumPy <http://www.numpy.org/>`_ array of point coordinates
2479
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
2480
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
2481
+ :param `LineWidth`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineWidth`
2482
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
2483
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
2484
+ :param boolean `InForeground`: should object be in foreground
2485
+
2486
+ """
2487
+
2488
+ DrawObject.__init__(self, InForeground)
2489
+
2490
+ # There is probably a more elegant way to do this next section
2491
+ # The bounding box just gets set to the WH of a circle, with center at CenterXY
2492
+ # This is suitable for a pie chart as it will be a circle anyway
2493
+ radius = np.sqrt( (StartXY[0]-CenterXY[0])**2 + (StartXY[1]-CenterXY[1])**2 )
2494
+ minX = CenterXY[0]-radius
2495
+ minY = CenterXY[1]-radius
2496
+ maxX = CenterXY[0]+radius
2497
+ maxY = CenterXY[1]+radius
2498
+ XY = [minX,minY]
2499
+ WH = [maxX-minX,maxY-minY]
2500
+
2501
+ self.XY = np.asarray( XY, float).reshape((2,))
2502
+ self.WH = np.asarray( WH, float).reshape((2,))
2503
+
2504
+ self.StartXY = np.asarray(StartXY, float).reshape((2,))
2505
+ self.CenterXY = np.asarray(CenterXY, float).reshape((2,))
2506
+ self.EndXY = np.asarray(EndXY, float).reshape((2,))
2507
+
2508
+ #self.BoundingBox = array((self.XY, (self.XY + self.WH)), Float)
2509
+ self.CalcBoundingBox()
2510
+
2511
+ #Finish the setup; allocate color,style etc.
2512
+ self.LineColor = LineColor
2513
+ self.LineStyle = LineStyle
2514
+ self.LineWidth = LineWidth
2515
+ self.FillColor = FillColor
2516
+ self.FillStyle = FillStyle
2517
+
2518
+ self.HitLineWidth = max(LineWidth,self.MinHitLineWidth)
2519
+
2520
+ self.SetPen(LineColor, LineStyle, LineWidth)
2521
+ self.SetBrush(FillColor, FillStyle) #Why isn't this working ???
2522
+
2523
+ def Move(self, Delta):
2524
+ """
2525
+ Move the object by delta
2526
+
2527
+ :param `Delta`: delta is a (dx, dy) pair. Ideally a `NumPy <http://www.numpy.org/>`_
2528
+ array of shape (2,)
2529
+
2530
+ """
2531
+
2532
+ Delta = np.asarray(Delta, float)
2533
+ self.XY += Delta
2534
+ self.StartXY += Delta
2535
+ self.CenterXY += Delta
2536
+ self.EndXY += Delta
2537
+ self.BoundingBox += Delta
2538
+
2539
+ if self._Canvas:
2540
+ self._Canvas.BoundingBoxDirty = True
2541
+
2542
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
2543
+ self.SetUpDraw(dc , WorldToPixel, ScaleWorldToPixel, HTdc)
2544
+ StartXY = WorldToPixel(self.StartXY)
2545
+ EndXY = WorldToPixel(self.EndXY)
2546
+ CenterXY = WorldToPixel(self.CenterXY)
2547
+
2548
+ dc.DrawArc(StartXY, EndXY, CenterXY)
2549
+ if HTdc and self.HitAble:
2550
+ HTdc.DrawArc(StartXY, EndXY, CenterXY)
2551
+
2552
+ def CalcBoundingBox(self):
2553
+ """Calculate the bounding box."""
2554
+ self.BoundingBox = BBox.asBBox( np.array((self.XY, (self.XY + self.WH) ),
2555
+ float) )
2556
+ if self._Canvas:
2557
+ self._Canvas.BoundingBoxDirty = True
2558
+
2559
+
2560
+ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject):
2561
+ """
2562
+ This is DrawObject for a pie chart
2563
+
2564
+ You can pass in a bunch of values, and it will draw a pie chart for
2565
+ you, and it will make the chart, scaling the size of each "slice" to
2566
+ match your values.
2567
+ """
2568
+
2569
+ ##fixme: this should be a longer and better designed set.
2570
+ ## Maybe one from: http://geography.uoregon.edu/datagraphics/color_scales.htm
2571
+ DefaultColorList = Colors.CategoricalColor1
2572
+ #["Red", "Green", "Blue", "Purple", "Yellow", "Cyan"]
2573
+
2574
+ def __init__(self,
2575
+ XY,
2576
+ Diameter,
2577
+ Values,
2578
+ FillColors=None,
2579
+ FillStyles=None,
2580
+ LineColor = None,
2581
+ LineStyle = "Solid",
2582
+ LineWidth = 1,
2583
+ Scaled = True,
2584
+ InForeground = False):
2585
+ """
2586
+ Default class constructor.
2587
+
2588
+ :param `XY`: The (x,y) coords of the center of the chart
2589
+ :param `Diameter`: The diameter of the chart in world coords, unless you
2590
+ set "Scaled" to False, in which case it's in pixel coords.
2591
+ :param `Values`: sequence of values you want to make the chart of.
2592
+ :param `FillColors`: sequence of colors you want the slices. If
2593
+ None, it will choose (no guarantee you'll like them!)
2594
+ :param `FillStyles`: Fill style you want ("Solid", "Hash", etc)
2595
+ :param `LineColor`: Color of lines separating the slices
2596
+ :param `LineStyle`: style of lines separating the slices
2597
+ :param `LineWidth`: With of lines separating the slices
2598
+ :param `Scaled`: Do you want the pie to scale when zooming?
2599
+ or stay the same size in pixels?
2600
+ :param `InForeground`: Should it be on the foreground?
2601
+ """
2602
+ DrawObject.__init__(self, InForeground)
2603
+
2604
+ self.XY = np.asarray(XY, float).reshape( (2,) )
2605
+ self.Diameter = Diameter
2606
+ self.Values = np.asarray(Values, dtype=float).reshape((-1,1))
2607
+ if FillColors is None:
2608
+ FillColors = self.DefaultColorList[:len(Values)]
2609
+ if FillStyles is None:
2610
+ FillStyles = ['Solid'] * len(FillColors)
2611
+ self.FillColors = FillColors
2612
+ self.FillStyles = FillStyles
2613
+ self.LineColor = LineColor
2614
+ self.LineStyle = LineStyle
2615
+
2616
+ self.Scaled = Scaled
2617
+ self.InForeground = InForeground
2618
+
2619
+ self.SetPen(LineColor, LineStyle, LineWidth)
2620
+ self.SetBrushes()
2621
+ self.CalculatePoints()
2622
+
2623
+ def SetFillColors(self, FillColors):
2624
+ """
2625
+ Set the FillColors and update the Brushes.
2626
+
2627
+ :param `FillColors`: sequence of colors
2628
+ """
2629
+ self.FillColors = FillColors
2630
+ self.SetBrushes()
2631
+
2632
+ def SetFillStyles(self, FillStyles):
2633
+ """
2634
+ Set the FillStyles and update the Brushes.
2635
+
2636
+ :param `FillStyles`: Fill style you want ("Solid", "Hash", etc)
2637
+ """
2638
+ self.FillStyles = FillStyles
2639
+ self.SetBrushed()
2640
+
2641
+ def SetValues(self, Values):
2642
+ """
2643
+ Set the values and calculate the points.
2644
+
2645
+ :param `Values`: sequence of values you want to use for the chart
2646
+ """
2647
+ Values = np.asarray(Values, dtype=float).reshape((-1,1))
2648
+ self.Values = Values
2649
+ self.CalculatePoints()
2650
+
2651
+ def CalculatePoints(self):
2652
+ """Calculate the points."""
2653
+ # add the zero point to start
2654
+ Values = np.vstack( ( (0,), self.Values) )
2655
+ self.Angles = 360. * Values.cumsum()/Values.sum()
2656
+ self.CalcBoundingBox()
2657
+
2658
+ def SetBrushes(self):
2659
+ """Set the Brushes."""
2660
+ self.Brushes = []
2661
+ for FillColor, FillStyle in zip(self.FillColors, self.FillStyles):
2662
+ if FillColor is None or FillStyle is None:
2663
+ self.Brush = wx.TRANSPARENT_BRUSH
2664
+ else:
2665
+ self.Brushes.append(self.BrushList.setdefault( (FillColor, FillStyle),
2666
+ wx.Brush( FillColor, self.FillStyleList[FillStyle] )
2667
+ )
2668
+ )
2669
+ def CalcBoundingBox(self):
2670
+ """Calculate the bounding box."""
2671
+ if self.Scaled:
2672
+ self.BoundingBox = BBox.asBBox( ((self.XY-self.Diameter),(self.XY+self.Diameter)) )
2673
+ else:
2674
+ self.BoundingBox = BBox.asBBox((self.XY, self.XY))
2675
+ if self._Canvas:
2676
+ self._Canvas.BoundingBoxDirty = True
2677
+
2678
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
2679
+ CenterXY = WorldToPixel(self.XY)
2680
+ if self.Scaled:
2681
+ Diameter = ScaleWorldToPixel( (self.Diameter,self.Diameter) )[0]
2682
+ else:
2683
+ Diameter = self.Diameter
2684
+ WH = np.array((Diameter,Diameter), dtype = float)
2685
+ Corner = CenterXY - (WH / 2)
2686
+ dc.SetPen(self.Pen)
2687
+ for i, brush in enumerate(self.Brushes):
2688
+ dc.SetBrush( brush )
2689
+ dc.DrawEllipticArc(int(Corner[0]), int(Corner[1]), int(WH[0]), int(WH[1]), self.Angles[i], self.Angles[i+1])
2690
+ if HTdc and self.HitAble:
2691
+ if self.Scaled:
2692
+ radius = (ScaleWorldToPixel(self.Diameter)/2)[0]# just the x-coord
2693
+ else:
2694
+ radius = self.Diameter/2
2695
+ HTdc.SetPen(self.HitPen)
2696
+ HTdc.SetBrush(self.HitBrush)
2697
+ HTdc.DrawCircle(CenterXY.tolist(), int(radius))
2698
+
2699
+
2700
+ class Group(DrawObject):
2701
+ """
2702
+ A group of other FloatCanvas Objects
2703
+
2704
+ Not all DrawObject methods may apply here.
2705
+
2706
+ Note that if an object is in more than one group, it will get drawn more than once.
2707
+
2708
+ """
2709
+
2710
+ def __init__(self, ObjectList=[], InForeground=False, IsVisible=True):
2711
+ """
2712
+ Default class constructor.
2713
+
2714
+ :param list `ObjectList`: a list of :class:`DrawObject` to be grouped
2715
+ :param boolean `InForeground`: keep in foreground
2716
+ :param boolean `IsVisible`: keep it visible
2717
+
2718
+ """
2719
+ self.ObjectList = []
2720
+ DrawObject.__init__(self, InForeground, IsVisible)
2721
+
2722
+ # this one uses a property for _Canvas...
2723
+ self._Actual_Canvas = None
2724
+
2725
+ self.CalcBoundingBox()
2726
+ for obj in ObjectList:
2727
+ self.AddObject(obj)
2728
+ self.CalcBoundingBox()
2729
+
2730
+ ## re-define _Canvas property so that the sub-objects get set up right
2731
+ @property
2732
+ def _Canvas(self):
2733
+ """
2734
+ getter for the _Canvas property
2735
+ """
2736
+ return self._Actual_Canvas
2737
+
2738
+ @_Canvas.setter
2739
+ def _Canvas(self, canvas):
2740
+ """
2741
+ setter for Canvas property
2742
+ """
2743
+ self._Actual_Canvas = canvas
2744
+ for obj in self.ObjectList:
2745
+ obj._Canvas = canvas
2746
+
2747
+ def AddObject(self, obj):
2748
+ """
2749
+ Add an object to the group.
2750
+
2751
+ :param DrawObject `obj`: object to add
2752
+
2753
+ """
2754
+ self.ObjectList.append(obj)
2755
+ self.BoundingBox.Merge(obj.BoundingBox)
2756
+
2757
+ def AddObjects(self, Objects):
2758
+ """
2759
+ Add objects to the group.
2760
+
2761
+ :param list `Objects`: a list of :class:`DrawObject` to be grouped
2762
+
2763
+ """
2764
+ for o in Objects:
2765
+ self.AddObject(o)
2766
+
2767
+ def CalcBoundingBox(self):
2768
+ """Calculate the bounding box."""
2769
+ if self.ObjectList:
2770
+ BB = BBox.BBox(self.ObjectList[0].BoundingBox).copy()
2771
+ for obj in self.ObjectList[1:]:
2772
+ BB.Merge(obj.BoundingBox)
2773
+ else:
2774
+ BB = BBox.NullBBox()
2775
+ self.BoundingBox = BB
2776
+
2777
+ def SetColor(self, Color):
2778
+ """
2779
+ Set the Color
2780
+
2781
+ :param `Color`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
2782
+ for valid values
2783
+
2784
+ """
2785
+ for o in self.ObjectList:
2786
+ o.SetColor(Color)
2787
+
2788
+ def SetLineColor(self, Color):
2789
+ """
2790
+ Set the LineColor
2791
+
2792
+ :param `LineColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
2793
+ for valid values
2794
+
2795
+ """
2796
+ for o in self.ObjectList:
2797
+ o.SetLineColor(Color)
2798
+
2799
+ def SetLineStyle(self, LineStyle):
2800
+ """
2801
+ Set the LineStyle
2802
+
2803
+ :param `LineStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetLineStyle`
2804
+ for valid values
2805
+
2806
+ """
2807
+ for o in self.ObjectList:
2808
+ o.SetLineStyle(LineStyle)
2809
+
2810
+ def SetLineWidth(self, LineWidth):
2811
+ """
2812
+ Set the LineWidth
2813
+
2814
+ :param integer `LineWidth`: line width in pixels
2815
+
2816
+ """
2817
+ for o in self.ObjectList:
2818
+ o.SetLineWidth(LineWidth)
2819
+
2820
+ def SetFillColor(self, Color):
2821
+ """
2822
+ Set the FillColor
2823
+
2824
+ :param `FillColor`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetColor`
2825
+ for valid values
2826
+
2827
+ """
2828
+ for o in self.ObjectList:
2829
+ o.SetFillColor(Color)
2830
+
2831
+ def SetFillStyle(self, FillStyle):
2832
+ """
2833
+ Set the FillStyle
2834
+
2835
+ :param `FillStyle`: see :meth:`~lib.floatcanvas.FloatCanvas.DrawObject.SetFillStyle`
2836
+ for valid values
2837
+
2838
+ """
2839
+ for o in self.ObjectList:
2840
+ o.SetFillStyle(FillStyle)
2841
+
2842
+ def Move(self, Delta):
2843
+ """
2844
+ Moves the object by delta, where delta is a (dx, dy) pair.
2845
+
2846
+ :param `Delta`: is a (dx, dy) pair ideally a `NumPy <http://www.numpy.org/>`_
2847
+ array of shape (2, )
2848
+
2849
+ """
2850
+ for obj in self.ObjectList:
2851
+ obj.Move(Delta)
2852
+ self.BoundingBox += Delta
2853
+
2854
+ def Bind(self, Event, CallBackFun):
2855
+ """
2856
+ Bind an event to the Group object
2857
+
2858
+ :param `Event`: see below for supported event types
2859
+
2860
+ - EVT_FC_LEFT_DOWN
2861
+ - EVT_FC_LEFT_UP
2862
+ - EVT_FC_LEFT_DCLICK
2863
+ - EVT_FC_MIDDLE_DOWN
2864
+ - EVT_FC_MIDDLE_UP
2865
+ - EVT_FC_MIDDLE_DCLICK
2866
+ - EVT_FC_RIGHT_DOWN
2867
+ - EVT_FC_RIGHT_UP
2868
+ - EVT_FC_RIGHT_DCLICK
2869
+ - EVT_FC_ENTER_OBJECT
2870
+ - EVT_FC_LEAVE_OBJECT
2871
+
2872
+ :param `CallBackFun`: the call back function for the event
2873
+
2874
+
2875
+ """
2876
+ ## slight variation on DrawObject Bind Method:
2877
+ ## fixme: There is a lot of repeated code from the DrawObject method, but
2878
+ ## it all needs a lot of cleaning up anyway.
2879
+ self.CallBackFuncs[Event] = CallBackFun
2880
+ self.HitAble = True
2881
+ self._Canvas.UseHitTest = True
2882
+ if self.InForeground and self._Canvas._ForegroundHTBitmap is None:
2883
+ self._Canvas.MakeNewForegroundHTBitmap()
2884
+ elif self._Canvas._HTBitmap is None:
2885
+ self._Canvas.MakeNewHTBitmap()
2886
+ if not self.HitColor:
2887
+ if not self._Canvas.HitColorGenerator:
2888
+ self._Canvas.HitColorGenerator = _colorGenerator()
2889
+ # first call to prevent the background color from being used.
2890
+ next(self._Canvas.HitColorGenerator)
2891
+ # Set all contained objects to the same Hit color:
2892
+ self.HitColor = next(self._Canvas.HitColorGenerator)
2893
+ self._ChangeChildrenHitColor(self.ObjectList)
2894
+ # put the object in the hit dict, indexed by it's color
2895
+ if not self._Canvas.HitDict:
2896
+ self._Canvas.MakeHitDict()
2897
+ self._Canvas.HitDict[Event][self.HitColor] = (self)
2898
+
2899
+ def _ChangeChildrenHitColor(self, objlist):
2900
+ for obj in objlist:
2901
+ obj.SetHitPen(self.HitColor, self.HitLineWidth)
2902
+ obj.SetHitBrush(self.HitColor)
2903
+ obj.HitAble = True
2904
+
2905
+ if isinstance(obj, Group):
2906
+ self._ChangeChildrenHitColor(obj.ObjectList)
2907
+
2908
+ def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel = None, HTdc=None):
2909
+ for obj in self.ObjectList:
2910
+ obj._Draw(dc, WorldToPixel, ScaleWorldToPixel, HTdc)