Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70d6d70

Browse files
committed
- clean up of examples, tested with wxPython 2.8.12.1, 3.0.1.1, Phoenix 3.0.2.dev77483 both for 'WX' and 'WXAgg' backends
- remove special casing of toolbar for WXMAC, if necessary put it back in but check WXMAC version as it does not work in 10.9
1 parent 6002b70 commit 70d6d70

File tree

4 files changed

+26
-61
lines changed

4 files changed

+26
-61
lines changed

examples/user_interfaces/embedding_in_wx2.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
wxversion.ensureMinimal('2.8')
1212
#wxversion.select('2.8')
1313
#wxversion.select('2.9.5')
14+
#wxversion.select('3.0-classic', True)
1415
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
1516

1617
from numpy import arange, sin, pi
@@ -41,11 +42,6 @@ def __init__(self):
4142
wx.Frame.__init__(self,None,-1,
4243
'CanvasFrame',size=(550,350))
4344

44-
if 'phoenix' in wx.PlatformInfo:
45-
self.SetBackgroundColour(wx.Colour("WHITE"))
46-
else:
47-
self.SetBackgroundColour(wx.NamedColour("WHITE"))
48-
4945
self.figure = Figure()
5046
self.axes = self.figure.add_subplot(111)
5147
t = arange(0.0,3.0,0.01)
@@ -55,7 +51,7 @@ def __init__(self):
5551
self.canvas = FigureCanvas(self, -1, self.figure)
5652

5753
self.sizer = wx.BoxSizer(wx.VERTICAL)
58-
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
54+
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
5955
self.SetSizer(self.sizer)
6056
self.Fit()
6157

@@ -64,33 +60,18 @@ def __init__(self):
6460
def add_toolbar(self):
6561
self.toolbar = NavigationToolbar2Wx(self.canvas)
6662
self.toolbar.Realize()
67-
if wx.Platform == '__WXMAC__':
68-
# Mac platform (OSX 10.3, MacPython) does not seem to cope with
69-
# having a toolbar in a sizer. This work-around gets the buttons
70-
# back, but at the expense of having the toolbar at the top
71-
self.SetToolBar(self.toolbar)
72-
else:
73-
# On Windows platform, default window size is incorrect, so set
74-
# toolbar width to figure width.
75-
if 'phoenix' in wx.PlatformInfo:
76-
tw, th = self.toolbar.GetSize()
77-
fw, fh = self.canvas.GetSize()
78-
else:
79-
tw, th = self.toolbar.GetSizeTuple()
80-
fw, fh = self.canvas.GetSizeTuple()
81-
# By adding toolbar in sizer, we are able to put it at the bottom
82-
# of the frame - so appearance is closer to GTK version.
83-
# As noted above, doesn't work for Mac.
84-
self.toolbar.SetSize(wx.Size(fw, th))
85-
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
63+
# By adding toolbar in sizer, we are able to put it at the bottom
64+
# of the frame - so appearance is closer to GTK version.
65+
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
8666
# update the axes menu on the toolbar
8767
self.toolbar.update()
8868

89-
90-
class App(wx.App):
69+
import wx.lib.mixins.inspection as WIT
70+
class App(WIT.InspectableApp):
9171

9272
def OnInit(self):
9373
'Create the main window and insert the custom frame'
74+
self.Init()
9475
frame = CanvasFrame()
9576
frame.Show(True)
9677

examples/user_interfaces/embedding_in_wx4.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
from numpy.random import rand
2727

2828
import wx
29+
print(wx.VERSION_STRING)
30+
print(wx.PlatformInfo)
31+
print(matplotlib.__version__)
32+
2933

3034

3135
class MyNavigationToolbar(NavigationToolbar2WxAgg):
@@ -73,11 +77,6 @@ def __init__(self):
7377
wx.Frame.__init__(self,None,-1,
7478
'CanvasFrame',size=(550,350))
7579

76-
if 'phoenix' in wx.PlatformInfo:
77-
self.SetBackgroundColour(wx.Colour("WHITE"))
78-
else:
79-
self.SetBackgroundColour(wx.NamedColour("WHITE"))
80-
8180
self.figure = Figure(figsize=(5,4), dpi=100)
8281
self.axes = self.figure.add_subplot(111)
8382
t = arange(0.0,3.0,0.01)
@@ -94,25 +93,9 @@ def __init__(self):
9493

9594
self.toolbar = MyNavigationToolbar(self.canvas, True)
9695
self.toolbar.Realize()
97-
if wx.Platform == '__WXMAC__':
98-
# Mac platform (OSX 10.3, MacPython) does not seem to cope with
99-
# having a toolbar in a sizer. This work-around gets the buttons
100-
# back, but at the expense of having the toolbar at the top
101-
self.SetToolBar(self.toolbar)
102-
else:
103-
# On Windows platform, default window size is incorrect, so set
104-
# toolbar width to figure width.
105-
if 'phoenix' in wx.PlatformInfo:
106-
tw, th = self.toolbar.GetSize()
107-
fw, fh = self.canvas.GetSize()
108-
else:
109-
tw, th = self.toolbar.GetSizeTuple()
110-
fw, fh = self.canvas.GetSizeTuple()
111-
# By adding toolbar in sizer, we are able to put it at the bottom
112-
# of the frame - so appearance is closer to GTK version.
113-
# As noted above, doesn't work for Mac.
114-
self.toolbar.SetSize(wx.Size(fw, th))
115-
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
96+
# By adding toolbar in sizer, we are able to put it at the bottom
97+
# of the frame - so appearance is closer to GTK version.
98+
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
11699

117100
# update the axes menu on the toolbar
118101
self.toolbar.update()

examples/user_interfaces/embedding_in_wx5.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
if sys.version_info.major < 3:
55
# Used to guarantee to use at least Wx2.8
66
import wxversion
7-
wxversion.ensureMinimal('2.8')
7+
#wxversion.ensureMinimal('2.8')
88
#wxversion.select('2.8')
99
#wxversion.select('2.9.5')
10-
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
10+
#wxversion.select('3.0-classic', True)
11+
wxversion.select('3.0.2-phoenix', optionsRequired=True)
1112

1213
import wx
13-
print(wx.VERSION_STRING)
1414

1515
if 'phoenix' in wx.PlatformInfo:
1616
import wx.lib.agw.aui as aui
@@ -21,6 +21,9 @@
2121
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
2222
from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar
2323

24+
print(wx.VERSION_STRING)
25+
print(wx.PlatformInfo)
26+
print(mpl.__version__)
2427

2528
class Plot(wx.Panel):
2629
def __init__(self, parent, id = -1, dpi = None, **kwargs):
@@ -34,11 +37,6 @@ def __init__(self, parent, id = -1, dpi = None, **kwargs):
3437
sizer.Add(self.canvas,1,wx.EXPAND)
3538
sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
3639
self.SetSizer(sizer)
37-
self.Bind(wx.EVT_PAINT, self.OnPaint)
38-
39-
def OnPaint(self, event):
40-
self.canvas.draw()
41-
event.Skip()
4240

4341

4442

examples/user_interfaces/fourier_demo_wx.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88
wxversion.ensureMinimal('2.8')
99
#wxversion.select('2.8')
1010
#wxversion.select('2.9.5')
11+
#wxversion.select('3.0-classic', True)
1112
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
1213

13-
1414
import wx
15-
print(wx.VERSION_STRING)
1615
import matplotlib
1716
matplotlib.interactive(False)
1817
matplotlib.use('WXAgg')
1918
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
2019
from matplotlib.figure import Figure
2120
from matplotlib.pyplot import gcf, setp
2221

22+
import wx
23+
print(wx.VERSION_STRING)
24+
print(wx.PlatformInfo)
25+
print(matplotlib.__version__)
2326

2427
class Knob:
2528
"""

0 commit comments

Comments
 (0)