wrap.py 27 KB

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