wrap.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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 BitmapFromImage(image, depth=-1):
  64. if wxPythonPhoenix:
  65. return wx.Bitmap(img=image, depth=depth)
  66. else:
  67. return wx.BitmapFromImage(image, depth=depth)
  68. def ImageFromBitmap(bitmap):
  69. if wxPythonPhoenix:
  70. return bitmap.ConvertToImage()
  71. else:
  72. return wx.ImageFromBitmap(bitmap)
  73. def EmptyBitmap(width, height, depth=-1):
  74. if wxPythonPhoenix:
  75. return wx.Bitmap(width=width, height=height, depth=depth)
  76. else:
  77. return wx.EmptyBitmap(width=width, height=height, depth=depth)
  78. def EmptyImage(width, height, clear=True):
  79. if wxPythonPhoenix:
  80. return wx.Image(width=width, height=height, clear=clear)
  81. else:
  82. return wx.EmptyImage(width=width, height=height, clear=clear)
  83. def StockCursor(cursorId):
  84. if wxPythonPhoenix:
  85. return wx.Cursor(cursorId=cursorId)
  86. else:
  87. return wx.StockCursor(cursorId)
  88. class Window(wx.Window):
  89. """Wrapper around wx.Window to have more control
  90. over the widget on different platforms/wxpython versions"""
  91. def __init__(self, *args, **kwargs):
  92. wx.Window.__init__(self, *args, **kwargs)
  93. def SetToolTip(self, tip):
  94. if wxPythonPhoenix:
  95. if tip is None:
  96. wx.Window.UnsetToolTip(self)
  97. else:
  98. wx.Window.SetToolTip(self, tipString=tip)
  99. else:
  100. if tip is None:
  101. wx.Window.SetToolTip(self, tip)
  102. else:
  103. wx.Window.SetToolTipString(self, tip)
  104. class Panel(wx.Panel):
  105. """Wrapper around wx.Panel to have more control
  106. over the widget on different platforms/wxpython versions"""
  107. def __init__(self, *args, **kwargs):
  108. wx.Panel.__init__(self, *args, **kwargs)
  109. def SetToolTip(self, tip):
  110. if wxPythonPhoenix:
  111. wx.Panel.SetToolTip(self, tipString=tip)
  112. else:
  113. wx.Panel.SetToolTipString(self, tip)
  114. class Slider(wx.Slider):
  115. """Wrapper around wx.Slider to have more control
  116. over the widget on different platforms/wxpython versions"""
  117. def __init__(self, *args, **kwargs):
  118. args = convertToInt(argsOrKwargs=args)
  119. kwargs = convertToInt(argsOrKwargs=kwargs)
  120. wx.Slider.__init__(self, *args, **kwargs)
  121. def SetRange(self, minValue, maxValue):
  122. wx.Slider.SetRange(self, int(minValue), int(maxValue))
  123. def SetValue(self, value):
  124. wx.Slider.SetValue(self, int(value))
  125. class SpinCtrl(wx.SpinCtrl):
  126. """Wrapper around wx.SpinCtrl to have more control
  127. over the widget on different platforms"""
  128. gtk3MinSize = 130
  129. def __init__(self, *args, **kwargs):
  130. args = convertToInt(argsOrKwargs=args)
  131. kwargs = convertToInt(argsOrKwargs=kwargs)
  132. if gtk3:
  133. if 'size' in kwargs:
  134. kwargs['size'] = wx.Size(max(self.gtk3MinSize, kwargs['size'][0]), kwargs['size'][1])
  135. else:
  136. kwargs['size'] = wx.Size(self.gtk3MinSize, -1)
  137. wx.SpinCtrl.__init__(self, *args, **kwargs)
  138. def SetToolTip(self, tip):
  139. if wxPythonPhoenix:
  140. wx.SpinCtrl.SetToolTip(self, tipString=tip)
  141. else:
  142. wx.SpinCtrl.SetToolTipString(self, tip)
  143. class FloatSpin(fs.FloatSpin):
  144. """Wrapper around fs.FloatSpin to have more control
  145. over the widget on different platforms"""
  146. gtk3MinSize = 130
  147. def __init__(self, *args, **kwargs):
  148. if gtk3:
  149. if 'size' in kwargs:
  150. kwargs['size'] = wx.Size(max(self.gtk3MinSize, kwargs['size'][0]), kwargs['size'][1])
  151. else:
  152. kwargs['size'] = wx.Size(self.gtk3MinSize, -1)
  153. fs.FloatSpin.__init__(self, *args, **kwargs)
  154. def SetToolTip(self, tip):
  155. if wxPythonPhoenix:
  156. fs.FloatSpin.SetToolTip(self, tipString=tip)
  157. else:
  158. fs.FloatSpin.SetToolTipString(self, tip)
  159. class Button(wx.Button):
  160. """Wrapper around wx.Button to have more control
  161. over the widget on different platforms/wxpython versions"""
  162. def __init__(self, *args, **kwargs):
  163. wx.Button.__init__(self, *args, **kwargs)
  164. def SetToolTip(self, tip):
  165. if wxPythonPhoenix:
  166. wx.Button.SetToolTip(self, tipString=tip)
  167. else:
  168. wx.Button.SetToolTipString(self, tip)
  169. class ClearButton(Button):
  170. """Wrapper around a Button with stock id wx.ID_CLEAR,
  171. to disable default key binding on certain platforms"""
  172. def __init__(self, *args, **kwargs):
  173. Button.__init__(self, *args, **kwargs)
  174. self.SetId(wx.ID_CLEAR)
  175. if sys.platform == "darwin":
  176. self.SetLabel(_("Clear"))
  177. else:
  178. self.SetLabel(_("&Clear"))
  179. class CancelButton(Button):
  180. """Wrapper around a Button with stock id wx.ID_CANCEL, to disable
  181. default key binding on certain platforms/wxpython versions"""
  182. def __init__(self, *args, **kwargs):
  183. Button.__init__(self, *args, **kwargs)
  184. self.SetId(wx.ID_CANCEL)
  185. if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
  186. self.SetLabel(_("Cancel"))
  187. else:
  188. self.SetLabel(_("&Cancel"))
  189. class CloseButton(Button):
  190. """Wrapper around a Close labeled Button with stock id wx.ID_CANCEL
  191. to disable default key binding on certain platforms/wxpython versions"""
  192. def __init__(self, *args, **kwargs):
  193. Button.__init__(self, *args, **kwargs)
  194. self.SetId(wx.ID_CANCEL)
  195. if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
  196. self.SetLabel(_("Close"))
  197. else:
  198. self.SetLabel(_("&Close"))
  199. class ApplyButton(Button):
  200. """Wrapper around a Button with stock id wx.ID_APPLY,
  201. to disable default key binding on certain platforms"""
  202. def __init__(self, *args, **kwargs):
  203. Button.__init__(self, *args, **kwargs)
  204. self.SetId(wx.ID_APPLY)
  205. if sys.platform == "darwin":
  206. self.SetLabel(_("Apply"))
  207. else:
  208. self.SetLabel(_("&Apply"))
  209. class RadioButton(wx.RadioButton):
  210. """Wrapper around wx.RadioButton to have more control
  211. over the widget on different platforms/wxpython versions"""
  212. def __init__(self, *args, **kwargs):
  213. wx.RadioButton.__init__(self, *args, **kwargs)
  214. def SetToolTip(self, tip):
  215. if wxPythonPhoenix:
  216. wx.RadioButton.SetToolTip(self, tipString=tip)
  217. else:
  218. wx.RadioButton.SetToolTipString(self, tip)
  219. class BitmapButton(wx.BitmapButton):
  220. """Wrapper around wx.BitmapButton to have more control
  221. over the widget on different platforms/wxpython versions"""
  222. def __init__(self, *args, **kwargs):
  223. wx.BitmapButton.__init__(self, *args, **kwargs)
  224. def SetToolTip(self, tip):
  225. if wxPythonPhoenix:
  226. wx.BitmapButton.SetToolTip(self, tipString=tip)
  227. else:
  228. wx.BitmapButton.SetToolTipString(self, tip)
  229. class GenBitmapButton(buttons.GenBitmapButton):
  230. """Wrapper around GenBitmapButton to have more control
  231. over the widget on different platforms/wxpython versions"""
  232. def __init__(self, *args, **kwargs):
  233. buttons.GenBitmapButton.__init__(self, *args, **kwargs)
  234. def SetToolTip(self, tip):
  235. if wxPythonPhoenix:
  236. buttons.GenBitmapButton.SetToolTip(self, tipString=tip)
  237. else:
  238. buttons.GenBitmapButton.SetToolTipString(self, tip)
  239. class ToggleButton(wx.ToggleButton):
  240. """Wrapper around wx.ToggleButton to have more control
  241. over the widget on different platforms/wxpython versions"""
  242. def __init__(self, *args, **kwargs):
  243. wx.ToggleButton.__init__(self, *args, **kwargs)
  244. def SetToolTip(self, tip):
  245. if wxPythonPhoenix:
  246. wx.ToggleButton.SetToolTip(self, tipString=tip)
  247. else:
  248. wx.ToggleButton.SetToolTipString(self, tip)
  249. class StaticText(wx.StaticText):
  250. """Wrapper around wx.StaticText to have more control
  251. over the widget on different platforms/wxpython versions"""
  252. def __init__(self, *args, **kwargs):
  253. wx.StaticText.__init__(self, *args, **kwargs)
  254. def SetToolTip(self, tip):
  255. if wxPythonPhoenix:
  256. wx.StaticText.SetToolTip(self, tip)
  257. else:
  258. wx.StaticText.SetToolTipString(self, tip)
  259. class StaticBox(wx.StaticBox):
  260. """Wrapper around wx.StaticBox to have more control
  261. over the widget on different platforms/wxpython versions"""
  262. def __init__(self, *args, **kwargs):
  263. wx.StaticBox.__init__(self, *args, **kwargs)
  264. def SetToolTip(self, tip):
  265. if wxPythonPhoenix:
  266. wx.StaticBox.SetToolTip(self, tipString=tip)
  267. else:
  268. wx.StaticBox.SetToolTipString(self, tip)
  269. class CheckListBox(wx.CheckListBox):
  270. """Wrapper around wx.CheckListBox to have more control
  271. over the widget on different platforms/wxpython versions"""
  272. def __init__(self, *args, **kwargs):
  273. wx.CheckListBox.__init__(self, *args, **kwargs)
  274. def SetToolTip(self, tip):
  275. if wxPythonPhoenix:
  276. wx.CheckListBox.SetToolTip(self, tipString=tip)
  277. else:
  278. wx.CheckListBox.SetToolTipString(self, tip)
  279. class TextCtrl(wx.TextCtrl):
  280. """Wrapper around wx.TextCtrl to have more control
  281. over the widget on different platforms/wxpython versions"""
  282. def __init__(self, *args, **kwargs):
  283. wx.TextCtrl.__init__(self, *args, **kwargs)
  284. def SetToolTip(self, tip):
  285. if wxPythonPhoenix:
  286. wx.TextCtrl.SetToolTip(self, tipString=tip)
  287. else:
  288. wx.TextCtrl.SetToolTipString(self, tip)
  289. class SearchCtrl(wx.SearchCtrl):
  290. """Wrapper around wx.SearchCtrl to have more control
  291. over the widget on different platforms/wxpython versions"""
  292. def __init__(self, *args, **kwargs):
  293. wx.SearchCtrl.__init__(self, *args, **kwargs)
  294. def SetToolTip(self, tip):
  295. if wxPythonPhoenix:
  296. wx.SearchCtrl.SetToolTip(self, tipString=tip)
  297. else:
  298. wx.SearchCtrl.SetToolTipString(self, tip)
  299. class ListCtrl(wx.ListCtrl):
  300. """Wrapper around wx.ListCtrl to have more control
  301. over the widget on different platforms/wxpython versions"""
  302. def __init__(self, *args, **kwargs):
  303. wx.ListCtrl.__init__(self, *args, **kwargs)
  304. def InsertItem(self, index, label, imageIndex=-1):
  305. if wxPythonPhoenix:
  306. return wx.ListCtrl.InsertItem(self, index=index, label=label, imageIndex=imageIndex)
  307. else:
  308. return wx.ListCtrl.InsertStringItem(self, index=index, label=label, imageIndex=imageIndex)
  309. def SetItem(self, index, column, label, imageId=-1):
  310. if wxPythonPhoenix:
  311. return wx.ListCtrl.SetItem(self, index=index, column=column, label=label, imageId=imageId)
  312. else:
  313. return wx.ListCtrl.SetStringItem(self, index=index, col=column, label=label, imageId=imageId)
  314. def CheckItem(self, item, check=True):
  315. """Uses either deprecated listmix.CheckListCtrlMixin
  316. or new checkbox implementation in wx.ListCtrl since 4.1.0"""
  317. if hasattr(self, 'HasCheckBoxes'):
  318. wx.ListCtrl.CheckItem(self, item, check)
  319. else:
  320. super(ListCtrl, self).CheckItem(item, check)
  321. def IsItemChecked(self, item):
  322. if hasattr(self, 'HasCheckBoxes'):
  323. return wx.ListCtrl.IsItemChecked(self, item)
  324. else:
  325. return super(ListCtrl, self).IsChecked(item)
  326. if CheckWxVersion([4, 1, 0]):
  327. class CheckListCtrlMixin():
  328. """This class pretends to be deprecated CheckListCtrlMixin mixin and
  329. only enables checkboxes in new versions of ListCtrl"""
  330. def __init__(self):
  331. self.EnableCheckBoxes(True)
  332. self.AssignImageList(wx.ImageList(16, 16), wx.IMAGE_LIST_SMALL)
  333. else:
  334. import wx.lib.mixins.listctrl as listmix
  335. class CheckListCtrlMixin(listmix.CheckListCtrlMixin):
  336. """Wrapper for deprecated mixin"""
  337. def __init__(self):
  338. listmix.CheckListCtrlMixin.__init__(self)
  339. class TreeCtrl(wx.TreeCtrl):
  340. """Wrapper around wx.TreeCtrl to have more control
  341. over the widget on different platforms/wxpython versions"""
  342. def __init__(self, *args, **kwargs):
  343. wx.TreeCtrl.__init__(self, *args, **kwargs)
  344. def AppendItem(self, parent, text, image=-1, selImage=-1, data=None):
  345. if wxPythonPhoenix:
  346. return wx.TreeCtrl.AppendItem(self, parent, text, image, selImage, data)
  347. else:
  348. return wx.TreeCtrl.AppendItem(self, parent, text, image, selImage, wx.TreeItemData(data))
  349. def GetItemData(self, item):
  350. if wxPythonPhoenix:
  351. return wx.TreeCtrl.GetItemData(self, item)
  352. else:
  353. return wx.TreeCtrl.GetPyData(self, item)
  354. class CustomTreeCtrl(CT.CustomTreeCtrl):
  355. """Wrapper around wx.lib.agw.customtreectrl to have more control
  356. over the widget on different platforms/wxpython versions"""
  357. def __init__(self, *args, **kwargs):
  358. CT.CustomTreeCtrl.__init__(self, *args, **kwargs)
  359. def SetToolTip(self, tip):
  360. if wxPythonPhoenix:
  361. CT.CustomTreeCtrl.SetToolTip(self, tipString=tip)
  362. else:
  363. CT.CustomTreeCtrl.SetToolTipString(self, tip)
  364. class ToolBar(wx.ToolBar):
  365. """Wrapper around wx.ToolBar to have more control
  366. over the widget on different platforms/wxpython versions"""
  367. def __init__(self, *args, **kwargs):
  368. wx.ToolBar.__init__(self, *args, **kwargs)
  369. def AddLabelTool(self, toolId, label, bitmap, bmpDisabled=wx.NullBitmap, kind=0,
  370. shortHelpString='', longHelpString='', clientData=None):
  371. if wxPythonPhoenix:
  372. return wx.ToolBar.AddTool(self, toolId=toolId, label=label, bitmap=bitmap, bmpDisabled=bmpDisabled,
  373. kind=kind, shortHelp=shortHelpString, longHelp=longHelpString,
  374. clientData=clientData)
  375. else:
  376. return wx.ToolBar.AddLabelTool(self, toolId, label, bitmap, bmpDisabled, kind,
  377. shortHelpString, longHelpString, clientData)
  378. def InsertLabelTool(self, pos, toolId, label, bitmap, bmpDisabled=wx.NullBitmap, kind=0,
  379. shortHelpString='', longHelpString='', clientData=None):
  380. if wxPythonPhoenix:
  381. return wx.ToolBar.InsertTool(self, pos, toolId=toolId, label=label, bitmap=bitmap, bmpDisabled=bmpDisabled,
  382. kind=kind, shortHelp=shortHelpString, longHelp=longHelpString,
  383. clientData=clientData)
  384. else:
  385. return wx.ToolBar.InsertLabelTool(self, pos, toolId, label, bitmap, bmpDisabled, kind,
  386. shortHelpString, longHelpString, clientData)
  387. class Menu(wx.Menu):
  388. """Wrapper around wx.Menu to have more control
  389. over the widget on different platforms/wxpython versions"""
  390. def __init__(self, *args, **kwargs):
  391. wx.Menu.__init__(self, *args, **kwargs)
  392. def AppendItem(self, menuItem):
  393. if wxPythonPhoenix:
  394. wx.Menu.Append(self, menuItem=menuItem)
  395. else:
  396. wx.Menu.AppendItem(self, menuItem)
  397. def AppendMenu(self, id, text, submenu, help=""):
  398. if wxPythonPhoenix:
  399. wx.Menu.Append(self, id=id, item=text, subMenu=submenu, helpString=help)
  400. else:
  401. wx.Menu.AppendMenu(self, id=id, text=text, submenu=submenu, help=help)
  402. class DragImage(wx.GenericDragImage if wxPythonPhoenix else wx.DragImage):
  403. """Wrapper around wx.DragImage to have more control
  404. over the widget on different platforms/wxpython versions"""
  405. def __init__(self, *args, **kwargs):
  406. super(DragImage, self).__init__(*args, **kwargs)
  407. class PseudoDC(wx.adv.PseudoDC if wxPythonPhoenix else wx.PseudoDC):
  408. """Wrapper around wx.PseudoDC to have more control
  409. over the widget on different platforms/wxpython versions"""
  410. def __init__(self, *args, **kwargs):
  411. super(PseudoDC, self).__init__(*args, **kwargs)
  412. def DrawLinePoint(self, *args, **kwargs):
  413. args = convertToInt(argsOrKwargs=args, roundVal=True)
  414. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  415. if wxPythonPhoenix:
  416. super(PseudoDC, self).DrawLine(*args, **kwargs)
  417. else:
  418. super(PseudoDC, self).DrawLinePoint(*args, **kwargs)
  419. def DrawRectangleRect(self, rect):
  420. if wxPythonPhoenix:
  421. super(PseudoDC, self).DrawRectangle(rect=rect)
  422. else:
  423. super(PseudoDC, self).DrawRectangleRect(rect)
  424. def BeginDrawing(self):
  425. if not wxPythonPhoenix:
  426. super(PseudoDC, self).BeginDrawing()
  427. def EndDrawing(self):
  428. if not wxPythonPhoenix:
  429. super(PseudoDC, self).EndDrawing()
  430. def DrawRectangle(self, *args, **kwargs):
  431. args = convertToInt(argsOrKwargs=args, roundVal=True)
  432. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  433. super(PseudoDC, self).DrawRectangle(*args, **kwargs)
  434. def DrawBitmap(self, *args, **kwargs):
  435. args = convertToInt(argsOrKwargs=args, roundVal=True)
  436. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  437. super(PseudoDC, self).DrawBitmap(*args, **kwargs)
  438. def DrawCircle(self, *args, **kwargs):
  439. args = convertToInt(argsOrKwargs=args, roundVal=True)
  440. kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
  441. super(PseudoDC, self).DrawCircle(*args, **kwargs)
  442. class ClientDC(wx.ClientDC):
  443. """Wrapper around wx.ClientDC to have more control
  444. over the widget on different platforms/wxpython versions"""
  445. def __init__(self, *args, **kwargs):
  446. super(ClientDC, self).__init__(*args, **kwargs)
  447. def GetFullMultiLineTextExtent(self, string, font=None):
  448. if wxPythonPhoenix:
  449. return super(ClientDC, self).GetFullMultiLineTextExtent(string, font)
  450. else:
  451. return super(ClientDC, self).GetMultiLineTextExtent(string, font)
  452. class Rect(wx.Rect):
  453. """Wrapper around wx.Rect to have more control
  454. over the widget on different platforms/wxpython versions"""
  455. def __init__(self, *args, **kwargs):
  456. args = convertToInt(argsOrKwargs=args)
  457. kwargs = convertToInt(argsOrKwargs=kwargs)
  458. wx.Rect.__init__(self, *args, **kwargs)
  459. def ContainsXY(self, x, y):
  460. if wxPythonPhoenix:
  461. return wx.Rect.Contains(self, x=int(x), y=int(y))
  462. else:
  463. return wx.Rect.ContainsXY(self, int(x), int(y))
  464. def ContainsRect(self, rect):
  465. if wxPythonPhoenix:
  466. return wx.Rect.Contains(self, rect=rect)
  467. else:
  468. return wx.Rect.ContainsRect(self, rect)
  469. def OffsetXY(self, dx, dy):
  470. if wxPythonPhoenix:
  471. return wx.Rect.Offset(self, int(dx), int(dy))
  472. else:
  473. return wx.Rect.OffsetXY(self, int(dx), int(dy))
  474. class CheckBox(wx.CheckBox):
  475. """Wrapper around wx.CheckBox to have more control
  476. over the widget on different platforms/wxpython versions"""
  477. def __init__(self, *args, **kwargs):
  478. wx.CheckBox.__init__(self, *args, **kwargs)
  479. def SetToolTip(self, tip):
  480. if wxPythonPhoenix:
  481. wx.CheckBox.SetToolTip(self, tipString=tip)
  482. else:
  483. wx.CheckBox.SetToolTipString(self, tip)
  484. class Choice(wx.Choice):
  485. """Wrapper around wx.Choice to have more control
  486. over the widget on different platforms/wxpython versions"""
  487. def __init__(self, *args, **kwargs):
  488. wx.Choice.__init__(self, *args, **kwargs)
  489. def SetToolTip(self, tip):
  490. if wxPythonPhoenix:
  491. wx.Choice.SetToolTip(self, tipString=tip)
  492. else:
  493. wx.Choice.SetToolTipString(self, tip)
  494. class TextEntryDialog(wx.TextEntryDialog):
  495. """Wrapper around wx.TextEntryDialog to have more control
  496. over the widget on different platforms/wxpython versions"""
  497. def __init__(self, parent, message, caption="Please enter text", value="",
  498. style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition):
  499. if wxPythonPhoenix:
  500. super(TextEntryDialog, self).__init__(parent=parent, message=message, caption=caption,
  501. value=value, style=style, pos=pos)
  502. else:
  503. super(TextEntryDialog, self).__init__(parent=parent, message=message, caption=caption,
  504. defaultValue=value, style=style, pos=pos)
  505. class ColourSelect(csel.ColourSelect):
  506. """Wrapper around wx.lib.colourselect.ColourSelect to have more control
  507. over the widget on different platforms/wxpython versions"""
  508. def __init__(self, *args, **kwargs):
  509. csel.ColourSelect.__init__(self, *args, **kwargs)
  510. def SetToolTip(self, tip):
  511. if wxPythonPhoenix:
  512. csel.ColourSelect.SetToolTip(self, tipString=tip)
  513. else:
  514. csel.ColourSelect.SetToolTipString(self, tip)
  515. class ComboCtrl(wxComboCtrl):
  516. def __init__(self, *args, **kwargs):
  517. wxComboCtrl.__init__(self, *args, **kwargs)
  518. def SetToolTip(self, tip):
  519. if wxPythonPhoenix:
  520. wxComboCtrl.SetToolTip(self, tipString=tip)
  521. else:
  522. wxComboCtrl.SetToolTipString(self, tip)
  523. class Dialog(wx.Dialog):
  524. """Wrapper around wx.Dialog to have more control
  525. over the widget on different platforms/wxpython versions"""
  526. def __init__(self, *args, **kwargs):
  527. wx.Dialog.__init__(self, *args, **kwargs)
  528. class Notebook(wx.Notebook):
  529. """Wrapper around NoteBook to have more control
  530. over the widget on different platforms/wxpython versions"""
  531. def __init__(self, *args, **kwargs):
  532. wx.Notebook.__init__(self, *args, **kwargs)
  533. class OwnerDrawnComboBox(OwnerDrawnComboBox_):
  534. """Wrapper around OwnerDrawnComboBox to have more control
  535. over the widget on different platforms/wxpython versions"""
  536. ODCB_PAINTING_CONTROL = ODCB_PAINTING_CONTROL
  537. ODCB_PAINTING_SELECTED = ODCB_PAINTING_SELECTED
  538. def __init__(self, *args, **kwargs):
  539. OwnerDrawnComboBox_.__init__(self, *args, **kwargs)
  540. def SetToolTip(self, tip):
  541. if wxPythonPhoenix:
  542. OwnerDrawnComboBox_.SetToolTip(self, tipString=tip)
  543. else:
  544. OwnerDrawnComboBox_.SetToolTipString(self, tip)
  545. class BitmapComboBox(BitmapComboBox_):
  546. """Wrapper around BitmapComboBox to have more control
  547. over the widget on different platforms/wxpython versions"""
  548. def __init__(self, *args, **kwargs):
  549. BitmapComboBox_.__init__(self, *args, **kwargs)
  550. def SetToolTip(self, tip):
  551. if wxPythonPhoenix:
  552. BitmapComboBox_.SetToolTip(self, tipString=tip)
  553. else:
  554. BitmapComboBox_.SetToolTipString(self, tip)
  555. class ScrolledPanel(scrolled.ScrolledPanel):
  556. """Wrapper around scrolled.ScrolledPanel to have more control
  557. over the widget on different platforms/wxpython versions"""
  558. def __init__(self, *args, **kwargs):
  559. scrolled.ScrolledPanel.__init__(self, *args, **kwargs)
  560. def SetToolTip(self, tip):
  561. if wxPythonPhoenix:
  562. scrolled.ScrolledPanel.SetToolTip(self, tipString=tip)
  563. else:
  564. scrolled.ScrolledPanel.SetToolTipString(self, tip)
  565. class FileBrowseButton(filebrowse.FileBrowseButton):
  566. """Wrapper around filebrowse.FileBrowseButton to have more control
  567. over the widget on different platforms/wxpython versions"""
  568. def __init__(self, *args, **kwargs):
  569. filebrowse.FileBrowseButton.__init__(self, *args, **kwargs)
  570. class DirBrowseButton(filebrowse.DirBrowseButton):
  571. """Wrapper around filebrowse.DirBrowseButton to have more control
  572. over the widget on different platforms/wxpython versions"""
  573. def __init__(self, *args, **kwargs):
  574. filebrowse.DirBrowseButton.__init__(self, *args, **kwargs)
  575. class ExpandoTextCtrl(expando.ExpandoTextCtrl):
  576. """Wrapper around expando.ExpandoTextCtrl to have more control
  577. over the widget on different platforms/wxpython versions"""
  578. EVT_ETC_LAYOUT_NEEDED = expando.EVT_ETC_LAYOUT_NEEDED
  579. def __init__(self, *args, **kwargs):
  580. expando.ExpandoTextCtrl.__init__(self, *args, **kwargs)
  581. class ColourPickerCtrl(wx.ColourPickerCtrl):
  582. """Wrapper around wx.ColourPickerCtrl to have more control
  583. over the widget on different platforms/wxpython versions"""
  584. def __init__(self, *args, **kwargs):
  585. wx.ColourPickerCtrl.__init__(self, *args, **kwargs)
  586. class ListBox(wx.ListBox):
  587. """Wrapper around wx.ListBox to have more control
  588. over the widget on different platforms/wxpython versions"""
  589. def __init__(self, *args, **kwargs):
  590. wx.ListBox.__init__(self, *args, **kwargs)
  591. def SetToolTip(self, tip):
  592. if wxPythonPhoenix:
  593. wx.ListBox.SetToolTip(self, tipString=tip)
  594. else:
  595. wx.ListBox.SetToolTipString(self, tip)
  596. class HyperlinkCtrl(HyperlinkCtrl_):
  597. """Wrapper around HyperlinkCtrl to have more control
  598. over the widget on different platforms/wxpython versions"""
  599. HL_ALIGN_LEFT = HL_ALIGN_LEFT
  600. HL_CONTEXTMENU = HL_CONTEXTMENU
  601. def __init__(self, *args, **kwargs):
  602. HyperlinkCtrl_.__init__(self, *args, **kwargs)
  603. def SetToolTip(self, tip):
  604. if wxPythonPhoenix:
  605. HyperlinkCtrl_.SetToolTip(self, tipString=tip)
  606. else:
  607. HyperlinkCtrl_.SetToolTipString(self, tip)
  608. class ComboBox(wx.ComboBox):
  609. """Wrapper around wx.ComboBox to have more control
  610. over the widget on different platforms/wxpython versions"""
  611. def __init__(self, *args, **kwargs):
  612. wx.ComboBox.__init__(self, *args, **kwargs)
  613. def SetToolTip(self, tip):
  614. if wxPythonPhoenix:
  615. wx.ComboBox.SetToolTip(self, tipString=tip)
  616. else:
  617. wx.ComboBox.SetToolTipString(self, tip)