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

Skip to content

Commit 970c774

Browse files
committed
- PEP8'ify
1 parent 25798d5 commit 970c774

File tree

4 files changed

+111
-67
lines changed

4 files changed

+111
-67
lines changed

examples/user_interfaces/embedding_in_wx2.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# Used to guarantee to use at least Wx2.8
1010
import wxversion
1111
wxversion.ensureMinimal('2.8')
12-
#wxversion.select('2.8')
13-
#wxversion.select('2.9.5')
12+
# wxversion.select('2.8')
13+
# wxversion.select('2.9.5')
1414
#wxversion.select('3.0-classic', True)
1515
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
1616

@@ -39,15 +39,15 @@
3939
class CanvasFrame(wx.Frame):
4040

4141
def __init__(self):
42-
wx.Frame.__init__(self,None,-1,
43-
'CanvasFrame',size=(550,350))
42+
wx.Frame.__init__(self, None, -1,
43+
'CanvasFrame', size=(550, 350))
4444

4545
self.figure = Figure()
4646
self.axes = self.figure.add_subplot(111)
47-
t = arange(0.0,3.0,0.01)
48-
s = sin(2*pi*t)
47+
t = arange(0.0, 3.0, 0.01)
48+
s = sin(2 * pi * t)
4949

50-
self.axes.plot(t,s)
50+
self.axes.plot(t, s)
5151
self.canvas = FigureCanvas(self, -1, self.figure)
5252

5353
self.sizer = wx.BoxSizer(wx.VERTICAL)
@@ -67,6 +67,8 @@ def add_toolbar(self):
6767
self.toolbar.update()
6868

6969
import wx.lib.mixins.inspection as WIT
70+
71+
7072
class App(WIT.InspectableApp):
7173

7274
def OnInit(self):

examples/user_interfaces/embedding_in_wx4.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# Used to guarantee to use at least Wx2.8
1010
import wxversion
1111
wxversion.ensureMinimal('2.8')
12-
#wxversion.select('2.8')
13-
#wxversion.select('2.9.5')
12+
# wxversion.select('2.8')
13+
# wxversion.select('2.9.5')
1414
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
1515

1616
from numpy import arange, sin, pi
@@ -31,8 +31,8 @@
3131
print(matplotlib.__version__)
3232

3333

34-
3534
class MyNavigationToolbar(NavigationToolbar2WxAgg):
35+
3636
"""
3737
Extend the default wx toolbar with your own event handlers
3838
"""
@@ -61,7 +61,7 @@ def _on_custom(self, evt):
6161
ax = self.canvas.figure.axes[0]
6262

6363
# generate a random location can color
64-
x,y = tuple(rand(2))
64+
x, y = tuple(rand(2))
6565
rgb = tuple(rand(3))
6666

6767
# add the text and draw
@@ -73,16 +73,17 @@ def _on_custom(self, evt):
7373

7474

7575
class CanvasFrame(wx.Frame):
76+
7677
def __init__(self):
77-
wx.Frame.__init__(self,None,-1,
78-
'CanvasFrame',size=(550,350))
78+
wx.Frame.__init__(self, None, -1,
79+
'CanvasFrame', size=(550, 350))
7980

80-
self.figure = Figure(figsize=(5,4), dpi=100)
81+
self.figure = Figure(figsize=(5, 4), dpi=100)
8182
self.axes = self.figure.add_subplot(111)
82-
t = arange(0.0,3.0,0.01)
83-
s = sin(2*pi*t)
83+
t = arange(0.0, 3.0, 0.01)
84+
s = sin(2 * pi * t)
8485

85-
self.axes.plot(t,s)
86+
self.axes.plot(t, s)
8687

8788
self.canvas = FigureCanvas(self, -1, self.figure)
8889

@@ -108,6 +109,7 @@ def OnPaint(self, event):
108109

109110

110111
class App(wx.App):
112+
111113
def OnInit(self):
112114
'Create the main window and insert the custom frame'
113115
frame = CanvasFrame()

examples/user_interfaces/embedding_in_wx5.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
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')
8-
#wxversion.select('2.8')
9-
#wxversion.select('2.9.5')
7+
# wxversion.ensureMinimal('2.8')
8+
# wxversion.select('2.8')
9+
# wxversion.select('2.9.5')
1010
#wxversion.select('3.0-classic', True)
1111
wxversion.select('3.0.2-phoenix', optionsRequired=True)
1212

@@ -25,47 +25,50 @@
2525
print(wx.PlatformInfo)
2626
print(mpl.__version__)
2727

28+
2829
class Plot(wx.Panel):
29-
def __init__(self, parent, id = -1, dpi = None, **kwargs):
30+
31+
def __init__(self, parent, id=-1, dpi=None, **kwargs):
3032
wx.Panel.__init__(self, parent, id=id, **kwargs)
31-
self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2,2))
33+
self.figure = mpl.figure.Figure(dpi=dpi, figsize=(2, 2))
3234
self.canvas = Canvas(self, -1, self.figure)
3335
self.toolbar = Toolbar(self.canvas)
3436
self.toolbar.Realize()
3537

3638
sizer = wx.BoxSizer(wx.VERTICAL)
37-
sizer.Add(self.canvas,1,wx.EXPAND)
38-
sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
39+
sizer.Add(self.canvas, 1, wx.EXPAND)
40+
sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
3941
self.SetSizer(sizer)
4042

4143

42-
4344
class PlotNotebook(wx.Panel):
44-
def __init__(self, parent, id = -1):
45+
46+
def __init__(self, parent, id=-1):
4547
wx.Panel.__init__(self, parent, id=id)
4648
self.nb = aui.AuiNotebook(self)
4749
sizer = wx.BoxSizer()
4850
sizer.Add(self.nb, 1, wx.EXPAND)
4951
self.SetSizer(sizer)
5052

51-
def add(self,name="plot"):
53+
def add(self, name="plot"):
5254
page = Plot(self.nb)
53-
self.nb.AddPage(page,name)
55+
self.nb.AddPage(page, name)
5456
return page.figure
5557

5658

5759
def demo():
5860
import wx.lib.mixins.inspection as wit
5961
app = wit.InspectableApp()
60-
frame = wx.Frame(None,-1,'Plotter')
62+
frame = wx.Frame(None, -1, 'Plotter')
6163
plotter = PlotNotebook(frame)
6264
axes1 = plotter.add('figure 1').gca()
63-
axes1.plot([1,2,3],[2,1,4])
65+
axes1.plot([1, 2, 3], [2, 1, 4])
6466
axes2 = plotter.add('figure 2').gca()
65-
axes2.plot([1,2,3,4,5],[2,1,4,2,3])
66-
#axes1.figure.canvas.draw()
67-
#axes2.figure.canvas.draw()
67+
axes2.plot([1, 2, 3, 4, 5], [2, 1, 4, 2, 3])
68+
# axes1.figure.canvas.draw()
69+
# axes2.figure.canvas.draw()
6870
frame.Show()
6971
app.MainLoop()
7072

71-
if __name__ == "__main__": demo()
73+
if __name__ == "__main__":
74+
demo()

examples/user_interfaces/fourier_demo_wx.py

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# Used to guarantee to use at least Wx2.8
77
import wxversion
88
wxversion.ensureMinimal('2.8')
9-
#wxversion.select('2.8')
10-
#wxversion.select('2.9.5')
9+
# wxversion.select('2.8')
10+
# wxversion.select('2.9.5')
1111
#wxversion.select('3.0-classic', True)
1212
#wxversion.select('3.0.2-phoenix', optionsRequired=True)
1313

@@ -24,17 +24,21 @@
2424
print(wx.PlatformInfo)
2525
print(matplotlib.__version__)
2626

27+
2728
class Knob:
29+
2830
"""
2931
Knob - simple class with a "setKnob" method.
3032
A Knob instance is attached to a Param instance, e.g., param.attach(knob)
3133
Base class is for documentation purposes.
3234
"""
35+
3336
def setKnob(self, value):
3437
pass
3538

3639

3740
class Param:
41+
3842
"""
3943
The idea of the "Param" class is that some parameter in the GUI may have
4044
several knobs that both control it and reflect the parameter's state, e.g.
@@ -47,6 +51,7 @@ class Param:
4751
- the other knobs in the knob list have a "set" method which gets
4852
called for the others.
4953
"""
54+
5055
def __init__(self, initialValue=None, minimum=0., maximum=1.):
5156
self.minimum = minimum
5257
self.maximum = maximum
@@ -75,17 +80,26 @@ def constrain(self, value):
7580

7681

7782
class SliderGroup(Knob):
83+
7884
def __init__(self, parent, label, param):
7985
self.sliderLabel = wx.StaticText(parent, label=label)
8086
self.sliderText = wx.TextCtrl(parent, -1, style=wx.TE_PROCESS_ENTER)
8187
self.slider = wx.Slider(parent, -1)
82-
#self.slider.SetMax(param.maximum*1000)
83-
self.slider.SetRange(0, param.maximum*1000)
88+
# self.slider.SetMax(param.maximum*1000)
89+
self.slider.SetRange(0, param.maximum * 1000)
8490
self.setKnob(param.value)
8591

8692
sizer = wx.BoxSizer(wx.HORIZONTAL)
87-
sizer.Add(self.sliderLabel, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=2)
88-
sizer.Add(self.sliderText, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=2)
93+
sizer.Add(
94+
self.sliderLabel,
95+
0,
96+
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL,
97+
border=2)
98+
sizer.Add(
99+
self.sliderText,
100+
0,
101+
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL,
102+
border=2)
89103
sizer.Add(self.slider, 1, wx.EXPAND)
90104
self.sizer = sizer
91105

@@ -104,30 +118,34 @@ def sliderTextHandler(self, evt):
104118
self.param.set(value)
105119

106120
def setKnob(self, value):
107-
self.sliderText.SetValue('%g'%value)
108-
self.slider.SetValue(value*1000)
121+
self.sliderText.SetValue('%g' % value)
122+
self.slider.SetValue(value * 1000)
109123

110124

111125
class FourierDemoFrame(wx.Frame):
126+
112127
def __init__(self, *args, **kwargs):
113128
wx.Frame.__init__(self, *args, **kwargs)
114129

115130
self.fourierDemoWindow = FourierDemoWindow(self)
116-
self.frequencySliderGroup = SliderGroup(self, label='Frequency f0:', \
131+
self.frequencySliderGroup = SliderGroup(
132+
self,
133+
label='Frequency f0:',
117134
param=self.fourierDemoWindow.f0)
118-
self.amplitudeSliderGroup = SliderGroup(self, label=' Amplitude a:', \
119-
param=self.fourierDemoWindow.A)
135+
self.amplitudeSliderGroup = SliderGroup(self, label=' Amplitude a:',
136+
param=self.fourierDemoWindow.A)
120137

121138
sizer = wx.BoxSizer(wx.VERTICAL)
122139
sizer.Add(self.fourierDemoWindow, 1, wx.EXPAND)
123-
sizer.Add(self.frequencySliderGroup.sizer, 0, \
124-
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5)
125-
sizer.Add(self.amplitudeSliderGroup.sizer, 0, \
126-
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5)
140+
sizer.Add(self.frequencySliderGroup.sizer, 0,
141+
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5)
142+
sizer.Add(self.amplitudeSliderGroup.sizer, 0,
143+
wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, border=5)
127144
self.SetSizer(sizer)
128145

129146

130147
class FourierDemoWindow(wx.Window, Knob):
148+
131149
def __init__(self, *args, **kwargs):
132150
wx.Window.__init__(self, *args, **kwargs)
133151
self.lines = []
@@ -166,7 +184,9 @@ def mouseDown(self, evt):
166184
self.state = 'time'
167185
else:
168186
self.state = ''
169-
self.mouseInfo = (evt.xdata, evt.ydata, max(self.f0.value, .1), self.A.value)
187+
self.mouseInfo = (
188+
evt.xdata, evt.ydata, max(
189+
self.f0.value, .1), self.A.value)
170190

171191
def mouseMotion(self, evt):
172192
if self.state == '':
@@ -175,12 +195,12 @@ def mouseMotion(self, evt):
175195
if x is None: # outside the axes
176196
return
177197
x0, y0, f0Init, AInit = self.mouseInfo
178-
self.A.set(AInit+(AInit*(y-y0)/y0), self)
198+
self.A.set(AInit + (AInit * (y - y0) / y0), self)
179199
if self.state == 'frequency':
180-
self.f0.set(f0Init+(f0Init*(x-x0)/x0))
200+
self.f0.set(f0Init + (f0Init * (x - x0) / x0))
181201
elif self.state == 'time':
182-
if (x-x0)/x0 != -1.:
183-
self.f0.set(1./(1./f0Init+(1./f0Init*(x-x0)/x0)))
202+
if (x - x0) / x0 != -1.:
203+
self.f0.set(1. / (1. / f0Init + (1. / f0Init * (x - x0) / x0)))
184204

185205
def mouseUp(self, evt):
186206
self.state = ''
@@ -193,26 +213,37 @@ def draw(self):
193213
color = (1., 0., 0.)
194214
self.lines += self.subplot1.plot(x1, y1, color=color, linewidth=2)
195215
self.lines += self.subplot2.plot(x2, y2, color=color, linewidth=2)
196-
#Set some plot attributes
197-
self.subplot1.set_title("Click and drag waveforms to change frequency and amplitude", fontsize=12)
198-
self.subplot1.set_ylabel("Frequency Domain Waveform X(f)", fontsize = 8)
199-
self.subplot1.set_xlabel("frequency f", fontsize = 8)
200-
self.subplot2.set_ylabel("Time Domain Waveform x(t)", fontsize = 8)
201-
self.subplot2.set_xlabel("time t", fontsize = 8)
216+
# Set some plot attributes
217+
self.subplot1.set_title(
218+
"Click and drag waveforms to change frequency and amplitude",
219+
fontsize=12)
220+
self.subplot1.set_ylabel("Frequency Domain Waveform X(f)", fontsize=8)
221+
self.subplot1.set_xlabel("frequency f", fontsize=8)
222+
self.subplot2.set_ylabel("Time Domain Waveform x(t)", fontsize=8)
223+
self.subplot2.set_xlabel("time t", fontsize=8)
202224
self.subplot1.set_xlim([-6, 6])
203225
self.subplot1.set_ylim([0, 1])
204226
self.subplot2.set_xlim([-2, 2])
205227
self.subplot2.set_ylim([-2, 2])
206-
self.subplot1.text(0.05, .95, r'$X(f) = \mathcal{F}\{x(t)\}$', \
207-
verticalalignment='top', transform = self.subplot1.transAxes)
208-
self.subplot2.text(0.05, .95, r'$x(t) = a \cdot \cos(2\pi f_0 t) e^{-\pi t^2}$', \
209-
verticalalignment='top', transform = self.subplot2.transAxes)
228+
self.subplot1.text(
229+
0.05,
230+
.95,
231+
r'$X(f) = \mathcal{F}\{x(t)\}$',
232+
verticalalignment='top',
233+
transform=self.subplot1.transAxes)
234+
self.subplot2.text(
235+
0.05,
236+
.95,
237+
r'$x(t) = a \cdot \cos(2\pi f_0 t) e^{-\pi t^2}$',
238+
verticalalignment='top',
239+
transform=self.subplot2.transAxes)
210240

211241
def compute(self, f0, A):
212242
f = np.arange(-6., 6., 0.02)
213243
t = np.arange(-2., 2., 0.01)
214-
x = A*np.cos(2*np.pi*f0*t)*np.exp(-np.pi*t**2)
215-
X = A/2*(np.exp(-np.pi*(f-f0)**2) + np.exp(-np.pi*(f+f0)**2))
244+
x = A * np.cos(2 * np.pi * f0 * t) * np.exp(-np.pi * t ** 2)
245+
X = A / 2 * \
246+
(np.exp(-np.pi * (f - f0) ** 2) + np.exp(-np.pi * (f + f0) ** 2))
216247
return f, X, t, x
217248

218249
def repaint(self):
@@ -227,8 +258,14 @@ def setKnob(self, value):
227258

228259

229260
class App(wx.App):
261+
230262
def OnInit(self):
231-
self.frame1 = FourierDemoFrame(parent=None, title="Fourier Demo", size=(640, 480))
263+
self.frame1 = FourierDemoFrame(
264+
parent=None,
265+
title="Fourier Demo",
266+
size=(
267+
640,
268+
480))
232269
self.frame1.Show()
233270
return True
234271

0 commit comments

Comments
 (0)