123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- """
- @package gui_core.wrap
- @brief Core wrapped wxpython widgets
- Classes:
- - wrap::GSpinCtrl
- (C) 2016 by the GRASS Development Team
- This program is free software under the GNU General Public License
- (>=v2). Read the file COPYING that comes with GRASS for details.
- @author Anna Petrasova <kratochanna gmail.com>
- """
- import sys
- import wx
- import wx.lib.agw.floatspin as fs
- import wx.lib.colourselect as csel
- import wx.lib.filebrowsebutton as filebrowse
- import wx.lib.scrolledpanel as scrolled
- from wx.lib import expando
- from wx.lib import buttons
- from wx.lib.agw.aui import tabart
- try:
- import wx.lib.agw.customtreectrl as CT
- except ImportError:
- import wx.lib.customtreectrl as CT
- from core.globalvar import CheckWxVersion, gtk3, wxPythonPhoenix
- if wxPythonPhoenix:
- import wx.adv
- from wx.adv import OwnerDrawnComboBox as OwnerDrawnComboBox_
- from wx.adv import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
- from wx.adv import BitmapComboBox as BitmapComboBox_
- from wx.adv import HyperlinkCtrl as HyperlinkCtrl_
- from wx.adv import HL_ALIGN_LEFT, HL_CONTEXTMENU
- ComboPopup = wx.ComboPopup
- wxComboCtrl = wx.ComboCtrl
- else:
- import wx.combo
- from wx.combo import OwnerDrawnComboBox as OwnerDrawnComboBox_
- from wx.combo import ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
- from wx.combo import BitmapComboBox as BitmapComboBox_
- from wx import HyperlinkCtrl as HyperlinkCtrl_
- from wx import HL_ALIGN_LEFT, HL_CONTEXTMENU
- ComboPopup = wx.combo.ComboPopup
- wxComboCtrl = wx.combo.ComboCtrl
- if wxPythonPhoenix and CheckWxVersion([4, 0, 3, 0]):
- from wx import NewIdRef as NewId
- else:
- from wx import NewId # noqa: F401
- def convertToInt(argsOrKwargs, roundVal=False):
- """Convert args, kwargs float value to int
- :param tuple/list/dict argsOrKwargs: args or kwargs
- :param bool roundVal: True if you want round float value
- return list or dict
- """
- result = {} if isinstance(argsOrKwargs, dict) else []
- j = None
- for i in argsOrKwargs:
- if isinstance(result, dict):
- i, j = argsOrKwargs[i], i
- if isinstance(i, float):
- if roundVal:
- i = round(i)
- i = int(i)
- result.update({j: i}) if j else result.append(i)
- return result
- def IsDark():
- """Detects if used theme is dark.
- Wraps wx method for different versions."""
- def luminance(c):
- return (0.299 * c.Red() + 0.587 * c.Green() + 0.114 * c.Blue()) / 255
- if hasattr(wx.SystemSettings, "GetAppearance"):
- return wx.SystemSettings.GetAppearance().IsDark()
- # for older wx
- bg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
- fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
- return luminance(fg) - luminance(bg) > 0.2
- def BitmapFromImage(image, depth=-1):
- if wxPythonPhoenix:
- return wx.Bitmap(img=image, depth=depth)
- else:
- return wx.BitmapFromImage(image, depth=depth)
- def ImageFromBitmap(bitmap):
- if wxPythonPhoenix:
- return bitmap.ConvertToImage()
- else:
- return wx.ImageFromBitmap(bitmap)
- def EmptyBitmap(width, height, depth=-1):
- if wxPythonPhoenix:
- return wx.Bitmap(width=width, height=height, depth=depth)
- else:
- return wx.EmptyBitmap(width=width, height=height, depth=depth)
- def EmptyImage(width, height, clear=True):
- if wxPythonPhoenix:
- return wx.Image(width=width, height=height, clear=clear)
- else:
- return wx.EmptyImage(width=width, height=height, clear=clear)
- def StockCursor(cursorId):
- if wxPythonPhoenix:
- return wx.Cursor(cursorId=cursorId)
- else:
- return wx.StockCursor(cursorId)
- class Window(wx.Window):
- """Wrapper around wx.Window to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Window.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- if tip is None:
- wx.Window.UnsetToolTip(self)
- else:
- wx.Window.SetToolTip(self, tipString=tip)
- else:
- if tip is None:
- wx.Window.SetToolTip(self, tip)
- else:
- wx.Window.SetToolTipString(self, tip)
- class Panel(wx.Panel):
- """Wrapper around wx.Panel to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Panel.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.Panel.SetToolTip(self, tipString=tip)
- else:
- wx.Panel.SetToolTipString(self, tip)
- class Slider(wx.Slider):
- """Wrapper around wx.Slider to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args)
- kwargs = convertToInt(argsOrKwargs=kwargs)
- wx.Slider.__init__(self, *args, **kwargs)
- def SetRange(self, minValue, maxValue):
- wx.Slider.SetRange(self, int(minValue), int(maxValue))
- def SetValue(self, value):
- wx.Slider.SetValue(self, int(value))
- class SpinCtrl(wx.SpinCtrl):
- """Wrapper around wx.SpinCtrl to have more control
- over the widget on different platforms"""
- gtk3MinSize = 130
- def __init__(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args)
- kwargs = convertToInt(argsOrKwargs=kwargs)
- if gtk3:
- if "size" in kwargs:
- kwargs["size"] = wx.Size(
- max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
- )
- else:
- kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
- wx.SpinCtrl.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.SpinCtrl.SetToolTip(self, tipString=tip)
- else:
- wx.SpinCtrl.SetToolTipString(self, tip)
- class FloatSpin(fs.FloatSpin):
- """Wrapper around fs.FloatSpin to have more control
- over the widget on different platforms"""
- gtk3MinSize = 130
- def __init__(self, *args, **kwargs):
- if gtk3:
- if "size" in kwargs:
- kwargs["size"] = wx.Size(
- max(self.gtk3MinSize, kwargs["size"][0]), kwargs["size"][1]
- )
- else:
- kwargs["size"] = wx.Size(self.gtk3MinSize, -1)
- fs.FloatSpin.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- fs.FloatSpin.SetToolTip(self, tipString=tip)
- else:
- fs.FloatSpin.SetToolTipString(self, tip)
- class Button(wx.Button):
- """Wrapper around wx.Button to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Button.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.Button.SetToolTip(self, tipString=tip)
- else:
- wx.Button.SetToolTipString(self, tip)
- class ClearButton(Button):
- """Wrapper around a Button with stock id wx.ID_CLEAR,
- to disable default key binding on certain platforms"""
- def __init__(self, *args, **kwargs):
- Button.__init__(self, *args, **kwargs)
- self.SetId(wx.ID_CLEAR)
- if sys.platform == "darwin":
- self.SetLabel(_("Clear"))
- else:
- self.SetLabel(_("&Clear"))
- class CancelButton(Button):
- """Wrapper around a Button with stock id wx.ID_CANCEL, to disable
- default key binding on certain platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- Button.__init__(self, *args, **kwargs)
- self.SetId(wx.ID_CANCEL)
- if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
- self.SetLabel(_("Cancel"))
- else:
- self.SetLabel(_("&Cancel"))
- class CloseButton(Button):
- """Wrapper around a Close labeled Button with stock id wx.ID_CANCEL
- to disable default key binding on certain platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- Button.__init__(self, *args, **kwargs)
- self.SetId(wx.ID_CANCEL)
- if sys.platform == "darwin" and not CheckWxVersion([4, 1, 0]):
- self.SetLabel(_("Close"))
- else:
- self.SetLabel(_("&Close"))
- class ApplyButton(Button):
- """Wrapper around a Button with stock id wx.ID_APPLY,
- to disable default key binding on certain platforms"""
- def __init__(self, *args, **kwargs):
- Button.__init__(self, *args, **kwargs)
- self.SetId(wx.ID_APPLY)
- if sys.platform == "darwin":
- self.SetLabel(_("Apply"))
- else:
- self.SetLabel(_("&Apply"))
- class RadioButton(wx.RadioButton):
- """Wrapper around wx.RadioButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.RadioButton.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.RadioButton.SetToolTip(self, tipString=tip)
- else:
- wx.RadioButton.SetToolTipString(self, tip)
- class BitmapButton(wx.BitmapButton):
- """Wrapper around wx.BitmapButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.BitmapButton.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.BitmapButton.SetToolTip(self, tipString=tip)
- else:
- wx.BitmapButton.SetToolTipString(self, tip)
- class GenBitmapButton(buttons.GenBitmapButton):
- """Wrapper around GenBitmapButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- buttons.GenBitmapButton.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- buttons.GenBitmapButton.SetToolTip(self, tipString=tip)
- else:
- buttons.GenBitmapButton.SetToolTipString(self, tip)
- class ToggleButton(wx.ToggleButton):
- """Wrapper around wx.ToggleButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ToggleButton.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.ToggleButton.SetToolTip(self, tipString=tip)
- else:
- wx.ToggleButton.SetToolTipString(self, tip)
- class StaticText(wx.StaticText):
- """Wrapper around wx.StaticText to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.StaticText.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.StaticText.SetToolTip(self, tip)
- else:
- wx.StaticText.SetToolTipString(self, tip)
- class StaticBox(wx.StaticBox):
- """Wrapper around wx.StaticBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.StaticBox.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.StaticBox.SetToolTip(self, tipString=tip)
- else:
- wx.StaticBox.SetToolTipString(self, tip)
- class CheckListBox(wx.CheckListBox):
- """Wrapper around wx.CheckListBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.CheckListBox.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.CheckListBox.SetToolTip(self, tipString=tip)
- else:
- wx.CheckListBox.SetToolTipString(self, tip)
- class TextCtrl(wx.TextCtrl):
- """Wrapper around wx.TextCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.TextCtrl.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.TextCtrl.SetToolTip(self, tipString=tip)
- else:
- wx.TextCtrl.SetToolTipString(self, tip)
- class SearchCtrl(wx.SearchCtrl):
- """Wrapper around wx.SearchCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.SearchCtrl.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.SearchCtrl.SetToolTip(self, tipString=tip)
- else:
- wx.SearchCtrl.SetToolTipString(self, tip)
- class ListCtrl(wx.ListCtrl):
- """Wrapper around wx.ListCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ListCtrl.__init__(self, *args, **kwargs)
- def InsertItem(self, index, label, imageIndex=-1):
- if wxPythonPhoenix:
- return wx.ListCtrl.InsertItem(
- self, index=index, label=label, imageIndex=imageIndex
- )
- else:
- return wx.ListCtrl.InsertStringItem(
- self, index=index, label=label, imageIndex=imageIndex
- )
- def SetItem(self, index, column, label, imageId=-1):
- if wxPythonPhoenix:
- return wx.ListCtrl.SetItem(
- self, index=index, column=column, label=label, imageId=imageId
- )
- else:
- return wx.ListCtrl.SetStringItem(
- self, index=index, col=column, label=label, imageId=imageId
- )
- def CheckItem(self, item, check=True):
- """Uses either deprecated listmix.CheckListCtrlMixin
- or new checkbox implementation in wx.ListCtrl since 4.1.0"""
- if hasattr(self, "HasCheckBoxes"):
- wx.ListCtrl.CheckItem(self, item, check)
- else:
- super(ListCtrl, self).CheckItem(item, check)
- def IsItemChecked(self, item):
- if hasattr(self, "HasCheckBoxes"):
- return wx.ListCtrl.IsItemChecked(self, item)
- else:
- return super(ListCtrl, self).IsChecked(item)
- if CheckWxVersion([4, 1, 0]):
- class CheckListCtrlMixin:
- """This class pretends to be deprecated CheckListCtrlMixin mixin and
- only enables checkboxes in new versions of ListCtrl"""
- def __init__(self):
- self.EnableCheckBoxes(True)
- self.AssignImageList(wx.ImageList(16, 16), wx.IMAGE_LIST_SMALL)
- else:
- import wx.lib.mixins.listctrl as listmix
- class CheckListCtrlMixin(listmix.CheckListCtrlMixin):
- """Wrapper for deprecated mixin"""
- def __init__(self):
- listmix.CheckListCtrlMixin.__init__(self)
- class TreeCtrl(wx.TreeCtrl):
- """Wrapper around wx.TreeCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.TreeCtrl.__init__(self, *args, **kwargs)
- def AppendItem(self, parent, text, image=-1, selImage=-1, data=None):
- if wxPythonPhoenix:
- return wx.TreeCtrl.AppendItem(self, parent, text, image, selImage, data)
- else:
- return wx.TreeCtrl.AppendItem(
- self, parent, text, image, selImage, wx.TreeItemData(data)
- )
- def GetItemData(self, item):
- if wxPythonPhoenix:
- return wx.TreeCtrl.GetItemData(self, item)
- else:
- return wx.TreeCtrl.GetPyData(self, item)
- class CustomTreeCtrl(CT.CustomTreeCtrl):
- """Wrapper around wx.lib.agw.customtreectrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- CT.CustomTreeCtrl.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- CT.CustomTreeCtrl.SetToolTip(self, tipString=tip)
- else:
- CT.CustomTreeCtrl.SetToolTipString(self, tip)
- class ToolBar(wx.ToolBar):
- """Wrapper around wx.ToolBar to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ToolBar.__init__(self, *args, **kwargs)
- def AddLabelTool(
- self,
- toolId,
- label,
- bitmap,
- bmpDisabled=wx.NullBitmap,
- kind=0,
- shortHelpString="",
- longHelpString="",
- clientData=None,
- ):
- if wxPythonPhoenix:
- return wx.ToolBar.AddTool(
- self,
- toolId=toolId,
- label=label,
- bitmap=bitmap,
- bmpDisabled=bmpDisabled,
- kind=kind,
- shortHelp=shortHelpString,
- longHelp=longHelpString,
- clientData=clientData,
- )
- else:
- return wx.ToolBar.AddLabelTool(
- self,
- toolId,
- label,
- bitmap,
- bmpDisabled,
- kind,
- shortHelpString,
- longHelpString,
- clientData,
- )
- def InsertLabelTool(
- self,
- pos,
- toolId,
- label,
- bitmap,
- bmpDisabled=wx.NullBitmap,
- kind=0,
- shortHelpString="",
- longHelpString="",
- clientData=None,
- ):
- if wxPythonPhoenix:
- return wx.ToolBar.InsertTool(
- self,
- pos,
- toolId=toolId,
- label=label,
- bitmap=bitmap,
- bmpDisabled=bmpDisabled,
- kind=kind,
- shortHelp=shortHelpString,
- longHelp=longHelpString,
- clientData=clientData,
- )
- else:
- return wx.ToolBar.InsertLabelTool(
- self,
- pos,
- toolId,
- label,
- bitmap,
- bmpDisabled,
- kind,
- shortHelpString,
- longHelpString,
- clientData,
- )
- class Menu(wx.Menu):
- """Wrapper around wx.Menu to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Menu.__init__(self, *args, **kwargs)
- def AppendItem(self, menuItem):
- if wxPythonPhoenix:
- wx.Menu.Append(self, menuItem=menuItem)
- else:
- wx.Menu.AppendItem(self, menuItem)
- def AppendMenu(self, id, text, submenu, help=""):
- if wxPythonPhoenix:
- wx.Menu.Append(self, id=id, item=text, subMenu=submenu, helpString=help)
- else:
- wx.Menu.AppendMenu(self, id=id, text=text, submenu=submenu, help=help)
- class DragImage(wx.GenericDragImage if wxPythonPhoenix else wx.DragImage):
- """Wrapper around wx.DragImage to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- super(DragImage, self).__init__(*args, **kwargs)
- class PseudoDC(wx.adv.PseudoDC if wxPythonPhoenix else wx.PseudoDC):
- """Wrapper around wx.PseudoDC to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- super(PseudoDC, self).__init__(*args, **kwargs)
- def DrawLinePoint(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args, roundVal=True)
- kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
- if wxPythonPhoenix:
- super(PseudoDC, self).DrawLine(*args, **kwargs)
- else:
- super(PseudoDC, self).DrawLinePoint(*args, **kwargs)
- def DrawRectangleRect(self, rect):
- if wxPythonPhoenix:
- super(PseudoDC, self).DrawRectangle(rect=rect)
- else:
- super(PseudoDC, self).DrawRectangleRect(rect)
- def BeginDrawing(self):
- if not wxPythonPhoenix:
- super(PseudoDC, self).BeginDrawing()
- def EndDrawing(self):
- if not wxPythonPhoenix:
- super(PseudoDC, self).EndDrawing()
- def DrawRectangle(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args, roundVal=True)
- kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
- super(PseudoDC, self).DrawRectangle(*args, **kwargs)
- def DrawBitmap(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args, roundVal=True)
- kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
- super(PseudoDC, self).DrawBitmap(*args, **kwargs)
- def DrawCircle(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args, roundVal=True)
- kwargs = convertToInt(argsOrKwargs=kwargs, roundVal=True)
- super(PseudoDC, self).DrawCircle(*args, **kwargs)
- class ClientDC(wx.ClientDC):
- """Wrapper around wx.ClientDC to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- super(ClientDC, self).__init__(*args, **kwargs)
- def GetFullMultiLineTextExtent(self, string, font=None):
- if wxPythonPhoenix:
- return super(ClientDC, self).GetFullMultiLineTextExtent(string, font)
- else:
- return super(ClientDC, self).GetMultiLineTextExtent(string, font)
- class Rect(wx.Rect):
- """Wrapper around wx.Rect to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- args = convertToInt(argsOrKwargs=args)
- kwargs = convertToInt(argsOrKwargs=kwargs)
- wx.Rect.__init__(self, *args, **kwargs)
- def ContainsXY(self, x, y):
- if wxPythonPhoenix:
- return wx.Rect.Contains(self, x=int(x), y=int(y))
- else:
- return wx.Rect.ContainsXY(self, int(x), int(y))
- def ContainsRect(self, rect):
- if wxPythonPhoenix:
- return wx.Rect.Contains(self, rect=rect)
- else:
- return wx.Rect.ContainsRect(self, rect)
- def OffsetXY(self, dx, dy):
- if wxPythonPhoenix:
- return wx.Rect.Offset(self, int(dx), int(dy))
- else:
- return wx.Rect.OffsetXY(self, int(dx), int(dy))
- class CheckBox(wx.CheckBox):
- """Wrapper around wx.CheckBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.CheckBox.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.CheckBox.SetToolTip(self, tipString=tip)
- else:
- wx.CheckBox.SetToolTipString(self, tip)
- class Choice(wx.Choice):
- """Wrapper around wx.Choice to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Choice.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.Choice.SetToolTip(self, tipString=tip)
- else:
- wx.Choice.SetToolTipString(self, tip)
- class TextEntryDialog(wx.TextEntryDialog):
- """Wrapper around wx.TextEntryDialog to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(
- self,
- parent,
- message,
- caption="Please enter text",
- value="",
- style=wx.OK | wx.CANCEL | wx.CENTRE,
- pos=wx.DefaultPosition,
- ):
- if wxPythonPhoenix:
- super(TextEntryDialog, self).__init__(
- parent=parent,
- message=message,
- caption=caption,
- value=value,
- style=style,
- pos=pos,
- )
- else:
- super(TextEntryDialog, self).__init__(
- parent=parent,
- message=message,
- caption=caption,
- defaultValue=value,
- style=style,
- pos=pos,
- )
- class ColourSelect(csel.ColourSelect):
- """Wrapper around wx.lib.colourselect.ColourSelect to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- csel.ColourSelect.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- csel.ColourSelect.SetToolTip(self, tipString=tip)
- else:
- csel.ColourSelect.SetToolTipString(self, tip)
- class ComboCtrl(wxComboCtrl):
- def __init__(self, *args, **kwargs):
- wxComboCtrl.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wxComboCtrl.SetToolTip(self, tipString=tip)
- else:
- wxComboCtrl.SetToolTipString(self, tip)
- class Dialog(wx.Dialog):
- """Wrapper around wx.Dialog to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Dialog.__init__(self, *args, **kwargs)
- class Notebook(wx.Notebook):
- """Wrapper around NoteBook to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.Notebook.__init__(self, *args, **kwargs)
- class OwnerDrawnComboBox(OwnerDrawnComboBox_):
- """Wrapper around OwnerDrawnComboBox to have more control
- over the widget on different platforms/wxpython versions"""
- ODCB_PAINTING_CONTROL = ODCB_PAINTING_CONTROL
- ODCB_PAINTING_SELECTED = ODCB_PAINTING_SELECTED
- def __init__(self, *args, **kwargs):
- OwnerDrawnComboBox_.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- OwnerDrawnComboBox_.SetToolTip(self, tipString=tip)
- else:
- OwnerDrawnComboBox_.SetToolTipString(self, tip)
- class BitmapComboBox(BitmapComboBox_):
- """Wrapper around BitmapComboBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- BitmapComboBox_.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- BitmapComboBox_.SetToolTip(self, tipString=tip)
- else:
- BitmapComboBox_.SetToolTipString(self, tip)
- class ScrolledPanel(scrolled.ScrolledPanel):
- """Wrapper around scrolled.ScrolledPanel to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- scrolled.ScrolledPanel.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- scrolled.ScrolledPanel.SetToolTip(self, tipString=tip)
- else:
- scrolled.ScrolledPanel.SetToolTipString(self, tip)
- class FileBrowseButton(filebrowse.FileBrowseButton):
- """Wrapper around filebrowse.FileBrowseButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- filebrowse.FileBrowseButton.__init__(self, *args, **kwargs)
- class DirBrowseButton(filebrowse.DirBrowseButton):
- """Wrapper around filebrowse.DirBrowseButton to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- filebrowse.DirBrowseButton.__init__(self, *args, **kwargs)
- class ExpandoTextCtrl(expando.ExpandoTextCtrl):
- """Wrapper around expando.ExpandoTextCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- EVT_ETC_LAYOUT_NEEDED = expando.EVT_ETC_LAYOUT_NEEDED
- def __init__(self, *args, **kwargs):
- expando.ExpandoTextCtrl.__init__(self, *args, **kwargs)
- class ColourPickerCtrl(wx.ColourPickerCtrl):
- """Wrapper around wx.ColourPickerCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ColourPickerCtrl.__init__(self, *args, **kwargs)
- class ListBox(wx.ListBox):
- """Wrapper around wx.ListBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ListBox.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.ListBox.SetToolTip(self, tipString=tip)
- else:
- wx.ListBox.SetToolTipString(self, tip)
- class HyperlinkCtrl(HyperlinkCtrl_):
- """Wrapper around HyperlinkCtrl to have more control
- over the widget on different platforms/wxpython versions"""
- HL_ALIGN_LEFT = HL_ALIGN_LEFT
- HL_CONTEXTMENU = HL_CONTEXTMENU
- def __init__(self, *args, **kwargs):
- HyperlinkCtrl_.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- HyperlinkCtrl_.SetToolTip(self, tipString=tip)
- else:
- HyperlinkCtrl_.SetToolTipString(self, tip)
- class ComboBox(wx.ComboBox):
- """Wrapper around wx.ComboBox to have more control
- over the widget on different platforms/wxpython versions"""
- def __init__(self, *args, **kwargs):
- wx.ComboBox.__init__(self, *args, **kwargs)
- def SetToolTip(self, tip):
- if wxPythonPhoenix:
- wx.ComboBox.SetToolTip(self, tipString=tip)
- else:
- wx.ComboBox.SetToolTipString(self, tip)
- class SimpleTabArt(tabart.AuiDefaultTabArt):
- """A class simplifying the appearance of AUI notebook tabs."""
- def __init__(self):
- """Default class constructor."""
- tabart.AuiDefaultTabArt.__init__(self)
- def SetDefaultColours(self, base_colour=None):
- """
- Overrides AuiDefaultTabArt.SetDefaultColours
- to get rid of gradient and to look more like
- flatnotebook tabs.
- """
- if base_colour is None:
- base_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)
- self.SetBaseColour(base_colour)
- tab_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
- self._border_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNSHADOW)
- self._border_pen = wx.Pen(self._border_colour)
- self._background_top_colour = base_colour
- self._background_bottom_colour = base_colour
- self._tab_top_colour = tab_color
- self._tab_bottom_colour = tab_color
- self._tab_gradient_highlight_colour = tab_color
- self._tab_inactive_top_colour = base_colour
- self._tab_inactive_bottom_colour = base_colour
- self._tab_text_colour = lambda page: page.text_colour
- self._tab_disabled_text_colour = wx.SystemSettings.GetColour(
- wx.SYS_COLOUR_GRAYTEXT
- )
|