-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwxwrap.py
112 lines (80 loc) · 3.18 KB
/
wxwrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
@brief Core wrapped wxpython widgets
Taken from GRASS GIS gui/wxpython/gui_core/wrap.py
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 ([email protected])
"""
import wx
wxPythonPhoenix = False
if "phoenix" in wx.version():
wxPythonPhoenix = True
gtk3 = True if "gtk3" in wx.PlatformInfo else False
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 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 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 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 SpinCtrl(wx.SpinCtrl):
"""Wrapper around wx.SpinCtrl 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)
wx.SpinCtrl.__init__(self, *args, **kwargs)
def SetToolTip(self, tip):
if wxPythonPhoenix:
wx.SpinCtrl.SetToolTip(self, tipString=tip)
else:
wx.SpinCtrl.SetToolTipString(self, tip)
def BitmapFromImage(image, depth=-1):
if wxPythonPhoenix:
return wx.Bitmap(img=image, depth=depth)
else:
return wx.BitmapFromImage(image, depth=depth)
def ImageFromStream(stream, type=wx.BITMAP_TYPE_ANY, index=-1):
if wxPythonPhoenix:
return wx.Image(stream=stream, type=type, index=index)
else:
return wx.ImageFromStream(stream=stream, type=type, index=index)