wrap.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. """
  2. @package gui_core.wrap
  3. @brief Core wrapped wxpython widgets
  4. Classes:
  5. - wrap::GSpinCtrl
  6. (C) 2016 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Anna Petrasova <kratochanna gmail.com>
  10. """
  11. import sys
  12. import wx
  13. import wx.lib.agw.floatspin as fs
  14. import wx.lib.colourselect as csel
  15. import wx.lib.filebrowsebutton as filebrowse
  16. import wx.lib.scrolledpanel as scrolled
  17. from wx.lib import expando
  18. from wx.lib import buttons
  19. try:
  20. import wx.lib.agw.customtreectrl as CT
  21. except ImportError:
  22. import wx.lib.customtreectrl as CT
  23. from core.globalvar import CheckWxVersion, gtk3, wxPythonPhoenix
  24. if wxPythonPhoenix:
  25. import wx.adv
  26. from wx.adv import OwnerDrawnComboBox as OwnerDrawnComboBox_
  27. from wx.adv import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
  28. from wx.adv import BitmapComboBox as BitmapComboBox_
  29. from wx.adv import HyperlinkCtrl as HyperlinkCtrl_
  30. from wx.adv import HL_ALIGN_LEFT, HL_CONTEXTMENU
  31. ComboPopup = wx.ComboPopup
  32. wxComboCtrl = wx.ComboCtrl
  33. else:
  34. import wx.combo
  35. from wx.combo import OwnerDrawnComboBox as OwnerDrawnComboBox_
  36. from wx.combo import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
  37. from wx.combo import BitmapComboBox as BitmapComboBox_
  38. from wx import HyperlinkCtrl as HyperlinkCtrl_
  39. from wx import HL_ALIGN_LEFT, HL_CONTEXTMENU
  40. ComboPopup = wx.combo.ComboPopup
  41. wxComboCtrl = wx.combo.ComboCtrl
  42. if wxPythonPhoenix and CheckWxVersion([4, 0, 3, 0]):
  43. from wx import NewIdRef as NewId
  44. else:
  45. from wx import NewId # noqa: F401
  46. def convertToInt(argsOrKwargs, roundVal=False):
  47. """Convert args, kwargs float value to int
  48. :param tuple/list/dict argsOrKwargs: args or kwargs
  49. :param bool roundVal: True if you want round float value
  50. return list or dict
  51. """
  52. result = {} if isinstance(argsOrKwargs, dict) else []
  53. j = None
  54. for i in argsOrKwargs:
  55. if isinstance(result, dict):
  56. i, j = argsOrKwargs[i], i
  57. if isinstance(i, float):
  58. if roundVal:
  59. i = round(i)
  60. i = int(i)
  61. result.update({j: i}) if j else result.append(i)
  62. return result
  63. def IsDark():
  64. """Detects if used theme is dark.
  65. Wraps wx method for different versions."""
  66. def luminance(c):
  67. return (0.299 * c.Red() + 0.587 * c.Green() + 0.114 * c.Blue()) / 255
  68. if hasattr(wx.SystemSettings, "GetAppearance"):
  69. return wx.SystemSettings.GetAppearance().IsDark()
  70. # for older wx
  71. bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
  72. fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
  73. return luminance(fg) - luminance(bg) > 0.2
  74. def BitmapFromImage(image, depth=-1):
  75. if wxPythonPhoenix:
  76. return wx.Bitmap(img=image, depth=depth)
  77. else:
  78. return wx.BitmapFromImage(image, depth=depth)
  79. def ImageFromBitmap(bitmap):
  80. if wxPythonPhoenix:
  81. return bitmap.ConvertToImage()
  82. else:
  83. return wx.ImageFromBitmap(bitmap)
  84. def EmptyBitmap(width, height, depth=-1):
  85. if wxPythonPhoenix:
  86. return wx.Bitmap(width=width, height=height, depth=depth)
  87. else:
  88. return wx.EmptyBitmap(width=width, height=height, depth=depth)
  89. def EmptyImage(width, height, clear=True):
  90. if wxPythonPhoenix:
  91. return wx.Image(width=width, height=height, clear=clear)
  92. else:
  93. return wx.EmptyImage(width=width, height=height, clear=clear)
  94. def StockCursor(cursorId):
  95. if wxPythonPhoenix:
  96. return wx.Cursor(cursorId=cursorId)
  97. else:
  98. return wx.StockCursor(cursorId)
  99. class Window(wx.Window):
  100. """Wrapper around wx.Window to have more control
  101. over the widget on different platforms/wxpython versions"""
  102. def __init__(self, *args, **kwargs):
  103. wx.Window.__init__(self, *args, **kwargs)
  104. def SetToolTip(self, tip):
  105. if wxPythonPhoenix:
  106. if tip is None:
  107. wx.Window.UnsetToolTip(self)
  108. else:
  109. wx.Window.SetToolTip(self, tipString=tip)
  110. else:
  111. if tip is None:
  112. wx.Window.SetToolTip(self, tip)
  113. else:
  114. wx.Window.SetToolTipString(self, tip)
  115. class Panel(wx.Panel):
  116. """Wrapper around wx.Panel to have more control
  117. over the widget on different platforms/wxpython versions"""
  118. def __init__(self, *args, **kwargs):
  119. wx.Panel.__init__(self, *args, **kwargs)
  120. def SetToolTip(self, tip):
  121. if wxPythonPhoenix:
  122. wx.Panel.SetToolTip(self, tipString=tip)
  123. else:
  124. wx.Panel.SetToolTipString(self, tip)
  125. class Slider(wx.Slider):
  126. """Wrapper around wx.Slider to have more control
  127. over the widget on different platforms/wxpython versions"""
  128. def __init__(self, *args, **kwargs):
  129. args = convertToInt(argsOrKwargs=args)
  130. kwargs = convertToInt(argsOrKwargs=kwargs)
  131. wx.Slider.__init__(self, *args, **kwargs)
  132. def SetRange(self, minValue, maxValue):
  133. wx.Slider.SetRange(self, int(minValue), int(maxValue))
  134. def SetValue(self, value):
  135. wx.Slider.SetValue(self, int(value))
  136. class SpinCtrl(wx.SpinCtrl):
  137. """Wrapper around wx.SpinCtrl to have more control
  138. over the widget on different platforms"""
  139. gtk3MinSize = 130
  140. def __init__(self, *args, **kwargs):
  141. args = convertToInt(argsOrKwargs=args)
  142. kwargs = convertToInt(argsOrKwargs=kwargs)
  143. if gtk3:
  144. if "size" in kwargs:
  145. kwargs["size"] = wx.Size(
  146. max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
  147. )
  148. else:
  149. kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
  150. wx.SpinCtrl.__init__(self, *args, **kwargs)
  151. def SetToolTip(self, tip):
  152. if wxPythonPhoenix:
  153. wx.SpinCtrl.SetToolTip(self, tipString=tip)
  154. else:
  155. wx.SpinCtrl.SetToolTipString(self, tip)
  156. class FloatSpin(fs.FloatSpin):
  157. """Wrapper around fs.FloatSpin to have more control
  158. over the widget on different platforms"""
  159. gtk3MinSize = 130
  160. def __init__(self, *args, **kwargs):
  161. if gtk3:
  162. if "size" in kwargs:
  163. kwargs["size"] = wx.Size(
  164. max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
  165. )
  166. else:
  167. kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
  168. fs.FloatSpin.__init__(self, *args, **kwargs)
  169. def SetToolTip(self, tip):
  170. if wxPythonPhoenix:
  171. fs.FloatSpin.SetToolTip(self, tipString=tip)
  172. else:
  173. fs.FloatSpin.SetToolTipString(self, tip)
  174. class Button(wx.Button):
  175. """Wrapper around wx.Button to have more control
  176. over the widget on different platforms/wxpython versions"""
  177. def __init__(self, *args, **kwargs):
  178. wx.Button.__init__(self, *args, **kwargs)
  179. def SetToolTip(self, tip):
  180. if wxPythonPhoenix:
  181. wx.Button.SetToolTip(self, tipString=tip)
  182. else:
  183. wx.Button.SetToolTipString(self, tip)
  184. class ClearButton(Button):
  185. """Wrapper around a Button with stock id wx.ID_CLEAR,
  186. to disable default key binding on certain platforms"""
  187. def __init__(self, *args, **kwargs):
  188. Button.__init__(self, *args, **kwargs)
  189. self.SetId(wx.ID_CLEAR)
  190. if sys.platform == "darwin":
  191. self.SetLabel(_("Clear"))
  192. else:
  193. self.SetLabel(_("&Clear"))
  194. class CancelButton(Button):
  195. """Wrapper around a Button with stock id wx.ID_CANCEL, to disable
  196. default key binding on certain platforms/wxpython versions"""
  197. def __init__(self, *args, **kwargs):
  198. Button.__init__(self, *args, **kwargs)
  199. self.SetId(wx.ID_CANCEL)
  200. if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
  201. self.SetLabel(_("Cancel"))
  202. else:
  203. self.SetLabel(_("&Cancel"))
  204. class CloseButton(Button):
  205. """Wrapper around a Close labeled Button with stock id wx.ID_CANCEL
  206. to disable default key binding on certain platforms/wxpython versions"""
  207. def __init__(self, *args, **kwargs):
  208. Button.__init__(self, *args, **kwargs)
  209. self.SetId(wx.ID_CANCEL)
  210. if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
  211. self.SetLabel(_("Close"))
  212. else:
  213. self.SetLabel(_("&Close"))
  214. class ApplyButton(Button):
  215. """Wrapper around a Button with stock id wx.ID_APPLY,
  216. to disable default key binding on certain platforms"""
  217. def __init__(self, *args, **kwargs):
  218. Button.__init__(self, *args, **kwargs)
  219. self.SetId(wx.ID_APPLY)
  220. if sys.platform == "darwin":
  221. self.SetLabel(_("Apply"))
  222. else:
  223. self.SetLabel(_("&Apply"))
  224. class RadioButton(wx.RadioButton):
  225. """Wrapper around wx.RadioButton to have more control
  226. over the widget on different platforms/wxpython versions"""
  227. def __init__(self, *args, **kwargs):
  228. wx.RadioButton.__init__(self, *args, **kwargs)
  229. def SetToolTip(self, tip):
  230. if wxPythonPhoenix:
  231. wx.RadioButton.SetToolTip(self, tipString=tip)
  232. else:
  233. wx.RadioButton.SetToolTipString(self, tip)
  234. class BitmapButton(wx.BitmapButton):
  235. """Wrapper around wx.BitmapButton to have more control
  236. over the widget on different platforms/wxpython versions"""
  237. def __init__(self, *args, **kwargs):
  238. wx.BitmapButton.__init__(self, *args, **kwargs)
  239. def SetToolTip(self, tip):
  240. if wxPythonPhoenix:
  241. wx.BitmapButton.SetToolTip(self, tipString=tip)
  242. else:
  243. wx.BitmapButton.SetToolTipString(self, tip)
  244. class GenBitmapButton(buttons.GenBitmapButton):
  245. """Wrapper around GenBitmapButton to have more control
  246. over the widget on different platforms/wxpython versions"""
  247. def __init__(self, *args, **kwargs):
  248. buttons.GenBitmapButton.__init__(self, *args, **kwargs)
  249. def SetToolTip(self, tip):
  250. if wxPythonPhoenix:
  251. buttons.GenBitmapButton.SetToolTip(self, tipString=tip)
  252. else:
  253. buttons.GenBitmapButton.SetToolTipString(self, tip)
  254. class ToggleButton(wx.ToggleButton):
  255. """Wrapper around wx.ToggleButton to have more control
  256. over the widget on different platforms/wxpython versions"""
  257. def __init__(self, *args, **kwargs):
  258. wx.ToggleButton.__init__(self, *args, **kwargs)
  259. def SetToolTip(self, tip):
  260. if wxPythonPhoenix:
  261. wx.ToggleButton.SetToolTip(self, tipString=tip)
  262. else:
  263. wx.ToggleButton.SetToolTipString(self, tip)
  264. class StaticText(wx.StaticText):
  265. """Wrapper around wx.StaticText to have more control
  266. over the widget on different platforms/wxpython versions"""
  267. def __init__(self, *args, **kwargs):
  268. wx.StaticText.__init__(self, *args, **kwargs)
  269. def SetToolTip(self, tip):
  270. if wxPythonPhoenix:
  271. wx.StaticText.SetToolTip(self, tip)
  272. else:
  273. wx.StaticText.SetToolTipString(self, tip)
  274. class StaticBox(wx.StaticBox):
  275. """Wrapper around wx.StaticBox to have more control
  276. over the widget on different platforms/wxpython versions"""
  277. def __init__(self, *args, **kwargs):
  278. wx.StaticBox.__init__(self, *args, **kwargs)
  279. def SetToolTip(self, tip):
  280. if wxPythonPhoenix:
  281. wx.StaticBox.SetToolTip(self, tipString=tip)
  282. else:
  283. wx.StaticBox.SetToolTipString(self, tip)
  284. class CheckListBox(wx.CheckListBox):
  285. """Wrapper around wx.CheckListBox to have more control
  286. over the widget on different platforms/wxpython versions"""
  287. def __init__(self, *args, **kwargs):
  288. wx.CheckListBox.__init__(self, *args, **kwargs)
  289. def SetToolTip(self, tip):
  290. if wxPythonPhoenix:
  291. wx.CheckListBox.SetToolTip(self, tipString=tip)
  292. else:
  293. wx.CheckListBox.SetToolTipString(self, tip)
  294. class TextCtrl(wx.TextCtrl):
  295. """Wrapper around wx.TextCtrl to have more control
  296. over the widget on different platforms/wxpython versions"""
  297. def __init__(self, *args, **kwargs):
  298. wx.TextCtrl.__init__(self, *args, **kwargs)
  299. def SetToolTip(self, tip):
  300. if wxPythonPhoenix:
  301. wx.TextCtrl.SetToolTip(self, tipString=tip)
  302. else:
  303. wx.TextCtrl.SetToolTipString(self, tip)
  304. class SearchCtrl(wx.SearchCtrl):
  305. """Wrapper around wx.SearchCtrl to have more control
  306. over the widget on different platforms/wxpython versions"""
  307. def __init__(self, *args, **kwargs):
  308. wx.SearchCtrl.__init__(self, *args, **kwargs)
  309. def SetToolTip(self, tip):
  310. if wxPythonPhoenix:
  311. wx.SearchCtrl.SetToolTip(self, tipString=tip)
  312. else:
  313. wx.SearchCtrl.SetToolTipString(self, tip)
  314. class ListCtrl(wx.ListCtrl):
  315. """Wrapper around wx.ListCtrl to have more control
  316. over the widget on different platforms/wxpython versions"""
  317. def __init__(self, *args, **kwargs):
  318. wx.ListCtrl.__init__(self, *args, **kwargs)
  319. def InsertItem(self, index, label, imageIndex=-1):
  320. if wxPythonPhoenix:
  321. return wx.ListCtrl.InsertItem(
  322. self, index=index, label=label, imageIndex=imageIndex
  323. )
  324. else:
  325. return wx.ListCtrl.InsertStringItem(
  326. self, index=index, label=label, imageIndex=imageIndex
  327. )
  328. def SetItem(self, index, column, label, imageId=-1):
  329. if wxPythonPhoenix:
  330. return wx.ListCtrl.SetItem(
  331. self, index=index, column=column, label=label, imageId=imageId
  332. )
  333. else:
  334. return wx.ListCtrl.SetStringItem(
  335. self, index=index, col=column, label=label, imageId=imageId
  336. )
  337. def CheckItem(self, item, check=True):
  338. """Uses either deprecated listmix.CheckListCtrlMixin
  339. or new checkbox implementation in wx.ListCtrl since 4.1.0"""
  340. if hasattr(self, "HasCheckBoxes"):
  341. wx.ListCtrl.CheckItem(self, item, check)
  342. else:
  343. super(ListCtrl, self).CheckItem(item, check)
  344. def IsItemChecked(self, item):
  345. if hasattr(self, "HasCheckBoxes"):
  346. return wx.ListCtrl.IsItemChecked(self, item)
  347. else:
  348. return super(ListCtrl, self).IsChecked(item)
  349. if CheckWxVersion([4, 1, 0]):
  350. class CheckListCtrlMixin:
  351. """This class pretends to be deprecated CheckListCtrlMixin mixin and
  352. only enables checkboxes in new versions of ListCtrl"""
  353. def __init__(self):
  354. self.EnableCheckBoxes(True)
  355. self.AssignImageList(wx.ImageList(16, 16), wx.IMAGE_LIST_SMALL)
  356. else:
  357. import wx.lib.mixins.listctrl as listmix
  358. class CheckListCtrlMixin(listmix.CheckListCtrlMixin):
  359. """Wrapper for deprecated mixin"""
  360. def __init__(self):
  361. listmix.CheckListCtrlMixin.__init__(self)
  362. class TreeCtrl(wx.TreeCtrl):
  363. """Wrapper around wx.TreeCtrl to have more control
  364. over the widget on different platforms/wxpython versions"""
  365. def __init__(self, *args, **kwargs):
  366. wx.TreeCtrl.__init__(self, *args, **kwargs)
  367. def AppendItem(self, parent, text, image=-1, selImage=-1, data=None):
  368. if wxPythonPhoenix:
  369. return wx.TreeCtrl.AppendItem(self, parent, text, image, selImage, data)
  370. else:
  371. return wx.TreeCtrl.AppendItem(
  372. self, parent, text, image, selImage, wx.TreeItemData(data)
  373. )
  374. def GetItemData(self, item):
  375. if wxPythonPhoenix:
  376. return wx.TreeCtrl.GetItemData(self, item)
  377. else:
  378. return wx.TreeCtrl.GetPyData(self, item)
  379. class CustomTreeCtrl(CT.CustomTreeCtrl):
  380. """Wrapper around wx.lib.agw.customtreectrl to have more control
  381. over the widget on different platforms/wxpython versions"""
  382. def __init__(self, *args, **kwargs):
  383. CT.CustomTreeCtrl.__init__(self, *args, **kwargs)
  384. def SetToolTip(self, tip):
  385. if wxPythonPhoenix:
  386. CT.CustomTreeCtrl.SetToolTip(self, tipString=tip)
  387. else:
  388. CT.CustomTreeCtrl.SetToolTipString(self, tip)
  389. class ToolBar(wx.ToolBar):
  390. """Wrapper around wx.ToolBar to have more control
  391. over the widget on different platforms/wxpython versions"""
  392. def __init__(self, *args, **kwargs):
  393. wx.ToolBar.__init__(self, *args, **kwargs)
  394. def AddLabelTool(
  395. self,
  396. toolId,
  397. label,
  398. bitmap,
  399. bmpDisabled=wx.NullBitmap,
  400. kind=0,
  401. shortHelpString="",
  402. longHelpString="",
  403. clientData=None,
  404. ):
  405. if wxPythonPhoenix:
  406. return wx.ToolBar.AddTool(
  407. self,
  408. toolId=toolId,
  409. label=label,
  410. bitmap=bitmap,
  411. bmpDisabled=bmpDisabled,
  412. kind=kind,
  413. shortHelp=shortHelpString,
  414. longHelp=longHelpString,
  415. clientData=clientData,
  416. )
  417. else:
  418. return wx.ToolBar.AddLabelTool(
  419. self,
  420. toolId,
  421. label,
  422. bitmap,
  423. bmpDisabled,
  424. kind,
  425. shortHelpString,
  426. longHelpString,
  427. clientData,
  428. )
  429. def InsertLabelTool(
  430. self,
  431. pos,
  432. toolId,
  433. label,
  434. bitmap,
  435. bmpDisabled=wx.NullBitmap,
  436. kind=0,
  437. shortHelpString="",
  438. longHelpString="",
  439. clientData=None,
  440. ):
  441. if wxPythonPhoenix:
  442. return wx.ToolBar.InsertTool(
  443. self,
  444. pos,
  445. toolId=toolId,
  446. label=label,
  447. bitmap=bitmap,
  448. bmpDisabled=bmpDisabled,
  449. kind=kind,
  450. shortHelp=shortHelpString,
  451. longHelp=longHelpString,
  452. clientData=clientData,
  453. )
  454. else:
  455. return wx.ToolBar.InsertLabelTool(
  456. self,
  457. pos,
  458. toolId,
  459. label,
  460. bitmap,
  461. bmpDisabled,
  462. kind,
  463. shortHelpString,
  464. longHelpString,
  465. clientData,
  466. )
  467. class Menu(wx.Menu):
  468. """Wrapper around wx.Menu to have more control
  469. over the widget on different platforms/wxpython versions"""
  470. def __init__(self, *args, **kwargs):
  471. wx.Menu.__init__(self, *args, **kwargs)
  472. def AppendItem(self, menuItem):
  473. if wxPythonPhoenix:
  474. wx.Menu.Append(self, menuItem=menuItem)
  475. else:
  476. wx.Menu.AppendItem(self, menuItem)
  477. def AppendMenu(self, id, text, submenu, help=""):
  478. if wxPythonPhoenix:
  479. wx.Menu.Append(self, id=id, item=text, subMenu=submenu, helpString=help)
  480. else:
  481. wx.Menu.AppendMenu(self, id=id, text=text, submenu=submenu, help=help)
  482. class DragImage(wx.GenericDragImage if wxPythonPhoenix else wx.DragImage):
  483. """Wrapper around wx.DragImage to have more control
  484. over the widget on different platforms/wxpython versions"""
  485. def __init__(self, *args, **kwargs):
  486. super(DragImage, self).__init__(*args, **kwargs)
  487. class PseudoDC(wx.adv.PseudoDC if wxPythonPhoenix else wx.PseudoDC):
  488. """Wrapper around wx.PseudoDC to have more control
  489. over the widget on different platforms/wxpython versions"""
  490. def __init__(self, *args, **kwargs):
  491. super(PseudoDC, self).__init__(*args, **kwargs)
  492. def DrawLinePoint(self, *args, **kwargs):
  493. args = convertToInt(argsOrKwargs=args, roundVal=True)
  494. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  495. if wxPythonPhoenix:
  496. super(PseudoDC, self).DrawLine(*args, **kwargs)
  497. else:
  498. super(PseudoDC, self).DrawLinePoint(*args, **kwargs)
  499. def DrawRectangleRect(self, rect):
  500. if wxPythonPhoenix:
  501. super(PseudoDC, self).DrawRectangle(rect=rect)
  502. else:
  503. super(PseudoDC, self).DrawRectangleRect(rect)
  504. def BeginDrawing(self):
  505. if not wxPythonPhoenix:
  506. super(PseudoDC, self).BeginDrawing()
  507. def EndDrawing(self):
  508. if not wxPythonPhoenix:
  509. super(PseudoDC, self).EndDrawing()
  510. def DrawRectangle(self, *args, **kwargs):
  511. args = convertToInt(argsOrKwargs=args, roundVal=True)
  512. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  513. super(PseudoDC, self).DrawRectangle(*args, **kwargs)
  514. def DrawBitmap(self, *args, **kwargs):
  515. args = convertToInt(argsOrKwargs=args, roundVal=True)
  516. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  517. super(PseudoDC, self).DrawBitmap(*args, **kwargs)
  518. def DrawCircle(self, *args, **kwargs):
  519. args = convertToInt(argsOrKwargs=args, roundVal=True)
  520. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  521. super(PseudoDC, self).DrawCircle(*args, **kwargs)
  522. class ClientDC(wx.ClientDC):
  523. """Wrapper around wx.ClientDC to have more control
  524. over the widget on different platforms/wxpython versions"""
  525. def __init__(self, *args, **kwargs):
  526. super(ClientDC, self).__init__(*args, **kwargs)
  527. def GetFullMultiLineTextExtent(self, string, font=None):
  528. if wxPythonPhoenix:
  529. return super(ClientDC, self).GetFullMultiLineTextExtent(string, font)
  530. else:
  531. return super(ClientDC, self).GetMultiLineTextExtent(string, font)
  532. class Rect(wx.Rect):
  533. """Wrapper around wx.Rect to have more control
  534. over the widget on different platforms/wxpython versions"""
  535. def __init__(self, *args, **kwargs):
  536. args = convertToInt(argsOrKwargs=args)
  537. kwargs = convertToInt(argsOrKwargs=kwargs)
  538. wx.Rect.__init__(self, *args, **kwargs)
  539. def ContainsXY(self, x, y):
  540. if wxPythonPhoenix:
  541. return wx.Rect.Contains(self, x=int(x), y=int(y))
  542. else:
  543. return wx.Rect.ContainsXY(self, int(x), int(y))
  544. def ContainsRect(self, rect):
  545. if wxPythonPhoenix:
  546. return wx.Rect.Contains(self, rect=rect)
  547. else:
  548. return wx.Rect.ContainsRect(self, rect)
  549. def OffsetXY(self, dx, dy):
  550. if wxPythonPhoenix:
  551. return wx.Rect.Offset(self, int(dx), int(dy))
  552. else:
  553. return wx.Rect.OffsetXY(self, int(dx), int(dy))
  554. class CheckBox(wx.CheckBox):
  555. """Wrapper around wx.CheckBox to have more control
  556. over the widget on different platforms/wxpython versions"""
  557. def __init__(self, *args, **kwargs):
  558. wx.CheckBox.__init__(self, *args, **kwargs)
  559. def SetToolTip(self, tip):
  560. if wxPythonPhoenix:
  561. wx.CheckBox.SetToolTip(self, tipString=tip)
  562. else:
  563. wx.CheckBox.SetToolTipString(self, tip)
  564. class Choice(wx.Choice):
  565. """Wrapper around wx.Choice to have more control
  566. over the widget on different platforms/wxpython versions"""
  567. def __init__(self, *args, **kwargs):
  568. wx.Choice.__init__(self, *args, **kwargs)
  569. def SetToolTip(self, tip):
  570. if wxPythonPhoenix:
  571. wx.Choice.SetToolTip(self, tipString=tip)
  572. else:
  573. wx.Choice.SetToolTipString(self, tip)
  574. class TextEntryDialog(wx.TextEntryDialog):
  575. """Wrapper around wx.TextEntryDialog to have more control
  576. over the widget on different platforms/wxpython versions"""
  577. def __init__(
  578. self,
  579. parent,
  580. message,
  581. caption="Please enter text",
  582. value="",
  583. style=wx.OK | wx.CANCEL | wx.CENTRE,
  584. pos=wx.DefaultPosition,
  585. ):
  586. if wxPythonPhoenix:
  587. super(TextEntryDialog, self).__init__(
  588. parent=parent,
  589. message=message,
  590. caption=caption,
  591. value=value,
  592. style=style,
  593. pos=pos,
  594. )
  595. else:
  596. super(TextEntryDialog, self).__init__(
  597. parent=parent,
  598. message=message,
  599. caption=caption,
  600. defaultValue=value,
  601. style=style,
  602. pos=pos,
  603. )
  604. class ColourSelect(csel.ColourSelect):
  605. """Wrapper around wx.lib.colourselect.ColourSelect to have more control
  606. over the widget on different platforms/wxpython versions"""
  607. def __init__(self, *args, **kwargs):
  608. csel.ColourSelect.__init__(self, *args, **kwargs)
  609. def SetToolTip(self, tip):
  610. if wxPythonPhoenix:
  611. csel.ColourSelect.SetToolTip(self, tipString=tip)
  612. else:
  613. csel.ColourSelect.SetToolTipString(self, tip)
  614. class ComboCtrl(wxComboCtrl):
  615. def __init__(self, *args, **kwargs):
  616. wxComboCtrl.__init__(self, *args, **kwargs)
  617. def SetToolTip(self, tip):
  618. if wxPythonPhoenix:
  619. wxComboCtrl.SetToolTip(self, tipString=tip)
  620. else:
  621. wxComboCtrl.SetToolTipString(self, tip)
  622. class Dialog(wx.Dialog):
  623. """Wrapper around wx.Dialog to have more control
  624. over the widget on different platforms/wxpython versions"""
  625. def __init__(self, *args, **kwargs):
  626. wx.Dialog.__init__(self, *args, **kwargs)
  627. class Notebook(wx.Notebook):
  628. """Wrapper around NoteBook to have more control
  629. over the widget on different platforms/wxpython versions"""
  630. def __init__(self, *args, **kwargs):
  631. wx.Notebook.__init__(self, *args, **kwargs)
  632. class OwnerDrawnComboBox(OwnerDrawnComboBox_):
  633. """Wrapper around OwnerDrawnComboBox to have more control
  634. over the widget on different platforms/wxpython versions"""
  635. ODCB_PAINTING_CONTROL = ODCB_PAINTING_CONTROL
  636. ODCB_PAINTING_SELECTED = ODCB_PAINTING_SELECTED
  637. def __init__(self, *args, **kwargs):
  638. OwnerDrawnComboBox_.__init__(self, *args, **kwargs)
  639. def SetToolTip(self, tip):
  640. if wxPythonPhoenix:
  641. OwnerDrawnComboBox_.SetToolTip(self, tipString=tip)
  642. else:
  643. OwnerDrawnComboBox_.SetToolTipString(self, tip)
  644. class BitmapComboBox(BitmapComboBox_):
  645. """Wrapper around BitmapComboBox to have more control
  646. over the widget on different platforms/wxpython versions"""
  647. def __init__(self, *args, **kwargs):
  648. BitmapComboBox_.__init__(self, *args, **kwargs)
  649. def SetToolTip(self, tip):
  650. if wxPythonPhoenix:
  651. BitmapComboBox_.SetToolTip(self, tipString=tip)
  652. else:
  653. BitmapComboBox_.SetToolTipString(self, tip)
  654. class ScrolledPanel(scrolled.ScrolledPanel):
  655. """Wrapper around scrolled.ScrolledPanel to have more control
  656. over the widget on different platforms/wxpython versions"""
  657. def __init__(self, *args, **kwargs):
  658. scrolled.ScrolledPanel.__init__(self, *args, **kwargs)
  659. def SetToolTip(self, tip):
  660. if wxPythonPhoenix:
  661. scrolled.ScrolledPanel.SetToolTip(self, tipString=tip)
  662. else:
  663. scrolled.ScrolledPanel.SetToolTipString(self, tip)
  664. class FileBrowseButton(filebrowse.FileBrowseButton):
  665. """Wrapper around filebrowse.FileBrowseButton to have more control
  666. over the widget on different platforms/wxpython versions"""
  667. def __init__(self, *args, **kwargs):
  668. filebrowse.FileBrowseButton.__init__(self, *args, **kwargs)
  669. class DirBrowseButton(filebrowse.DirBrowseButton):
  670. """Wrapper around filebrowse.DirBrowseButton to have more control
  671. over the widget on different platforms/wxpython versions"""
  672. def __init__(self, *args, **kwargs):
  673. filebrowse.DirBrowseButton.__init__(self, *args, **kwargs)
  674. class ExpandoTextCtrl(expando.ExpandoTextCtrl):
  675. """Wrapper around expando.ExpandoTextCtrl to have more control
  676. over the widget on different platforms/wxpython versions"""
  677. EVT_ETC_LAYOUT_NEEDED = expando.EVT_ETC_LAYOUT_NEEDED
  678. def __init__(self, *args, **kwargs):
  679. expando.ExpandoTextCtrl.__init__(self, *args, **kwargs)
  680. class ColourPickerCtrl(wx.ColourPickerCtrl):
  681. """Wrapper around wx.ColourPickerCtrl to have more control
  682. over the widget on different platforms/wxpython versions"""
  683. def __init__(self, *args, **kwargs):
  684. wx.ColourPickerCtrl.__init__(self, *args, **kwargs)
  685. class ListBox(wx.ListBox):
  686. """Wrapper around wx.ListBox to have more control
  687. over the widget on different platforms/wxpython versions"""
  688. def __init__(self, *args, **kwargs):
  689. wx.ListBox.__init__(self, *args, **kwargs)
  690. def SetToolTip(self, tip):
  691. if wxPythonPhoenix:
  692. wx.ListBox.SetToolTip(self, tipString=tip)
  693. else:
  694. wx.ListBox.SetToolTipString(self, tip)
  695. class HyperlinkCtrl(HyperlinkCtrl_):
  696. """Wrapper around HyperlinkCtrl to have more control
  697. over the widget on different platforms/wxpython versions"""
  698. HL_ALIGN_LEFT = HL_ALIGN_LEFT
  699. HL_CONTEXTMENU = HL_CONTEXTMENU
  700. def __init__(self, *args, **kwargs):
  701. HyperlinkCtrl_.__init__(self, *args, **kwargs)
  702. def SetToolTip(self, tip):
  703. if wxPythonPhoenix:
  704. HyperlinkCtrl_.SetToolTip(self, tipString=tip)
  705. else:
  706. HyperlinkCtrl_.SetToolTipString(self, tip)
  707. class ComboBox(wx.ComboBox):
  708. """Wrapper around wx.ComboBox to have more control
  709. over the widget on different platforms/wxpython versions"""
  710. def __init__(self, *args, **kwargs):
  711. wx.ComboBox.__init__(self, *args, **kwargs)
  712. def SetToolTip(self, tip):
  713. if wxPythonPhoenix:
  714. wx.ComboBox.SetToolTip(self, tipString=tip)
  715. else:
  716. wx.ComboBox.SetToolTipString(self, tip)