wrap.py 30 KB

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