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,2000 @@
1
+ #----------------------------------------------------------------------------
2
+ # Name: wx.lib.masked.numctrl.py
3
+ # Author: Will Sadkin
4
+ # Created: 09/06/2003
5
+ # Copyright: (c) 2003-2007 by Will Sadkin
6
+ #
7
+ # License: wxWidgets license
8
+ # Tags: phoenix-port, py3-port, unittest, documented
9
+ #----------------------------------------------------------------------------
10
+ # NOTE:
11
+ # This was written to provide a numeric edit control for wxPython that
12
+ # does things like right-insert (like a calculator), and does grouping, etc.
13
+ # (ie. the features of masked.TextCtrl), but allows Get/Set of numeric
14
+ # values, rather than text.
15
+ #
16
+ # Masked.NumCtrl permits integer, and floating point values to be set
17
+ # retrieved or set via .GetValue() and .SetValue() (type chosen based on
18
+ # fraction width, and provides an masked.EVT_NUM() event function for trapping
19
+ # changes to the control.
20
+ #
21
+ # It supports negative numbers as well as the naturals, and has the option
22
+ # of not permitting leading zeros or an empty control; if an empty value is
23
+ # not allowed, attempting to delete the contents of the control will result
24
+ # in a (selected) value of zero, thus preserving a legitimate numeric value.
25
+ # Similarly, replacing the contents of the control with '-' will result in
26
+ # a selected (absolute) value of -1.
27
+ #
28
+ # masked.NumCtrl also supports range limits, with the option of either
29
+ # enforcing them or simply coloring the text of the control if the limits
30
+ # are exceeded.
31
+ #
32
+ # masked.NumCtrl is intended to support fixed-point numeric entry, and
33
+ # is derived from BaseMaskedTextCtrl. As such, it supports a limited range
34
+ # of values to comply with a fixed-width entry mask.
35
+ #----------------------------------------------------------------------------
36
+ # 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
37
+ #
38
+ # o Updated for wx namespace
39
+ #
40
+ # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
41
+ #
42
+ # o wxMaskedEditMixin -> MaskedEditMixin
43
+ # o wxMaskedTextCtrl -> masked.TextCtrl
44
+ # o wxMaskedNumNumberUpdatedEvent -> masked.NumberUpdatedEvent
45
+ # o wxMaskedNumCtrl -> masked.NumCtrl
46
+ #
47
+
48
+ """
49
+ masked.NumCtrl:
50
+ - allows you to get and set integer or floating point numbers as value,</LI>
51
+ - provides bounds support and optional value limiting,</LI>
52
+ - has the right-insert input style that MaskedTextCtrl supports,</LI>
53
+ - provides optional automatic grouping, sign control and format, grouping and decimal
54
+ character selection, etc. etc.</LI>
55
+
56
+
57
+ Being derived from masked.TextCtrl, the control only allows
58
+ fixed-point notation. That is, it has a fixed (though reconfigurable)
59
+ maximum width for the integer portion and optional fixed width
60
+ fractional portion.
61
+
62
+ Here's the API::
63
+
64
+ from wx.lib.masked import NumCtrl
65
+
66
+ NumCtrl(
67
+ parent, id = -1,
68
+ value = 0,
69
+ pos = wx.DefaultPosition,
70
+ size = wx.DefaultSize,
71
+ style = 0,
72
+ validator = wx.DefaultValidator,
73
+ name = "masked.number",
74
+ integerWidth = 10,
75
+ fractionWidth = 0,
76
+ allowNone = False,
77
+ allowNegative = True,
78
+ useParensForNegatives = False,
79
+ groupDigits = False,
80
+ groupChar = ',',
81
+ decimalChar = '.',
82
+ min = None,
83
+ max = None,
84
+ limited = False,
85
+ limitOnFieldChange = False,
86
+ selectOnEntry = True,
87
+ foregroundColour = "Black",
88
+ signedForegroundColour = "Red",
89
+ emptyBackgroundColour = "White",
90
+ validBackgroundColour = "White",
91
+ invalidBackgroundColour = "Yellow",
92
+ autoSize = True,
93
+ )
94
+
95
+
96
+ value
97
+ If no initial value is set, the default will be zero, or
98
+ the minimum value, if specified. If an illegal string is specified,
99
+ a ValueError will result. (You can always later set the initial
100
+ value with SetValue() after instantiation of the control.)
101
+
102
+ integerWidth
103
+ Indicates how many places to the right of any decimal point
104
+ should be allowed in the control. This will, perforce, limit
105
+ the size of the values that can be entered. This number need
106
+ not include space for grouping characters or the sign, if either
107
+ of these options are enabled, as the resulting underlying
108
+ mask is automatically by the control. The default of 10
109
+ will allow any 32 bit integer value. The minimum value
110
+ for integerWidth is 1.
111
+
112
+ fractionWidth
113
+ Indicates how many decimal places to show for numeric value.
114
+ If default (0), then the control will display and return only
115
+ integer or long values.
116
+
117
+ allowNone
118
+ Boolean indicating whether or not the control is allowed to be
119
+ empty, representing a value of None for the control.
120
+
121
+ allowNegative
122
+ Boolean indicating whether or not control is allowed to hold
123
+ negative numbers.
124
+
125
+ useParensForNegatives
126
+ If true, this will cause negative numbers to be displayed with ()s
127
+ rather than -, (although '-' will still trigger a negative number.)
128
+
129
+ groupDigits
130
+ Indicates whether or not grouping characters should be allowed and/or
131
+ inserted when leaving the control or the decimal character is entered.
132
+
133
+ groupChar
134
+ What grouping character will be used if allowed. (By default ',')
135
+
136
+ decimalChar
137
+ If fractionWidth is > 0, what character will be used to represent
138
+ the decimal point. (By default '.')
139
+
140
+ min
141
+ The minimum value that the control should allow. This can be also be
142
+ adjusted with SetMin(). If the control is not limited, any value
143
+ below this bound will result in a background colored with the current
144
+ invalidBackgroundColour. If the min specified will not fit into the
145
+ control, the min setting will be ignored.
146
+
147
+ max
148
+ The maximum value that the control should allow. This can be
149
+ adjusted with SetMax(). If the control is not limited, any value
150
+ above this bound will result in a background colored with the current
151
+ invalidBackgroundColour. If the max specified will not fit into the
152
+ control, the max setting will be ignored.
153
+
154
+ limited
155
+ Boolean indicating whether the control prevents values from
156
+ exceeding the currently set minimum and maximum values (bounds).
157
+ If False and bounds are set, out-of-bounds values will
158
+ result in a background colored with the current invalidBackgroundColour.
159
+
160
+ limitOnFieldChange
161
+ An alternative to limited, this boolean indicates whether or not a
162
+ field change should be allowed if the value in the control
163
+ is out of bounds. If True, and control focus is lost, this will also
164
+ cause the control to take on the nearest bound value.
165
+
166
+ selectOnEntry
167
+ Boolean indicating whether or not the value in each field of the
168
+ control should be automatically selected (for replacement) when
169
+ that field is entered, either by cursor movement or tabbing.
170
+ This can be desirable when using these controls for rapid data entry.
171
+
172
+ foregroundColour
173
+ Color value used for positive values of the control.
174
+
175
+ signedForegroundColour
176
+ Color value used for negative values of the control.
177
+
178
+ emptyBackgroundColour
179
+ What background color to use when the control is considered
180
+ "empty." (allow_none must be set to trigger this behavior.)
181
+
182
+ validBackgroundColour
183
+ What background color to use when the control value is
184
+ considered valid.
185
+
186
+ invalidBackgroundColour
187
+ Color value used for illegal values or values out-of-bounds of the
188
+ control when the bounds are set but the control is not limited.
189
+
190
+ autoSize
191
+ Boolean indicating whether or not the control should set its own
192
+ width based on the integer and fraction widths. True by default.
193
+ <I>Note:</I> Setting this to False will produce seemingly odd
194
+ behavior unless the control is large enough to hold the maximum
195
+ specified value given the widths and the sign positions; if not,
196
+ the control will appear to "jump around" as the contents scroll.
197
+ (ie. autoSize is highly recommended.)
198
+
199
+ --------------------------
200
+
201
+ masked.EVT_NUM(win, id, func)
202
+ Respond to a EVT_COMMAND_MASKED_NUMBER_UPDATED event, generated when
203
+ the value changes. Notice that this event will always be sent when the
204
+ control's contents changes - whether this is due to user input or
205
+ comes from the program itself (for example, if SetValue() is called.)
206
+
207
+
208
+ SetValue(int|long|float|string)
209
+ Sets the value of the control to the value specified, if
210
+ possible. The resulting actual value of the control may be
211
+ altered to conform to the format of the control, changed
212
+ to conform with the bounds set on the control if limited,
213
+ or colored if not limited but the value is out-of-bounds.
214
+ A ValueError exception will be raised if an invalid value
215
+ is specified.
216
+
217
+ GetValue()
218
+ Retrieves the numeric value from the control. The value
219
+ retrieved will be either be returned as a long if the
220
+ fractionWidth is 0, or a float otherwise.
221
+
222
+
223
+ SetParameters(**kwargs)
224
+ Allows simultaneous setting of various attributes
225
+ of the control after construction. Keyword arguments
226
+ allowed are the same parameters as supported in the constructor.
227
+
228
+
229
+ SetIntegerWidth(value)
230
+ Resets the width of the integer portion of the control. The
231
+ value must be >= 1, or an AttributeError exception will result.
232
+ This value should account for any grouping characters that might
233
+ be inserted (if grouping is enabled), but does not need to account
234
+ for the sign, as that is handled separately by the control.
235
+ GetIntegerWidth()
236
+ Returns the current width of the integer portion of the control,
237
+ not including any reserved sign position.
238
+
239
+
240
+ SetFractionWidth(value)
241
+ Resets the width of the fractional portion of the control. The
242
+ value must be >= 0, or an AttributeError exception will result. If
243
+ 0, the current value of the control will be truncated to an integer
244
+ value.
245
+ GetFractionWidth()
246
+ Returns the current width of the fractional portion of the control.
247
+
248
+
249
+ SetMin(min=None)
250
+ Resets the minimum value of the control. If a value of <I>None</I>
251
+ is provided, then the control will have no explicit minimum value.
252
+ If the value specified is greater than the current maximum value,
253
+ then the function returns False and the minimum will not change from
254
+ its current setting. On success, the function returns True.
255
+
256
+ If successful and the current value is lower than the new lower
257
+ bound, if the control is limited, the value will be automatically
258
+ adjusted to the new minimum value; if not limited, the value in the
259
+ control will be colored as invalid.
260
+
261
+ If min > the max value allowed by the width of the control,
262
+ the function will return False, and the min will not be set.
263
+
264
+ GetMin()
265
+ Gets the current lower bound value for the control.
266
+ It will return None if no lower bound is currently specified.
267
+
268
+
269
+ SetMax(max=None)
270
+ Resets the maximum value of the control. If a value of <I>None</I>
271
+ is provided, then the control will have no explicit maximum value.
272
+ If the value specified is less than the current minimum value, then
273
+ the function returns False and the maximum will not change from its
274
+ current setting. On success, the function returns True.
275
+
276
+ If successful and the current value is greater than the new upper
277
+ bound, if the control is limited the value will be automatically
278
+ adjusted to this maximum value; if not limited, the value in the
279
+ control will be colored as invalid.
280
+
281
+ If max > the max value allowed by the width of the control,
282
+ the function will return False, and the max will not be set.
283
+
284
+ GetMax()
285
+ Gets the current upper bound value for the control.
286
+ It will return None if no upper bound is currently specified.
287
+
288
+
289
+ SetBounds(min=None,max=None)
290
+ This function is a convenience function for setting the min and max
291
+ values at the same time. The function only applies the maximum bound
292
+ if setting the minimum bound is successful, and returns True
293
+ only if both operations succeed. <B><I>Note:</I> leaving out an argument
294
+ will remove the corresponding bound.
295
+ GetBounds()
296
+ This function returns a two-tuple (min,max), indicating the
297
+ current bounds of the control. Each value can be None if
298
+ that bound is not set.
299
+
300
+
301
+ IsInBounds(value=None)
302
+ Returns <I>True</I> if no value is specified and the current value
303
+ of the control falls within the current bounds. This function can also
304
+ be called with a value to see if that value would fall within the current
305
+ bounds of the given control.
306
+
307
+
308
+ SetLimited(bool)
309
+ If called with a value of True, this function will cause the control
310
+ to limit the value to fall within the bounds currently specified.
311
+ If the control's value currently exceeds the bounds, it will then
312
+ be limited accordingly.
313
+ If called with a value of False, this function will disable value
314
+ limiting, but coloring of out-of-bounds values will still take
315
+ place if bounds have been set for the control.
316
+
317
+ GetLimited()
318
+
319
+ IsLimited()
320
+ Returns <I>True</I> if the control is currently limiting the
321
+ value to fall within the current bounds.
322
+
323
+ SetLimitOnFieldChange()
324
+ If called with a value of True, will cause the control to allow
325
+ out-of-bounds values, but will prevent field change if attempted
326
+ via navigation, and if the control loses focus, it will change
327
+ the value to the nearest bound.
328
+
329
+ GetLimitOnFieldChange()
330
+
331
+ IsLimitedOnFieldChange()
332
+ Returns <I>True</I> if the control is currently limiting the
333
+ value on field change.
334
+
335
+
336
+ SetAllowNone(bool)
337
+ If called with a value of True, this function will cause the control
338
+ to allow the value to be empty, representing a value of None.
339
+ If called with a value of False, this function will prevent the value
340
+ from being None. If the value of the control is currently None,
341
+ ie. the control is empty, then the value will be changed to that
342
+ of the lower bound of the control, or 0 if no lower bound is set.
343
+
344
+ GetAllowNone()
345
+
346
+ IsNoneAllowed()
347
+ Returns <I>True</I> if the control currently allows its
348
+ value to be None.
349
+
350
+
351
+ SetAllowNegative(bool)
352
+ If called with a value of True, this function will cause the
353
+ control to allow the value to be negative (and reserve space for
354
+ displaying the sign. If called with a value of False, and the
355
+ value of the control is currently negative, the value of the
356
+ control will be converted to the absolute value, and then
357
+ limited appropriately based on the existing bounds of the control
358
+ (if any).
359
+
360
+ GetAllowNegative()
361
+
362
+ IsNegativeAllowed()
363
+ Returns <I>True</I> if the control currently permits values
364
+ to be negative.
365
+
366
+
367
+ SetGroupDigits(bool)
368
+ If called with a value of True, this will make the control
369
+ automatically add and manage grouping characters to the presented
370
+ value in integer portion of the control.
371
+
372
+ GetGroupDigits()
373
+
374
+ IsGroupingAllowed()
375
+ Returns <I>True</I> if the control is currently set to group digits.
376
+
377
+
378
+ SetGroupChar()
379
+ Sets the grouping character for the integer portion of the
380
+ control. (The default grouping character this is ','.
381
+ GetGroupChar()
382
+ Returns the current grouping character for the control.
383
+
384
+
385
+ SetSelectOnEntry()
386
+ If called with a value of <I>True</I>, this will make the control
387
+ automatically select the contents of each field as it is entered
388
+ within the control. (The default is True.)
389
+ GetSelectOnEntry()
390
+ Returns <I>True</I> if the control currently auto selects
391
+ the field values on entry.
392
+
393
+
394
+ SetAutoSize(bool)
395
+ Resets the autoSize attribute of the control.
396
+ GetAutoSize()
397
+ Returns the current state of the autoSize attribute for the control.
398
+
399
+ """
400
+
401
+ import copy
402
+
403
+ import wx
404
+
405
+ from sys import maxsize
406
+ MAXINT = maxsize # (constants should be in upper case)
407
+ MININT = -maxsize-1
408
+
409
+ from wx.tools.dbg import Logger
410
+ from wx.lib.masked import MaskedEditMixin, Field, BaseMaskedTextCtrl
411
+ ##dbg = Logger()
412
+ ##dbg(enable=1)
413
+
414
+ #----------------------------------------------------------------------------
415
+
416
+ wxEVT_COMMAND_MASKED_NUMBER_UPDATED = wx.NewEventType()
417
+ EVT_NUM = wx.PyEventBinder(wxEVT_COMMAND_MASKED_NUMBER_UPDATED, 1)
418
+
419
+ #----------------------------------------------------------------------------
420
+
421
+ class NumberUpdatedEvent(wx.PyCommandEvent):
422
+ """
423
+ Used to fire an EVT_NUM event whenever the value in a NumCtrl changes.
424
+ """
425
+
426
+ def __init__(self, id, value = 0, object=None):
427
+ wx.PyCommandEvent.__init__(self, wxEVT_COMMAND_MASKED_NUMBER_UPDATED, id)
428
+
429
+ self.__value = value
430
+ self.SetEventObject(object)
431
+
432
+ def GetValue(self):
433
+ """Retrieve the value of the control at the time
434
+ this event was generated."""
435
+ return self.__value
436
+
437
+
438
+ #----------------------------------------------------------------------------
439
+ class NumCtrlAccessorsMixin:
440
+ """
441
+ Defines masked.NumCtrl's list of attributes having their own
442
+ Get/Set functions, ignoring those that make no sense for
443
+ a numeric control.
444
+ """
445
+ exposed_basectrl_params = (
446
+ 'decimalChar',
447
+ 'shiftDecimalChar',
448
+ 'groupChar',
449
+ 'useParensForNegatives',
450
+ 'defaultValue',
451
+ 'description',
452
+
453
+ 'useFixedWidthFont',
454
+ 'autoSize',
455
+ 'signedForegroundColour',
456
+ 'emptyBackgroundColour',
457
+ 'validBackgroundColour',
458
+ 'invalidBackgroundColour',
459
+
460
+ 'emptyInvalid',
461
+ 'validFunc',
462
+ 'validRequired',
463
+ 'stopFieldChangeIfInvalid',
464
+ )
465
+ for param in exposed_basectrl_params:
466
+ propname = param[0].upper() + param[1:]
467
+ exec('def Set%s(self, value): self.SetCtrlParameters(%s=value)' % (propname, param))
468
+ exec('def Get%s(self): return self.GetCtrlParameter("%s")''' % (propname, param))
469
+
470
+ if param.find('Colour') != -1:
471
+ # add non-british spellings, for backward-compatibility
472
+ propname.replace('Colour', 'Color')
473
+
474
+ exec('def Set%s(self, value): self.SetCtrlParameters(%s=value)' % (propname, param))
475
+ exec('def Get%s(self): return self.GetCtrlParameter("%s")''' % (propname, param))
476
+
477
+
478
+
479
+ #----------------------------------------------------------------------------
480
+
481
+ class NumCtrl(BaseMaskedTextCtrl, NumCtrlAccessorsMixin):
482
+ """
483
+ Masked edit control supporting "native" numeric values, ie. .SetValue(3), for
484
+ example, and supporting a variety of formatting options, including automatic
485
+ rounding specifiable precision, grouping and decimal place characters, etc.
486
+ """
487
+
488
+
489
+ valid_ctrl_params = {
490
+ 'integerWidth': 10, # by default allow all 32-bit integers
491
+ 'fractionWidth': 0, # by default, use integers
492
+ 'decimalChar': '.', # by default, use '.' for decimal point
493
+ 'allowNegative': True, # by default, allow negative numbers
494
+ 'useParensForNegatives': False, # by default, use '-' to indicate negatives
495
+ 'groupDigits': False, # by default, don't insert grouping
496
+ 'groupChar': ',', # by default, use ',' for grouping
497
+ 'min': None, # by default, no bounds set
498
+ 'max': None,
499
+ 'limited': False, # by default, no limiting even if bounds set
500
+ 'limitOnFieldChange': False, # by default, don't limit if changing fields, even if bounds set
501
+ 'allowNone': False, # by default, don't allow empty value
502
+ 'selectOnEntry': True, # by default, select the value of each field on entry
503
+ 'foregroundColour': "Black",
504
+ 'signedForegroundColour': "Red",
505
+ 'emptyBackgroundColour': "White",
506
+ 'validBackgroundColour': "White",
507
+ 'invalidBackgroundColour': "Yellow",
508
+ 'useFixedWidthFont': False, # use base control default font, instead of fixed width one
509
+ 'autoSize': True, # by default, set the width of the control based on the mask
510
+ }
511
+
512
+
513
+ def __init__ (
514
+ self, parent, id=-1, value = 0,
515
+ pos = wx.DefaultPosition, size = wx.DefaultSize,
516
+ style = wx.TE_PROCESS_TAB, validator = wx.DefaultValidator,
517
+ name = "masked.num",
518
+ **kwargs ):
519
+ """
520
+ Default class constructor.
521
+
522
+ :param wx.Window `parent`: the window parent. Must not be ``None``;
523
+ :param integer `id`: window identifier. A value of -1 indicates a default value;
524
+ :param integer `value`: value to be shown;
525
+ :param `pos`: the control position. A value of (-1, -1) indicates a default position,
526
+ chosen by either the windowing system or wxPython, depending on platform;
527
+ :type `pos`: tuple or :class:`wx.Point`
528
+ :param `size`: the control size. A value of (-1, -1) indicates a default size,
529
+ chosen by either the windowing system or wxPython, depending on platform;
530
+ :param integer `style`: the window style;
531
+ :param wx.Validator `validator`: this is mainly provided for data-transfer, as control does
532
+ its own validation;
533
+ :param string `name`: the window name;
534
+
535
+ """
536
+
537
+ ## dbg('masked.NumCtrl::__init__', indent=1)
538
+
539
+ # Set defaults for control:
540
+ ## dbg('setting defaults:')
541
+ for key, param_value in NumCtrl.valid_ctrl_params.items():
542
+ # This is done this way to make setattr behave consistently with
543
+ # "private attribute" name mangling
544
+ setattr(self, '_' + key, copy.copy(param_value))
545
+
546
+ # Assign defaults for all attributes:
547
+ init_args = copy.deepcopy(NumCtrl.valid_ctrl_params)
548
+ ## dbg('kwargs:', kwargs)
549
+ for key, param_value in kwargs.items():
550
+ key = key.replace('Color', 'Colour')
551
+ if key not in NumCtrl.valid_ctrl_params:
552
+ raise AttributeError('invalid keyword argument "%s"' % key)
553
+ else:
554
+ init_args[key] = param_value
555
+ ## dbg('init_args:', indent=1)
556
+ for key, param_value in init_args.items():
557
+ ## dbg('%s:' % key, param_value)
558
+ pass
559
+ ## dbg(indent=0)
560
+
561
+ # Process initial fields for the control, as part of construction:
562
+ if not isinstance(init_args['integerWidth'], int):
563
+ raise AttributeError('invalid integerWidth (%s) specified; expected integer' % repr(init_args['integerWidth']))
564
+ elif init_args['integerWidth'] < 1:
565
+ raise AttributeError('invalid integerWidth (%s) specified; must be > 0' % repr(init_args['integerWidth']))
566
+
567
+ fields = {}
568
+
569
+ if 'fractionWidth' in init_args:
570
+ if not isinstance(init_args['fractionWidth'], int):
571
+ raise AttributeError('invalid fractionWidth (%s) specified; expected integer' % repr(self._fractionWidth))
572
+ elif init_args['fractionWidth'] < 0:
573
+ raise AttributeError('invalid fractionWidth (%s) specified; must be >= 0' % repr(init_args['fractionWidth']))
574
+ self._fractionWidth = init_args['fractionWidth']
575
+
576
+ if self._fractionWidth:
577
+ fracmask = '.' + '#{%d}' % self._fractionWidth
578
+ ## dbg('fracmask:', fracmask)
579
+ fields[1] = Field(defaultValue='0'*self._fractionWidth)
580
+ else:
581
+ fracmask = ''
582
+
583
+ self._integerWidth = init_args['integerWidth']
584
+ if init_args['groupDigits']:
585
+ self._groupSpace = (self._integerWidth - 1) // 3
586
+ else:
587
+ self._groupSpace = 0
588
+ intmask = '#{%d}' % (self._integerWidth + self._groupSpace)
589
+ if self._fractionWidth:
590
+ emptyInvalid = False
591
+ else:
592
+ emptyInvalid = True
593
+ fields[0] = Field(formatcodes='r<>', emptyInvalid=emptyInvalid)
594
+ ## dbg('intmask:', intmask)
595
+
596
+ # don't bother to reprocess these arguments:
597
+ del init_args['integerWidth']
598
+ del init_args['fractionWidth']
599
+
600
+ self._autoSize = init_args['autoSize']
601
+ if self._autoSize:
602
+ formatcodes = 'FR<'
603
+ else:
604
+ formatcodes = 'R<'
605
+
606
+
607
+ mask = intmask+fracmask
608
+
609
+ # initial value of state vars
610
+ self._oldvalue = 0
611
+ self._integerEnd = 0
612
+ self._typedSign = False
613
+
614
+ # Construct the base control:
615
+ BaseMaskedTextCtrl.__init__(
616
+ self, parent, id, '',
617
+ pos, size, style, validator, name,
618
+ mask = mask,
619
+ formatcodes = formatcodes,
620
+ fields = fields,
621
+ validFunc=self.IsInBounds,
622
+ setupEventHandling = False)
623
+
624
+ self.Bind(wx.EVT_SET_FOCUS, self._OnFocus ) ## defeat automatic full selection
625
+ self.Bind(wx.EVT_KILL_FOCUS, self._OnKillFocus ) ## run internal validator
626
+ self.Bind(wx.EVT_LEFT_DCLICK, self._OnDoubleClick) ## select field under cursor on dclick
627
+ self.Bind(wx.EVT_RIGHT_UP, self._OnContextMenu ) ## bring up an appropriate context menu
628
+ self.Bind(wx.EVT_KEY_DOWN, self._OnKeyDown ) ## capture control events not normally seen, eg ctrl-tab.
629
+ self.Bind(wx.EVT_CHAR, self._OnChar ) ## handle each keypress
630
+ self.Bind(wx.EVT_TEXT, self.OnTextChange ) ## color control appropriately & keep
631
+ ## track of previous value for undo
632
+
633
+ # Establish any additional parameters, with appropriate error checking
634
+ self.SetParameters(**init_args)
635
+
636
+ # right alignment with prefixed blanks doesn't work with wxPython 2.9+
637
+ if wx.Platform == "__WXMSW__":
638
+ self.SetWindowStyleFlag(self.GetWindowStyleFlag() | wx.TE_RIGHT)
639
+
640
+ # Set the value requested (if possible)
641
+ ## wxCallAfter(self.SetValue, value)
642
+ self.SetValue(value)
643
+
644
+ # Ensure proper coloring:
645
+ self.Refresh()
646
+ ## dbg('finished NumCtrl::__init__', indent=0)
647
+
648
+
649
+ def SetParameters(self, **kwargs):
650
+ """
651
+ This function is used to initialize and reconfigure the control.
652
+ See :class:`~lib.masked.timectrl.TimeCtrl` module overview for available
653
+ parameters.
654
+ """
655
+ ## dbg('NumCtrl::SetParameters', indent=1)
656
+ maskededit_kwargs = {}
657
+ reset_fraction_width = False
658
+
659
+
660
+ if( ('integerWidth' in kwargs and kwargs['integerWidth'] != self._integerWidth)
661
+ or ('fractionWidth' in kwargs and kwargs['fractionWidth'] != self._fractionWidth)
662
+ or ('groupDigits' in kwargs and kwargs['groupDigits'] != self._groupDigits)
663
+ or ('autoSize' in kwargs and kwargs['autoSize'] != self._autoSize) ):
664
+
665
+ fields = {}
666
+
667
+ if 'fractionWidth' in kwargs:
668
+ if not isinstance(kwargs['fractionWidth'], int):
669
+ raise AttributeError('invalid fractionWidth (%s) specified; expected integer' % repr(kwargs['fractionWidth']))
670
+ elif kwargs['fractionWidth'] < 0:
671
+ raise AttributeError('invalid fractionWidth (%s) specified; must be >= 0' % repr(kwargs['fractionWidth']))
672
+ else:
673
+ if self._fractionWidth != kwargs['fractionWidth']:
674
+ self._fractionWidth = kwargs['fractionWidth']
675
+
676
+ if self._fractionWidth:
677
+ fracmask = '.' + '#{%d}' % self._fractionWidth
678
+ fields[1] = Field(defaultValue='0'*self._fractionWidth)
679
+ emptyInvalid = False
680
+ else:
681
+ emptyInvalid = True
682
+ fracmask = ''
683
+ ## dbg('fracmask:', fracmask)
684
+
685
+ if 'integerWidth' in kwargs:
686
+ if not isinstance(kwargs['integerWidth'], int):
687
+ ## dbg(indent=0)
688
+ raise AttributeError('invalid integerWidth (%s) specified; expected integer' % repr(kwargs['integerWidth']))
689
+ elif kwargs['integerWidth'] < 0:
690
+ ## dbg(indent=0)
691
+ raise AttributeError('invalid integerWidth (%s) specified; must be > 0' % repr(kwargs['integerWidth']))
692
+ else:
693
+ self._integerWidth = kwargs['integerWidth']
694
+
695
+ if 'groupDigits' in kwargs:
696
+ self._groupDigits = kwargs['groupDigits']
697
+
698
+ if self._groupDigits:
699
+ self._groupSpace = (self._integerWidth - 1) // 3
700
+ else:
701
+ self._groupSpace = 0
702
+
703
+ intmask = '#{%d}' % (self._integerWidth + self._groupSpace)
704
+ ## dbg('intmask:', intmask)
705
+ fields[0] = Field(formatcodes='r<>', emptyInvalid=emptyInvalid)
706
+ maskededit_kwargs['fields'] = fields
707
+
708
+ # don't bother to reprocess these arguments:
709
+ if 'integerWidth' in kwargs:
710
+ del kwargs['integerWidth']
711
+ if 'fractionWidth' in kwargs:
712
+ del kwargs['fractionWidth']
713
+
714
+ maskededit_kwargs['mask'] = intmask+fracmask
715
+
716
+ if 'groupChar' in kwargs or 'decimalChar' in kwargs:
717
+ old_groupchar = self._groupChar # save so we can reformat properly
718
+ old_decimalchar = self._decimalChar
719
+ ## dbg("old_groupchar: '%s'" % old_groupchar)
720
+ ## dbg("old_decimalchar: '%s'" % old_decimalchar)
721
+ groupchar = old_groupchar
722
+ decimalchar = old_decimalchar
723
+ old_numvalue = self._GetNumValue(self._GetValue())
724
+
725
+ if 'groupChar' in kwargs:
726
+ maskededit_kwargs['groupChar'] = kwargs['groupChar']
727
+ groupchar = kwargs['groupChar']
728
+ if 'decimalChar' in kwargs:
729
+ maskededit_kwargs['decimalChar'] = kwargs['decimalChar']
730
+ decimalchar = kwargs['decimalChar']
731
+
732
+ # Add sanity check to make sure these are distinct, and if not,
733
+ # raise attribute error
734
+ if groupchar == decimalchar:
735
+ raise AttributeError('groupChar and decimalChar must be distinct')
736
+
737
+
738
+ # for all other parameters, assign keyword args as appropriate:
739
+ for key, param_value in kwargs.items():
740
+ key = key.replace('Color', 'Colour')
741
+ if key not in NumCtrl.valid_ctrl_params:
742
+ raise AttributeError('invalid keyword argument "%s"' % key)
743
+ elif key not in MaskedEditMixin.valid_ctrl_params:
744
+ setattr(self, '_' + key, param_value)
745
+ elif key in ('mask', 'autoformat'): # disallow explicit setting of mask
746
+ raise AttributeError('invalid keyword argument "%s"' % key)
747
+ else:
748
+ maskededit_kwargs[key] = param_value
749
+ ## dbg('kwargs:', kwargs)
750
+
751
+ # reprocess existing format codes to ensure proper resulting format:
752
+ formatcodes = self.GetCtrlParameter('formatcodes')
753
+ if 'allowNegative' in kwargs:
754
+ if kwargs['allowNegative'] and '-' not in formatcodes:
755
+ formatcodes += '-'
756
+ maskededit_kwargs['formatcodes'] = formatcodes
757
+ elif not kwargs['allowNegative'] and '-' in formatcodes:
758
+ formatcodes = formatcodes.replace('-','')
759
+ maskededit_kwargs['formatcodes'] = formatcodes
760
+
761
+ if 'groupDigits' in kwargs:
762
+ if kwargs['groupDigits'] and ',' not in formatcodes:
763
+ formatcodes += ','
764
+ maskededit_kwargs['formatcodes'] = formatcodes
765
+ elif not kwargs['groupDigits'] and ',' in formatcodes:
766
+ formatcodes = formatcodes.replace(',','')
767
+ maskededit_kwargs['formatcodes'] = formatcodes
768
+
769
+ if 'selectOnEntry' in kwargs:
770
+ self._selectOnEntry = kwargs['selectOnEntry']
771
+ ## dbg("kwargs['selectOnEntry']?", kwargs['selectOnEntry'], "'S' in formatcodes?", 'S' in formatcodes)
772
+ if kwargs['selectOnEntry'] and 'S' not in formatcodes:
773
+ formatcodes += 'S'
774
+ maskededit_kwargs['formatcodes'] = formatcodes
775
+ elif not kwargs['selectOnEntry'] and 'S' in formatcodes:
776
+ formatcodes = formatcodes.replace('S','')
777
+ maskededit_kwargs['formatcodes'] = formatcodes
778
+
779
+ if 'autoSize' in kwargs:
780
+ self._autoSize = kwargs['autoSize']
781
+ if kwargs['autoSize'] and 'F' not in formatcodes:
782
+ formatcodes += 'F'
783
+ maskededit_kwargs['formatcodes'] = formatcodes
784
+ elif not kwargs['autoSize'] and 'F' in formatcodes:
785
+ formatcodes = formatcodes.replace('F', '')
786
+ maskededit_kwargs['formatcodes'] = formatcodes
787
+
788
+
789
+ if 'r' in formatcodes and self._fractionWidth:
790
+ # top-level mask should only be right insert if no fractional
791
+ # part will be shown; ie. if reconfiguring control, remove
792
+ # previous "global" setting.
793
+ formatcodes = formatcodes.replace('r', '')
794
+ maskededit_kwargs['formatcodes'] = formatcodes
795
+
796
+
797
+ if 'limited' in kwargs:
798
+ if kwargs['limited'] and not self._limited:
799
+ maskededit_kwargs['validRequired'] = True
800
+ elif not kwargs['limited'] and self._limited:
801
+ maskededit_kwargs['validRequired'] = False
802
+ self._limited = kwargs['limited']
803
+
804
+ if 'limitOnFieldChange' in kwargs:
805
+ if kwargs['limitOnFieldChange'] and not self._limitOnFieldChange:
806
+ maskededit_kwargs['stopFieldChangeIfInvalid'] = True
807
+ elif kwargs['limitOnFieldChange'] and self._limitOnFieldChange:
808
+ maskededit_kwargs['stopFieldChangeIfInvalid'] = False
809
+
810
+ ## dbg('maskededit_kwargs:', maskededit_kwargs)
811
+ if maskededit_kwargs:
812
+ self.SetCtrlParameters(**maskededit_kwargs)
813
+
814
+ # Go ensure all the format codes necessary are present:
815
+ orig_intformat = intformat = self.GetFieldParameter(0, 'formatcodes')
816
+ if 'r' not in intformat:
817
+ intformat += 'r'
818
+ if '>' not in intformat:
819
+ intformat += '>'
820
+ if intformat != orig_intformat:
821
+ if self._fractionWidth:
822
+ self.SetFieldParameters(0, formatcodes=intformat)
823
+ else:
824
+ self.SetCtrlParameters(formatcodes=intformat)
825
+
826
+ # Record end of integer and place cursor there unless selecting, or select entire field:
827
+ integerStart, integerEnd = self._fields[0]._extent
828
+ if not self._fields[0]._selectOnFieldEntry:
829
+ self.SetInsertionPoint(0)
830
+ self.SetInsertionPoint(integerEnd)
831
+ self.SetSelection(integerEnd, integerEnd)
832
+ else:
833
+ self.SetInsertionPoint(0) # include any sign
834
+ self.SetSelection(0, integerEnd)
835
+
836
+
837
+ # Set min and max as appropriate:
838
+ if 'min' in kwargs:
839
+ min = kwargs['min']
840
+ if( self._max is None
841
+ or min is None
842
+ or (self._max is not None and self._max >= min) ):
843
+ ## dbg('examining min')
844
+ if min is not None:
845
+ try:
846
+ textmin = self._toGUI(min, apply_limits = False)
847
+ except ValueError:
848
+ ## dbg('min will not fit into control; ignoring', indent=0)
849
+ raise
850
+ ## dbg('accepted min')
851
+ self._min = min
852
+ else:
853
+ ## dbg('ignoring min')
854
+ pass
855
+
856
+
857
+ if 'max' in kwargs:
858
+ max = kwargs['max']
859
+ if( self._min is None
860
+ or max is None
861
+ or (self._min is not None and self._min <= max) ):
862
+ ## dbg('examining max')
863
+ if max is not None:
864
+ try:
865
+ textmax = self._toGUI(max, apply_limits = False)
866
+ except ValueError:
867
+ ## dbg('max will not fit into control; ignoring', indent=0)
868
+ raise
869
+ ## dbg('accepted max')
870
+ self._max = max
871
+ else:
872
+ ## dbg('ignoring max')
873
+ pass
874
+
875
+ if 'allowNegative' in kwargs:
876
+ self._allowNegative = kwargs['allowNegative']
877
+
878
+ # Ensure current value of control obeys any new restrictions imposed:
879
+ text = self._GetValue()
880
+ ## dbg('text value: "%s"' % text)
881
+ if 'groupChar' in kwargs and self._groupChar != old_groupchar and text.find(old_groupchar) != -1:
882
+ text = old_numvalue
883
+ ## dbg('old_groupchar: "%s" newgroupchar: "%s"' % (old_groupchar, self._groupChar))
884
+ if 'decimalChar' in kwargs and self._decimalChar != old_decimalchar and text.find(old_decimalchar) != -1:
885
+ text = old_numvalue
886
+
887
+ if text != self._GetValue():
888
+ if self._decimalChar != '.':
889
+ # ensure latest decimal char is in "numeric value" so it won't be removed
890
+ # when going to the GUI:
891
+ text = text.replace('.', self._decimalChar)
892
+ newtext = self._toGUI(text)
893
+ ## dbg('calling wx.TextCtrl.ChangeValue(self, %s)' % newtext)
894
+ wx.TextCtrl.ChangeValue(self, newtext)
895
+
896
+ value = self.GetValue()
897
+
898
+ ## dbg('self._allowNegative?', self._allowNegative)
899
+ if not self._allowNegative and self._isNeg:
900
+ value = abs(value)
901
+ ## dbg('abs(value):', value)
902
+ self._isNeg = False
903
+
904
+ elif not self._allowNone and BaseMaskedTextCtrl.GetValue(self) == '':
905
+ if self._min > 0:
906
+ value = self._min
907
+ else:
908
+ value = 0
909
+
910
+ sel_start, sel_to = self.GetSelection()
911
+ if self.IsLimited() and self._min is not None and value < self._min:
912
+ ## dbg('Set to min value:', self._min)
913
+ self._ChangeValue(self._toGUI(self._min))
914
+
915
+ elif self.IsLimited() and self._max is not None and value > self._max:
916
+ ## dbg('Setting to max value:', self._max)
917
+ self._ChangeValue(self._toGUI(self._max))
918
+ else:
919
+ # reformat current value as appropriate to possibly new conditions
920
+ ## dbg('Reformatting value:', value)
921
+ sel_start, sel_to = self.GetSelection()
922
+ self._ChangeValue(self._toGUI(value))
923
+ self.Refresh() # recolor as appropriate
924
+ ## dbg('finished NumCtrl::SetParameters', indent=0)
925
+
926
+
927
+
928
+ def _GetNumValue(self, value):
929
+ """
930
+ This function attempts to "clean up" a text value, providing a regularized
931
+ convertible string, via atol() or atof(), for any well-formed numeric text value.
932
+ """
933
+ return value.replace(self._groupChar, '').replace(self._decimalChar, '.').replace('(', '-').replace(')','').strip()
934
+
935
+
936
+ def GetFraction(self, candidate=None):
937
+ """
938
+ Returns the fractional portion of the value as a float. If there is no
939
+ fractional portion, the value returned will be 0.0.
940
+ """
941
+ if not self._fractionWidth:
942
+ return 0.0
943
+ else:
944
+ fracstart, fracend = self._fields[1]._extent
945
+ if candidate is None:
946
+ value = self._toGUI(BaseMaskedTextCtrl.GetValue(self))
947
+ else:
948
+ value = self._toGUI(candidate)
949
+ fracstring = value[fracstart:fracend].strip()
950
+ if not value:
951
+ return 0.0
952
+ else:
953
+ return float(fracstring)
954
+
955
+ def _OnChangeSign(self, event):
956
+ ## dbg('NumCtrl::_OnChangeSign', indent=1)
957
+ self._typedSign = True
958
+ MaskedEditMixin._OnChangeSign(self, event)
959
+ ## dbg(indent=0)
960
+
961
+
962
+ def _disallowValue(self):
963
+ ## dbg('NumCtrl::_disallowValue')
964
+ # limited and -1 is out of bounds
965
+ if self._typedSign:
966
+ self._isNeg = False
967
+ if not wx.Validator.IsSilent():
968
+ wx.Bell()
969
+ sel_start, sel_to = self._GetSelection()
970
+ ## dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
971
+ wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
972
+ wx.CallAfter(self.SetSelection, sel_start, sel_to)
973
+
974
+
975
+ def _OnChangeField(self, event):
976
+ """
977
+ This routine enhances the base masked control _OnFieldChange(). It's job
978
+ is to ensure limits are imposed if limitOnFieldChange is enabled.
979
+ """
980
+ ## dbg('NumCtrl::_OnFieldChange', indent=1)
981
+ if self._limitOnFieldChange and not (self._min <= self.GetValue() <= self._max):
982
+ self._disallowValue()
983
+ ## dbg('oob - field change disallowed',indent=0)
984
+ return False
985
+ else:
986
+ ## dbg(indent=0)
987
+ return MaskedEditMixin._OnChangeField(self, event) # call the baseclass function
988
+
989
+
990
+ def _LostFocus(self):
991
+ """
992
+ On loss of focus, if limitOnFieldChange is set, ensure value conforms to limits.
993
+ """
994
+ ## dbg('NumCtrl::_LostFocus', indent=1)
995
+ if self._limitOnFieldChange:
996
+ ## dbg("limiting on loss of focus")
997
+ value = self.GetValue()
998
+ if self._min is not None and value < self._min:
999
+ ## dbg('Set to min value:', self._min)
1000
+ self._SetValue(self._toGUI(self._min))
1001
+
1002
+ elif self._max is not None and value > self._max:
1003
+ ## dbg('Setting to max value:', self._max)
1004
+ self._SetValue(self._toGUI(self._max))
1005
+ # (else do nothing.)
1006
+ # (else do nothing.)
1007
+ ## dbg(indent=0)
1008
+ return True
1009
+
1010
+
1011
+ def _SetValue(self, value):
1012
+ """
1013
+ This routine supersedes the base masked control _SetValue(). It is
1014
+ needed to ensure that the value of the control is always representable/convertible
1015
+ to a numeric return value (via GetValue().) This routine also handles
1016
+ automatic adjustment and grouping of the value without explicit intervention
1017
+ by the user.
1018
+ """
1019
+
1020
+ ## dbg('NumCtrl::_SetValue("%s")' % value, indent=1)
1021
+
1022
+ if( (self._fractionWidth and value.find(self._decimalChar) == -1) or
1023
+ (self._fractionWidth == 0 and value.find(self._decimalChar) != -1) ) :
1024
+ value = self._toGUI(value)
1025
+
1026
+ numvalue = self._GetNumValue(value)
1027
+ ## dbg('cleansed value: "%s"' % numvalue)
1028
+ replacement = None
1029
+
1030
+ if numvalue == "":
1031
+ if self._allowNone:
1032
+ ## dbg('calling base BaseMaskedTextCtrl._SetValue(self, "%s")' % value)
1033
+ BaseMaskedTextCtrl._SetValue(self, value)
1034
+ self.Refresh()
1035
+ ## dbg(indent=0)
1036
+ return
1037
+ elif self._min > 0 and self.IsLimited():
1038
+ replacement = self._min
1039
+ else:
1040
+ replacement = 0
1041
+ ## dbg('empty value; setting replacement:', replacement)
1042
+
1043
+ if replacement is None:
1044
+ # Go get the integer portion about to be set and verify its validity
1045
+ intstart, intend = self._fields[0]._extent
1046
+ ## dbg('intstart, intend:', intstart, intend)
1047
+ ## dbg('raw integer:"%s"' % value[intstart:intend])
1048
+ int_str = self._GetNumValue(value[intstart:intend])
1049
+ numval = self._fromGUI(value)
1050
+
1051
+ ## dbg('integer: "%s"' % int)
1052
+ try:
1053
+ # if a float value, this will implicitly verify against limits,
1054
+ # and generate an exception if out-of-bounds and limited
1055
+ # if not a float, it will just return 0.0, and we therefore
1056
+ # have to test against the limits explicitly after testing
1057
+ # special cases for handling -0 and empty controls...
1058
+ fracval = self.GetFraction(value)
1059
+ except ValueError as e:
1060
+ ## dbg('Exception:', e, 'must be out of bounds; disallow value')
1061
+ self._disallowValue()
1062
+ ## dbg(indent=0)
1063
+ return
1064
+
1065
+ if fracval == 0.0: # (can be 0 for floats as well as integers)
1066
+ # we have to do special testing to account for emptying controls, or -0
1067
+ # and/or just leaving the sign character or changing the sign,
1068
+ # so we can do appropriate things to the value of the control,
1069
+ # we can't just immediately test to see if the value is valid
1070
+ # If all of these special cases are not in play, THEN we can do
1071
+ # a limits check and see if the value is otherwise ok...
1072
+
1073
+ ## dbg('self._isNeg?', self._isNeg)
1074
+ if int_str == '-' and self._oldvalue < 0 and not self._typedSign:
1075
+ ## dbg('just a negative sign; old value < 0; setting replacement of 0')
1076
+ replacement = 0
1077
+ self._isNeg = False
1078
+ elif int_str[:2] == '-0':
1079
+ if self._oldvalue < 0:
1080
+ ## dbg('-0; setting replacement of 0')
1081
+ replacement = 0
1082
+ self._isNeg = False
1083
+ elif not self._limited or (self._min < -1 and self._max >= -1):
1084
+ ## dbg('-0; setting replacement of -1')
1085
+ replacement = -1
1086
+ self._isNeg = True
1087
+ else:
1088
+ # limited and -1 is out of bounds
1089
+ self._disallowValue()
1090
+ ## dbg(indent=0)
1091
+ return
1092
+
1093
+ elif int_str == '-' and (self._oldvalue >= 0 or self._typedSign):
1094
+ if not self._limited or (self._min < -1 and self._max >= -1):
1095
+ ## dbg('just a negative sign; setting replacement of -1')
1096
+ replacement = -1
1097
+ else:
1098
+ # limited and -1 is out of bounds
1099
+ self._disallowValue()
1100
+ ## dbg(indent=0)
1101
+ return
1102
+
1103
+ elif( self._typedSign
1104
+ and int_str.find('-') != -1
1105
+ and self._limited
1106
+ and not self._min <= numval <= self._max):
1107
+ # changed sign resulting in value that's now out-of-bounds;
1108
+ # disallow
1109
+ self._disallowValue()
1110
+ ## dbg(indent=0)
1111
+ return
1112
+
1113
+ if replacement is None:
1114
+ if int_str and int_str != '-':
1115
+ try:
1116
+ int(int_str)
1117
+ except ValueError:
1118
+ # integer requested is not legal. This can happen if the user
1119
+ # is attempting to insert a digit in the middle of the control
1120
+ # resulting in something like " 3 45". Disallow such actions:
1121
+ ## dbg('>>>>>>>>>>>>>>>> "%s" does not convert to a long!' % int)
1122
+ if not wx.Validator.IsSilent():
1123
+ wx.Bell()
1124
+ sel_start, sel_to = self._GetSelection()
1125
+ ## dbg('queuing reselection of (%d, %d)' % (sel_start, sel_to))
1126
+ wx.CallAfter(self.SetInsertionPoint, sel_start) # preserve current selection/position
1127
+ wx.CallAfter(self.SetSelection, sel_start, sel_to)
1128
+ ## dbg(indent=0)
1129
+ return
1130
+
1131
+ ## dbg('numvalue: "%s"' % numvalue.replace(' ', ''))
1132
+ # finally, (potentially re) verify that numvalue will pass any limits imposed:
1133
+ try:
1134
+ if self._fractionWidth:
1135
+ value = self._toGUI(float(numvalue))
1136
+ else:
1137
+ value = self._toGUI(int(numvalue))
1138
+ except ValueError as e:
1139
+ ## dbg('Exception:', e, 'must be out of bounds; disallow value')
1140
+ self._disallowValue()
1141
+ ## dbg(indent=0)
1142
+ return
1143
+
1144
+ ## dbg('modified value: "%s"' % value)
1145
+
1146
+
1147
+ self._typedSign = False # reset state var
1148
+
1149
+ if replacement is not None:
1150
+ # Value presented wasn't a legal number, but control should do something
1151
+ # reasonable instead:
1152
+ ## dbg('setting replacement value:', replacement)
1153
+ self._SetValue(self._toGUI(replacement))
1154
+ sel_start = BaseMaskedTextCtrl.GetValue(self).find(str(abs(replacement))) # find where it put the 1, so we can select it
1155
+ sel_to = sel_start + len(str(abs(replacement)))
1156
+ ## dbg('queuing selection of (%d, %d)' %(sel_start, sel_to))
1157
+ wx.CallAfter(self.SetInsertionPoint, sel_start)
1158
+ wx.CallAfter(self.SetSelection, sel_start, sel_to)
1159
+ ## dbg(indent=0)
1160
+ return
1161
+
1162
+ # Otherwise, apply appropriate formatting to value:
1163
+
1164
+ # Because we're intercepting the value and adjusting it
1165
+ # before a sign change is detected, we need to do this here:
1166
+ if '-' in value or '(' in value:
1167
+ self._isNeg = True
1168
+ else:
1169
+ self._isNeg = False
1170
+
1171
+ ## dbg('value:"%s"' % value, 'self._useParens:', self._useParens)
1172
+ if self._fractionWidth:
1173
+ adjvalue = self._adjustFloat(self._GetNumValue(value).replace('.',self._decimalChar))
1174
+ else:
1175
+ adjvalue = self._adjustInt(self._GetNumValue(value))
1176
+ ## dbg('adjusted value: "%s"' % adjvalue)
1177
+
1178
+
1179
+ sel_start, sel_to = self._GetSelection() # record current insertion point
1180
+ ## dbg('calling BaseMaskedTextCtrl._SetValue(self, "%s")' % adjvalue)
1181
+ BaseMaskedTextCtrl._SetValue(self, adjvalue)
1182
+ # After all actions so far scheduled, check that resulting cursor
1183
+ # position is appropriate, and move if not:
1184
+ wx.CallAfter(self._CheckInsertionPoint)
1185
+
1186
+ ## dbg('finished NumCtrl::_SetValue', indent=0)
1187
+
1188
+ def _CheckInsertionPoint(self):
1189
+ # If current insertion point is before the end of the integer and
1190
+ # its before the 1st digit, place it just after the sign position:
1191
+ ## dbg('NumCtrl::CheckInsertionPoint', indent=1)
1192
+ sel_start, sel_to = self._GetSelection()
1193
+ text = self._GetValue()
1194
+ if sel_to < self._fields[0]._extent[1] and text[sel_to] in (' ', '-', '('):
1195
+ text, signpos, right_signpos = self._getSignedValue()
1196
+ ## dbg('setting selection(%d, %d)' % (signpos+1, signpos+1))
1197
+ self.SetInsertionPoint(signpos+1)
1198
+ self.SetSelection(signpos+1, signpos+1)
1199
+ ## dbg(indent=0)
1200
+
1201
+
1202
+ def _OnErase( self, event=None, just_return_value=False ):
1203
+ """
1204
+ This overrides the base control _OnErase, so that erasing around
1205
+ grouping characters auto selects the digit before or after the
1206
+ grouping character, so that the erasure does the right thing.
1207
+ """
1208
+ ## dbg('NumCtrl::_OnErase', indent=1)
1209
+ if event is None: # called as action routine from Cut() operation.
1210
+ key = wx.WXK_DELETE
1211
+ else:
1212
+ key = event.GetKeyCode()
1213
+ #if grouping digits, make sure deletes next to group char always
1214
+ # delete next digit to appropriate side:
1215
+ if self._groupDigits:
1216
+ value = BaseMaskedTextCtrl.GetValue(self)
1217
+ sel_start, sel_to = self._GetSelection()
1218
+
1219
+ if key == wx.WXK_BACK:
1220
+ # if 1st selected char is group char, select to previous digit
1221
+ if sel_start > 0 and sel_start < len(self._mask) and value[sel_start:sel_to] == self._groupChar:
1222
+ self.SetInsertionPoint(sel_start-1)
1223
+ self.SetSelection(sel_start-1, sel_to)
1224
+
1225
+ # elif previous char is group char, select to previous digit
1226
+ elif sel_start > 1 and sel_start == sel_to and value[sel_start-1:sel_start] == self._groupChar:
1227
+ self.SetInsertionPoint(sel_start-2)
1228
+ self.SetSelection(sel_start-2, sel_to)
1229
+
1230
+ elif key == wx.WXK_DELETE:
1231
+ if( sel_to < len(self._mask) - 2 + (1 *self._useParens)
1232
+ and sel_start == sel_to
1233
+ and value[sel_to] == self._groupChar ):
1234
+ self.SetInsertionPoint(sel_start)
1235
+ self.SetSelection(sel_start, sel_to+2)
1236
+
1237
+ elif( sel_to < len(self._mask) - 2 + (1 *self._useParens)
1238
+ and value[sel_start:sel_to] == self._groupChar ):
1239
+ self.SetInsertionPoint(sel_start)
1240
+ self.SetSelection(sel_start, sel_to+1)
1241
+ ## dbg(indent=0)
1242
+ return BaseMaskedTextCtrl._OnErase(self, event, just_return_value)
1243
+
1244
+
1245
+ def OnTextChange( self, event ):
1246
+ """
1247
+ Handles an event indicating that the text control's value
1248
+ has changed, and issue EVT_NUM event.
1249
+
1250
+ .. note::
1251
+
1252
+ Using :meth:`TextCtrl.SetValue` to change the control's contents from
1253
+ within a EVT_CHAR handler can cause double text events. So we check
1254
+ for actual changes to the text before passing the events on.
1255
+ """
1256
+ ## dbg('NumCtrl::OnTextChange', indent=1)
1257
+ if not BaseMaskedTextCtrl._OnTextChange(self, event):
1258
+ ## dbg(indent=0)
1259
+ return
1260
+
1261
+ # else... legal value
1262
+
1263
+ value = self.GetValue()
1264
+ if value != self._oldvalue:
1265
+ try:
1266
+ self.GetEventHandler().ProcessEvent(
1267
+ NumberUpdatedEvent( self.GetId(), self.GetValue(), self ) )
1268
+ except ValueError:
1269
+ ## dbg(indent=0)
1270
+ return
1271
+ # let normal processing of the text continue
1272
+ event.Skip()
1273
+ self._oldvalue = value # record for next event
1274
+ ## dbg(indent=0)
1275
+
1276
+ def _GetValue(self):
1277
+ """
1278
+ Override of BaseMaskedTextCtrl to allow mixin to get the raw text value of the
1279
+ control with this function.
1280
+ """
1281
+ return wx.TextCtrl.GetValue(self)
1282
+
1283
+
1284
+ def GetValue(self):
1285
+ """
1286
+ Returns the current numeric value of the control.
1287
+ """
1288
+ return self._fromGUI( BaseMaskedTextCtrl.GetValue(self) )
1289
+
1290
+ def SetValue(self, value):
1291
+ """
1292
+ Sets the value of the control to the value specified.
1293
+ The resulting actual value of the control may be altered to
1294
+ conform with the bounds set on the control if limited,
1295
+ or colored if not limited but the value is out-of-bounds.
1296
+ A ValueError exception will be raised if an invalid value
1297
+ is specified.
1298
+
1299
+ :param integer `value`: new value
1300
+
1301
+ """
1302
+ ## dbg('NumCtrl::SetValue(%s)' % value, indent=1)
1303
+ BaseMaskedTextCtrl.SetValue( self, self._toGUI(value) )
1304
+ ## dbg(indent=0)
1305
+
1306
+ def ChangeValue(self, value):
1307
+ """
1308
+ Sets the value of the control to the value specified.
1309
+ The resulting actual value of the control may be altered to
1310
+ conform with the bounds set on the control if limited,
1311
+ or colored if not limited but the value is out-of-bounds.
1312
+ A ValueError exception will be raised if an invalid value
1313
+ is specified.
1314
+
1315
+ This method does not fire a change event.
1316
+
1317
+ :param integer `value`: new value
1318
+
1319
+ """
1320
+ ## dbg('NumCtrl::ChangeValue(%s)' % value, indent=1)
1321
+ BaseMaskedTextCtrl.ChangeValue( self, self._toGUI(value) )
1322
+ ## dbg(indent=0)
1323
+
1324
+
1325
+ def SetIntegerWidth(self, value):
1326
+ """
1327
+ Set the integer width of the control
1328
+
1329
+ :param integer `value`: the width value
1330
+
1331
+ """
1332
+ self.SetParameters(integerWidth=value)
1333
+
1334
+ def GetIntegerWidth(self):
1335
+ """
1336
+ Get the integer width.
1337
+ """
1338
+ return self._integerWidth
1339
+
1340
+ def SetFractionWidth(self, value):
1341
+ """
1342
+ Set the fraction width of the control
1343
+
1344
+ :param integer `value`: the width value
1345
+
1346
+ """
1347
+ self.SetParameters(fractionWidth=value)
1348
+
1349
+ def GetFractionWidth(self):
1350
+ """
1351
+ Get the fraction width.
1352
+ """
1353
+ return self._fractionWidth
1354
+
1355
+ def SetMin(self, min=None):
1356
+ """
1357
+ Sets the minimum value of the control. If a value of None
1358
+ is provided, then the control will have no explicit minimum value.
1359
+ If the value specified is greater than the current maximum value,
1360
+ then the function returns False and the minimum will not change from
1361
+ its current setting. On success, the function returns True.
1362
+
1363
+ If successful and the current value is lower than the new lower
1364
+ bound, if the control is limited, the value will be automatically
1365
+ adjusted to the new minimum value; if not limited, the value in the
1366
+ control will be colored as invalid.
1367
+
1368
+ If min > the max value allowed by the width of the control,
1369
+ the function will return False, and the min will not be set.
1370
+
1371
+ :param `min`: Minimum value for the control
1372
+ :type `min`: integer or None
1373
+
1374
+ """
1375
+ ## dbg('NumCtrl::SetMin(%s)' % repr(min), indent=1)
1376
+ if( self._max is None
1377
+ or min is None
1378
+ or (self._max is not None and self._max >= min) ):
1379
+ try:
1380
+ self.SetParameters(min=min)
1381
+ bRet = True
1382
+ except ValueError:
1383
+ bRet = False
1384
+ else:
1385
+ bRet = False
1386
+ ## dbg(indent=0)
1387
+ return bRet
1388
+
1389
+ def GetMin(self):
1390
+ """
1391
+ Gets the lower bound value of the control. It will return
1392
+ None if not specified.
1393
+ """
1394
+ return self._min
1395
+
1396
+ def SetMax(self, max=None):
1397
+ """
1398
+ Sets the maximum value of the control. If a value of None
1399
+ is provided, then the control will have no explicit maximum value.
1400
+ If the value specified is less than the current minimum value, then
1401
+ the function returns False and the maximum will not change from its
1402
+ current setting. On success, the function returns True.
1403
+
1404
+ If successful and the current value is greater than the new upper
1405
+ bound, if the control is limited the value will be automatically
1406
+ adjusted to this maximum value; if not limited, the value in the
1407
+ control will be colored as invalid.
1408
+
1409
+ If max > the max value allowed by the width of the control,
1410
+ the function will return False, and the max will not be set.
1411
+
1412
+ :param `max`: Minimum value for the control
1413
+ :type `max`: integer or None
1414
+
1415
+ """
1416
+ if( self._min is None
1417
+ or max is None
1418
+ or (self._min is not None and self._min <= max) ):
1419
+ try:
1420
+ self.SetParameters(max=max)
1421
+ bRet = True
1422
+ except ValueError:
1423
+ bRet = False
1424
+ else:
1425
+ bRet = False
1426
+
1427
+ return bRet
1428
+
1429
+ def GetMax(self):
1430
+ """
1431
+ Gets the maximum value of the control. It will return the current
1432
+ maximum integer, or None if not specified.
1433
+ """
1434
+ return self._max
1435
+
1436
+ def SetBounds(self, min=None, max=None):
1437
+ """
1438
+ This function is a convenience function for setting the min and max
1439
+ values at the same time. The function only applies the maximum bound
1440
+ if setting the minimum bound is successful, and returns True
1441
+ only if both operations succeed.
1442
+
1443
+ .. note:: leaving out an argument will remove the corresponding bound.
1444
+
1445
+ :param `min`: Minimum value for the control
1446
+ :type `min`: integer or None
1447
+ :param `max`: Minimum value for the control
1448
+ :type `max`: integer or None
1449
+
1450
+ """
1451
+ ret = self.SetMin(min)
1452
+ return ret and self.SetMax(max)
1453
+
1454
+
1455
+ def GetBounds(self):
1456
+ """
1457
+ This function returns a two-tuple (min,max), indicating the
1458
+ current bounds of the control. Each value can be None if
1459
+ that bound is not set.
1460
+ """
1461
+ return (self._min, self._max)
1462
+
1463
+
1464
+ def SetLimited(self, limited):
1465
+ """
1466
+ If called with a value of True, this function will cause the control
1467
+ to limit the value to fall within the bounds currently specified.
1468
+ If the control's value currently exceeds the bounds, it will then
1469
+ be limited accordingly.
1470
+
1471
+ If called with a value of False, this function will disable value
1472
+ limiting, but coloring of out-of-bounds values will still take
1473
+ place if bounds have been set for the control.
1474
+
1475
+ :param boolean `limited`: define value limiting
1476
+
1477
+ """
1478
+ self.SetParameters(limited = limited)
1479
+
1480
+
1481
+ def IsLimited(self):
1482
+ """
1483
+ Returns True if the control is currently limiting the
1484
+ value to fall within the current bounds.
1485
+ """
1486
+ return self._limited
1487
+
1488
+ def GetLimited(self):
1489
+ """ (For regularization of property accessors) """
1490
+ return self.IsLimited()
1491
+
1492
+ def SetLimitOnFieldChange(self, limit):
1493
+ """
1494
+ If called with a value of True, this function will cause the control
1495
+ to prevent navigation out of the current field if its value is out-of-bounds,
1496
+ and limit the value to fall within the bounds currently specified if the
1497
+ control loses focus.
1498
+
1499
+ If called with a value of False, this function will disable value
1500
+ limiting, but coloring of out-of-bounds values will still take
1501
+ place if bounds have been set for the control.
1502
+
1503
+ :param boolean `limit`: define value limiting
1504
+
1505
+ """
1506
+ self.SetParameters(limitOnFieldChange = limit)
1507
+
1508
+
1509
+ def IsLimitedOnFieldChange(self):
1510
+ """
1511
+ Returns True if the control is currently limiting the
1512
+ value to fall within the current bounds.
1513
+ """
1514
+ return self._limitOnFieldChange
1515
+
1516
+ def GetLimitOnFieldChange(self):
1517
+ """ (For regularization of property accessors) """
1518
+ return self.IsLimitedOnFieldChange()
1519
+
1520
+
1521
+ def IsInBounds(self, value=None):
1522
+ """
1523
+ Returns True if no value is specified and the current value
1524
+ of the control falls within the current bounds. This function can
1525
+ also be called with a value to see if that value would fall within
1526
+ the current bounds of the given control.
1527
+
1528
+ :param `value`: value to check
1529
+
1530
+ """
1531
+ ## dbg('IsInBounds(%s)' % repr(value), indent=1)
1532
+ if value is None:
1533
+ value = self.GetValue()
1534
+ else:
1535
+ try:
1536
+ value = self._GetNumValue(self._toGUI(value))
1537
+ except ValueError as e:
1538
+ ## dbg('error getting NumValue(self._toGUI(value)):', e, indent=0)
1539
+ return False
1540
+ if value.strip() == '':
1541
+ value = None
1542
+ elif self._fractionWidth:
1543
+ value = float(value)
1544
+ else:
1545
+ value = int(value)
1546
+
1547
+ min = self.GetMin()
1548
+ max = self.GetMax()
1549
+ if min is None: min = value
1550
+ if max is None: max = value
1551
+
1552
+ # if bounds set, and value is None, return False
1553
+ if value is None and (min is not None or max is not None):
1554
+ ## dbg('finished IsInBounds', indent=0)
1555
+ return 0
1556
+ else:
1557
+ ## dbg('finished IsInBounds', indent=0)
1558
+ return min <= value <= max
1559
+
1560
+
1561
+ def SetAllowNone(self, allow_none):
1562
+ """
1563
+ Change the behavior of the validation code, allowing control
1564
+ to have a value of None or not, as appropriate. If the value
1565
+ of the control is currently None, and allow_none is False, the
1566
+ value of the control will be set to the minimum value of the
1567
+ control, or 0 if no lower bound is set.
1568
+
1569
+ :param boolean `allow_none`: True if None is allowed
1570
+
1571
+ """
1572
+ self._allowNone = allow_none
1573
+ if not allow_none and self.GetValue() is None:
1574
+ min = self.GetMin()
1575
+ if min is not None: self.SetValue(min)
1576
+ else: self.SetValue(0)
1577
+
1578
+
1579
+ def IsNoneAllowed(self):
1580
+ return self._allowNone
1581
+
1582
+ def GetAllowNone(self):
1583
+ """ (For regularization of property accessors) """
1584
+ return self.IsNoneAllowed()
1585
+
1586
+ def SetAllowNegative(self, value):
1587
+ self.SetParameters(allowNegative=value)
1588
+
1589
+ def IsNegativeAllowed(self):
1590
+ return self._allowNegative
1591
+
1592
+ def GetAllowNegative(self):
1593
+ """ (For regularization of property accessors) """
1594
+ return self.IsNegativeAllowed()
1595
+
1596
+ def SetGroupDigits(self, value):
1597
+ self.SetParameters(groupDigits=value)
1598
+
1599
+ def IsGroupingAllowed(self):
1600
+ return self._groupDigits
1601
+
1602
+ def GetGroupDigits(self):
1603
+ """ (For regularization of property accessors) """
1604
+ return self.IsGroupingAllowed()
1605
+
1606
+ def SetGroupChar(self, value):
1607
+ self.SetParameters(groupChar=value)
1608
+
1609
+ def GetGroupChar(self):
1610
+ return self._groupChar
1611
+
1612
+ def SetDecimalChar(self, value):
1613
+ self.SetParameters(decimalChar=value)
1614
+
1615
+ def GetDecimalChar(self):
1616
+ return self._decimalChar
1617
+
1618
+ def SetSelectOnEntry(self, value):
1619
+ self.SetParameters(selectOnEntry=value)
1620
+
1621
+ def GetSelectOnEntry(self):
1622
+ return self._selectOnEntry
1623
+
1624
+ def SetAutoSize(self, value):
1625
+ self.SetParameters(autoSize=value)
1626
+
1627
+ def GetAutoSize(self):
1628
+ return self._autoSize
1629
+
1630
+ # (Other parameter accessors are inherited from base class)
1631
+
1632
+ def _toGUI( self, value, apply_limits = True ):
1633
+ """
1634
+ Conversion function used to set the value of the control; does
1635
+ type and bounds checking and raises ValueError if argument is
1636
+ not a valid value.
1637
+ """
1638
+ ## dbg('NumCtrl::_toGUI(%s)' % repr(value), indent=1)
1639
+ if value is None and self.IsNoneAllowed():
1640
+ ## dbg(indent=0)
1641
+ return self._template
1642
+
1643
+ elif isinstance(value, str):
1644
+ value = self._GetNumValue(value)
1645
+ ## dbg('cleansed num value: "%s"' % value)
1646
+ if value == "":
1647
+ if self.IsNoneAllowed():
1648
+ ## dbg(indent=0)
1649
+ return self._template
1650
+ else:
1651
+ ## dbg('exception raised:', e, indent=0)
1652
+ raise ValueError ('NumCtrl requires numeric value, passed %s'% repr(value) )
1653
+ # else...
1654
+ try:
1655
+ if self._fractionWidth or value.find('.') != -1:
1656
+ value = float(value)
1657
+ else:
1658
+ value = int(value)
1659
+ except Exception as e:
1660
+ ## dbg('exception raised:', e, indent=0)
1661
+ raise ValueError ('NumCtrl requires numeric value, passed %s'% repr(value) )
1662
+
1663
+ elif not isinstance(value, (int, float)):
1664
+ ## dbg(indent=0)
1665
+ raise ValueError (
1666
+ 'NumCtrl requires numeric value, passed %s'% repr(value) )
1667
+
1668
+ if not self._allowNegative and value < 0:
1669
+ raise ValueError (
1670
+ 'control configured to disallow negative values, passed %s'% repr(value) )
1671
+
1672
+ if self.IsLimited() and apply_limits:
1673
+ min = self.GetMin()
1674
+ max = self.GetMax()
1675
+ if not min is None and value < min:
1676
+ ## dbg(indent=0)
1677
+ raise ValueError (
1678
+ 'value %d is below minimum value of control'% value )
1679
+ if not max is None and value > max:
1680
+ ## dbg(indent=0)
1681
+ raise ValueError (
1682
+ 'value %d exceeds value of control'% value )
1683
+
1684
+ adjustwidth = len(self._mask) - (1 * self._useParens * self._signOk)
1685
+ ## dbg('len(%s):' % self._mask, len(self._mask))
1686
+ ## dbg('adjustwidth - groupSpace:', adjustwidth - self._groupSpace)
1687
+ ## dbg('adjustwidth:', adjustwidth)
1688
+ if self._fractionWidth == 0:
1689
+ s = str(int(value)).rjust(self._integerWidth)
1690
+ else:
1691
+ format = '%' + '%d.%df' % (self._integerWidth+self._fractionWidth+1, self._fractionWidth)
1692
+ s = format % float(value)
1693
+ ## dbg('s:"%s"' % s, 'len(s):', len(s))
1694
+ if len(s) > (adjustwidth - self._groupSpace):
1695
+ ## dbg(indent=0)
1696
+ raise ValueError ('value %s exceeds the integer width of the control (%d)' % (s, self._integerWidth))
1697
+ elif s[0] not in ('-', ' ') and self._allowNegative and len(s) == (adjustwidth - self._groupSpace):
1698
+ ## dbg(indent=0)
1699
+ raise ValueError ('value %s exceeds the integer width of the control (%d)' % (s, self._integerWidth))
1700
+
1701
+ s = s.rjust(adjustwidth).replace('.', self._decimalChar)
1702
+ if self._signOk and self._useParens:
1703
+ if s.find('-') != -1:
1704
+ s = s.replace('-', '(') + ')'
1705
+ else:
1706
+ s += ' '
1707
+ ## dbg('returned: "%s"' % s, indent=0)
1708
+ return s
1709
+
1710
+
1711
+ def _fromGUI( self, value ):
1712
+ """
1713
+ Conversion function used in getting the value of the control.
1714
+ """
1715
+ ## dbg(suspend=0)
1716
+ ## dbg('NumCtrl::_fromGUI(%s)' % value, indent=1)
1717
+ # One or more of the underlying text control implementations
1718
+ # issue an intermediate EVT_TEXT when replacing the control's
1719
+ # value, where the intermediate value is an empty string.
1720
+ # So, to ensure consistency and to prevent spurious ValueErrors,
1721
+ # we make the following test, and react accordingly:
1722
+ #
1723
+ if value.strip() == '':
1724
+ if not self.IsNoneAllowed():
1725
+ ## dbg('empty value; not allowed,returning 0', indent = 0)
1726
+ if self._fractionWidth:
1727
+ return 0.0
1728
+ else:
1729
+ return 0
1730
+ else:
1731
+ ## dbg('empty value; returning None', indent = 0)
1732
+ return None
1733
+ else:
1734
+ value = self._GetNumValue(value)
1735
+ ## dbg('Num value: "%s"' % value)
1736
+ if self._fractionWidth:
1737
+ try:
1738
+ ## dbg(indent=0)
1739
+ return float( value )
1740
+ except ValueError:
1741
+ ## dbg("couldn't convert to float; returning None")
1742
+ return None
1743
+ else:
1744
+ raise ValueError
1745
+ else:
1746
+ try:
1747
+ ## dbg(indent=0)
1748
+ return int( value )
1749
+ except ValueError:
1750
+ try:
1751
+ ## dbg(indent=0)
1752
+ return int( value )
1753
+ except ValueError:
1754
+ ## dbg("couldn't convert to long; returning None")
1755
+ return None
1756
+
1757
+ else:
1758
+ raise ValueError
1759
+ else:
1760
+ ## dbg('exception occurred; returning None')
1761
+ return None
1762
+
1763
+
1764
+ def _Paste( self, value=None, raise_on_invalid=False, just_return_value=False ):
1765
+ """
1766
+ Preprocessor for base control paste; if value needs to be right-justified
1767
+ to fit in control, do so prior to paste:
1768
+ """
1769
+ ## dbg('NumCtrl::_Paste (value = "%s")' % value, indent=1)
1770
+ if value is None:
1771
+ paste_text = self._getClipboardContents()
1772
+ else:
1773
+ paste_text = value
1774
+ sel_start, sel_to = self._GetSelection()
1775
+ orig_sel_start = sel_start
1776
+ orig_sel_to = sel_to
1777
+ ## dbg('selection:', (sel_start, sel_to))
1778
+ old_value = self._GetValue()
1779
+
1780
+ #
1781
+ field = self._FindField(sel_start)
1782
+ edit_start, edit_end = field._extent
1783
+
1784
+ # handle possibility of groupChar being a space:
1785
+ newtext = paste_text.lstrip()
1786
+ lspace_count = len(paste_text) - len(newtext)
1787
+ paste_text = ' ' * lspace_count + newtext.replace(self._groupChar, '').replace('(', '-').replace(')','')
1788
+
1789
+ if field._insertRight and self._groupDigits:
1790
+ # want to paste to the left; see if it will fit:
1791
+ left_text = old_value[edit_start:sel_start].lstrip()
1792
+ ## dbg('len(left_text):', len(left_text))
1793
+ ## dbg('len(paste_text):', len(paste_text))
1794
+ ## dbg('sel_start - (len(left_text) + len(paste_text)) >= edit_start?', sel_start - (len(left_text) + len(paste_text)) >= edit_start)
1795
+ if sel_start - (len(left_text) + len(paste_text)) >= edit_start:
1796
+ # will fit! create effective paste text, and move cursor back to do so:
1797
+ paste_text = left_text + paste_text
1798
+ sel_start -= len(paste_text)
1799
+ sel_start += sel_to - orig_sel_start # decrease by amount selected
1800
+ else:
1801
+ ## dbg("won't fit left;", 'paste text remains: "%s"' % paste_text)
1802
+ ## dbg('adjusted start before accounting for grouping:', sel_start)
1803
+ ## dbg('adjusted paste_text before accounting for grouping: "%s"' % paste_text)
1804
+ pass
1805
+ if self._groupDigits and sel_start != orig_sel_start:
1806
+ left_len = len(old_value[:sel_to].lstrip())
1807
+ # remove group chars from adjusted paste string, and left pad to wipe out
1808
+ # old characters, so that selection will remove the right chars, and
1809
+ # readjust will do the right thing:
1810
+ paste_text = paste_text.replace(self._groupChar,'')
1811
+ adjcount = left_len - len(paste_text)
1812
+ paste_text = ' ' * adjcount + paste_text
1813
+ sel_start = sel_to - len(paste_text)
1814
+ ## dbg('adjusted start after accounting for grouping:', sel_start)
1815
+ ## dbg('adjusted paste_text after accounting for grouping: "%s"' % paste_text)
1816
+ self.SetInsertionPoint(sel_to)
1817
+ self.SetSelection(sel_start, sel_to)
1818
+
1819
+ new_text, replace_to = MaskedEditMixin._Paste(self,
1820
+ paste_text,
1821
+ raise_on_invalid=raise_on_invalid,
1822
+ just_return_value=True)
1823
+ self._SetInsertionPoint(orig_sel_to)
1824
+ self._SetSelection(orig_sel_start, orig_sel_to)
1825
+ if not just_return_value and new_text is not None:
1826
+ if new_text != self._GetValue():
1827
+ self.modified = True
1828
+ if new_text == '':
1829
+ self.ClearValue()
1830
+ else:
1831
+ wx.CallAfter(self._SetValue, new_text)
1832
+ wx.CallAfter(self._SetInsertionPoint, replace_to)
1833
+ ## dbg(indent=0)
1834
+ else:
1835
+ ## dbg(indent=0)
1836
+ return new_text, replace_to
1837
+
1838
+ def _Undo(self, value=None, prev=None):
1839
+ '''numctrl's undo is more complicated than the base control's, due to
1840
+ grouping characters; we don't want to consider them when calculating
1841
+ the undone portion.'''
1842
+ ## dbg('NumCtrl::_Undo', indent=1)
1843
+ if value is None: value = self._GetValue()
1844
+ if prev is None: prev = self._prevValue
1845
+ if not self._groupDigits:
1846
+ ignore, (new_sel_start, new_sel_to) = BaseMaskedTextCtrl._Undo(self, value, prev, just_return_results = True)
1847
+ self._SetValue(prev)
1848
+ self._SetInsertionPoint(new_sel_start)
1849
+ self._SetSelection(new_sel_start, new_sel_to)
1850
+ self._prevSelection = (new_sel_start, new_sel_to)
1851
+ ## dbg('resetting "prev selection" to', self._prevSelection)
1852
+ ## dbg(indent=0)
1853
+ return
1854
+ # else...
1855
+ sel_start, sel_to = self._prevSelection
1856
+ edit_start, edit_end = self._FindFieldExtent(0)
1857
+
1858
+ adjvalue = self._GetNumValue(value).rjust(self._masklength)
1859
+ adjprev = self._GetNumValue(prev ).rjust(self._masklength)
1860
+
1861
+ # move selection to account for "ungrouped" value:
1862
+ left_text = value[sel_start:].lstrip()
1863
+ numleftgroups = len(left_text) - len(left_text.replace(self._groupChar, ''))
1864
+ adjsel_start = sel_start + numleftgroups
1865
+ right_text = value[sel_to:].lstrip()
1866
+ numrightgroups = len(right_text) - len(right_text.replace(self._groupChar, ''))
1867
+ adjsel_to = sel_to + numrightgroups
1868
+ ## dbg('adjusting "previous" selection from', (sel_start, sel_to), 'to:', (adjsel_start, adjsel_to))
1869
+ self._prevSelection = (adjsel_start, adjsel_to)
1870
+
1871
+ # determine appropriate selection for ungrouped undo
1872
+ ignore, (new_sel_start, new_sel_to) = BaseMaskedTextCtrl._Undo(self, adjvalue, adjprev, just_return_results = True)
1873
+
1874
+ # adjust new selection based on grouping:
1875
+ left_len = edit_end - new_sel_start
1876
+ numleftgroups = left_len / 3
1877
+ new_sel_start -= numleftgroups
1878
+ if numleftgroups and left_len % 3 == 0:
1879
+ new_sel_start += 1
1880
+
1881
+ if new_sel_start < self._masklength and prev[new_sel_start] == self._groupChar:
1882
+ new_sel_start += 1
1883
+
1884
+ right_len = edit_end - new_sel_to
1885
+ numrightgroups = right_len / 3
1886
+ new_sel_to -= numrightgroups
1887
+
1888
+ if new_sel_to and prev[new_sel_to-1] == self._groupChar:
1889
+ new_sel_to -= 1
1890
+
1891
+ if new_sel_start > new_sel_to:
1892
+ new_sel_to = new_sel_start
1893
+
1894
+ # for numbers, we don't care about leading whitespace; adjust selection if
1895
+ # it includes leading space.
1896
+ prev_stripped = prev.lstrip()
1897
+ prev_start = self._masklength - len(prev_stripped)
1898
+ if new_sel_start < prev_start:
1899
+ new_sel_start = prev_start
1900
+
1901
+ ## dbg('adjusted selection accounting for grouping:', (new_sel_start, new_sel_to))
1902
+ self._SetValue(prev)
1903
+ self._SetInsertionPoint(new_sel_start)
1904
+ self._SetSelection(new_sel_start, new_sel_to)
1905
+ self._prevSelection = (new_sel_start, new_sel_to)
1906
+ ## dbg('resetting "prev selection" to', self._prevSelection)
1907
+ ## dbg(indent=0)
1908
+
1909
+ #===========================================================================
1910
+
1911
+ if __name__ == '__main__':
1912
+
1913
+ import traceback
1914
+
1915
+ class myDialog(wx.Dialog):
1916
+ def __init__(self, parent, id, title,
1917
+ pos = wx.DefaultPosition, size = wx.DefaultSize,
1918
+ style = wx.DEFAULT_DIALOG_STYLE ):
1919
+ wx.Dialog.__init__(self, parent, id, title, pos, size, style)
1920
+
1921
+ self.int_ctrl = NumCtrl(self, wx.ID_ANY, size=(55,20))
1922
+ self.OK = wx.Button( self, wx.ID_OK, "OK")
1923
+ self.Cancel = wx.Button( self, wx.ID_CANCEL, "Cancel")
1924
+
1925
+ vs = wx.BoxSizer( wx.VERTICAL )
1926
+ vs.Add( self.int_ctrl, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
1927
+ hs = wx.BoxSizer( wx.HORIZONTAL )
1928
+ hs.Add( self.OK, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
1929
+ hs.Add( self.Cancel, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
1930
+ vs.Add(hs, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
1931
+
1932
+ self.SetAutoLayout( True )
1933
+ self.SetSizer( vs )
1934
+ vs.Fit( self )
1935
+ vs.SetSizeHints( self )
1936
+ self.Bind(EVT_NUM, self.OnChange, self.int_ctrl)
1937
+
1938
+ def OnChange(self, event):
1939
+ print('value now', event.GetValue())
1940
+
1941
+ class TestApp(wx.App):
1942
+ def OnInit(self):
1943
+ try:
1944
+ self.frame = wx.Frame(None, -1, "Test", (20,20), (120,100) )
1945
+ self.panel = wx.Panel(self.frame, -1)
1946
+ button = wx.Button(self.panel, -1, "Push Me", (20, 20))
1947
+ self.Bind(wx.EVT_BUTTON, self.OnClick, button)
1948
+ except:
1949
+ traceback.print_exc()
1950
+ return False
1951
+ return True
1952
+
1953
+ def OnClick(self, event):
1954
+ dlg = myDialog(self.panel, -1, "test NumCtrl")
1955
+ dlg.int_ctrl.SetValue(501)
1956
+ dlg.int_ctrl.SetInsertionPoint(1)
1957
+ dlg.int_ctrl.SetSelection(1,2)
1958
+ rc = dlg.ShowModal()
1959
+ print('final value', dlg.int_ctrl.GetValue())
1960
+ del dlg
1961
+ self.frame.Destroy()
1962
+
1963
+ def Show(self):
1964
+ self.frame.Show(True)
1965
+
1966
+ try:
1967
+ app = TestApp(0)
1968
+ app.Show()
1969
+ app.MainLoop()
1970
+ except:
1971
+ traceback.print_exc()
1972
+
1973
+ __i=0
1974
+ ## To-Do's:
1975
+ ## =============================##
1976
+ ## 1. Add support for printf-style format specification.
1977
+ ## 2. Add option for repositioning on 'illegal' insertion point.
1978
+ ##
1979
+ ## Version 1.4
1980
+ ## 1. In response to user request, added limitOnFieldChange feature, so that
1981
+ ## out-of-bounds values can be temporarily added to the control, but should
1982
+ ## navigation be attempted out of an invalid field, it will not navigate,
1983
+ ## and if focus is lost on a control so limited with an invalid value, it
1984
+ ## will change the value to the nearest bound.
1985
+ ##
1986
+ ## Version 1.3
1987
+ ## 1. fixed to allow space for a group char.
1988
+ ##
1989
+ ## Version 1.2
1990
+ ## 1. Allowed select/replace digits.
1991
+ ## 2. Fixed undo to ignore grouping chars.
1992
+ ##
1993
+ ## Version 1.1
1994
+ ## 1. Fixed .SetIntegerWidth() and .SetFractionWidth() functions.
1995
+ ## 2. Added autoSize parameter, to allow manual sizing of the control.
1996
+ ## 3. Changed inheritance to use wxBaseMaskedTextCtrl, to remove exposure of
1997
+ ## nonsensical parameter methods from the control, so it will work
1998
+ ## properly with Boa.
1999
+ ## 4. Fixed allowNone bug found by user sameerc1@grandecom.net
2000
+ ##