Skip to content

Commit 3035058

Browse files
author
Pierre Raybaut
committed
Fixed some examples (MapDemo, MultiDemo, ReallySimpleDemo, ...)
1 parent ee279a8 commit 3035058

File tree

9 files changed

+63
-571
lines changed

9 files changed

+63
-571
lines changed

examples/CurveDemo2.py

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#!/usr/bin/env python
22

3-
# The Python version of qwt-*/examples/curvdemo2
4-
3+
#FIXME: scale issue!
54

65
import sys
76
from PyQt4 import Qt
8-
#import PyQt4.Qwt5 as Qwt
97
import qwt as Qwt
10-
from PyQt4.Qwt5.anynumpy import *
8+
import numpy as np
119

12-
Size=15
13-
USize=13
10+
Size = 15
11+
USize = 13
1412

1513
class CurveDemo(Qt.QFrame):
1614

@@ -29,18 +27,14 @@ def __init__(self, *args):
2927
# curve 1
3028
curve = Qwt.QwtPlotCurve()
3129
curve.setPen(Qt.QPen(Qt.QColor(150, 150, 200), 2))
32-
curve.setCurveType(Qwt.QwtPlotCurve.Xfy)
3330
curve.setStyle(Qwt.QwtPlotCurve.Lines)
34-
curveFitter = Qwt.QwtSplineCurveFitter()
35-
curveFitter.setSplineSize(150)
36-
curve.setCurveFitter(curveFitter)
3731
curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.XCross,
3832
Qt.QBrush(),
3933
Qt.QPen(Qt.Qt.yellow, 2),
4034
Qt.QSize(7, 7)))
4135
self.tuples.append((curve,
4236
Qwt.QwtScaleMap(0, 100, -1.5, 1.5),
43-
Qwt.QwtScaleMap(0, 100, 0.0, 2*pi)))
37+
Qwt.QwtScaleMap(0, 100, 0.0, 2*np.pi)))
4438
# curve 2
4539
curve = Qwt.QwtPlotCurve()
4640
curve.setPen(Qt.QPen(Qt.QColor(200, 150, 50),
@@ -52,75 +46,59 @@ def __init__(self, *args):
5246
Qt.QPen(Qt.Qt.yellow),
5347
Qt.QSize(5, 5)))
5448
self.tuples.append((curve,
55-
Qwt.QwtScaleMap(0, 100, 0.0, 2*pi),
49+
Qwt.QwtScaleMap(0, 100, 0.0, 2*np.pi),
5650
Qwt.QwtScaleMap(0, 100, -3.0, 1.1)))
5751
# curve 3
5852
curve = Qwt.QwtPlotCurve()
5953
curve.setPen(Qt.QPen(Qt.QColor(100, 200, 150)))
6054
curve.setStyle(Qwt.QwtPlotCurve.Lines)
61-
curve.setCurveAttribute(Qwt.QwtPlotCurve.Fitted)
62-
curveFitter = Qwt.QwtSplineCurveFitter()
63-
curveFitter.setFitMode(Qwt.QwtSplineCurveFitter.ParametricSpline)
64-
curveFitter.setSplineSize(200)
65-
curve.setCurveFitter(curveFitter)
6655
self.tuples.append((curve,
6756
Qwt.QwtScaleMap(0, 100, -1.1, 3.0),
6857
Qwt.QwtScaleMap(0, 100, -1.1, 3.0)))
6958
# curve 4
7059
curve = Qwt.QwtPlotCurve()
7160
curve.setPen(Qt.QPen(Qt.Qt.red))
7261
curve.setStyle(Qwt.QwtPlotCurve.Lines)
73-
curve.setCurveAttribute(Qwt.QwtPlotCurve.Fitted)
74-
curveFitter = Qwt.QwtSplineCurveFitter()
75-
curveFitter.setSplineSize(200)
76-
curve.setCurveFitter(curveFitter)
7762
self.tuples.append((curve,
7863
Qwt.QwtScaleMap(0, 100, -5.0, 1.1),
7964
Qwt.QwtScaleMap(0, 100, -1.1, 5.0)))
8065
# data
8166
self.phase = 0.0
82-
self.base = arange(0.0, 2.01*pi, 2*pi/(USize-1))
83-
self.uval = cos(self.base)
84-
self.vval = sin(self.base)
67+
self.base = np.arange(0.0, 2.01*np.pi, 2*np.pi/(USize-1))
68+
self.uval = np.cos(self.base)
69+
self.vval = np.sin(self.base)
8570
self.uval[1::2] *= 0.5
8671
self.vval[1::2] *= 0.5
8772
self.newValues()
8873
# start timer
8974
self.tid = self.startTimer(250)
9075

91-
# __init__()
92-
9376
def paintEvent(self, event):
9477
Qt.QFrame.paintEvent(self,event)
9578
painter = Qt.QPainter(self)
96-
#painter.setRenderHint(Qt.QPainter.Antialiasing)
9779
painter.setClipRect(self.contentsRect())
9880
self.drawContents(painter)
9981

100-
# paintEvent()
101-
10282
def drawContents(self, painter):
10383
r = self.contentsRect()
10484
for curve, xMap, yMap in self.tuples:
10585
xMap.setPaintInterval(r.left(), r.right())
10686
yMap.setPaintInterval(r.top(), r.bottom())
10787
curve.draw(painter, xMap, yMap, r)
10888

109-
# drawContents()
110-
11189
def timerEvent(self, event):
11290
self.newValues()
11391
self.repaint()
11492

11593
def newValues(self):
11694
phase = self.phase
11795

118-
self.xval = arange(0, 2.01*pi, 2*pi/(Size-1))
119-
self.yval = sin(self.xval - phase)
120-
self.zval = cos(3*(self.xval + phase))
96+
self.xval = np.arange(0, 2.01*np.pi, 2*np.pi/(Size-1))
97+
self.yval = np.sin(self.xval - phase)
98+
self.zval = np.cos(3*(self.xval + phase))
12199

122-
s = 0.25 * sin(phase)
123-
c = sqrt(1.0 - s*s)
100+
s = 0.25 * np.sin(phase)
101+
c = np.sqrt(1.0 - s*s)
124102
u = self.uval
125103
self.uval = c*self.uval-s*self.vval
126104
self.vval = c*self.vval+s*u
@@ -130,32 +108,19 @@ def newValues(self):
130108
self.tuples[2][0].setData(self.yval, self.zval)
131109
self.tuples[3][0].setData(self.uval, self.vval)
132110

133-
self.phase += 2*pi/100
134-
if self.phase>2*pi:
111+
self.phase += 2*np.pi/100
112+
if self.phase>2*np.pi:
135113
self.phase = 0.0
136114

137115

138116
def make():
139117
demo = CurveDemo()
140-
demo.resize(300, 300)
118+
demo.resize(600, 600)
141119
demo.show()
142120
return demo
143121

144-
# make()
145-
146122

147-
def main(args):
148-
app = Qt.QApplication(args)
149-
demo = make()
150-
sys.exit(app.exec_())
151-
152-
# main()
153-
154-
155-
# Admire!
156123
if __name__ == '__main__':
157-
main(sys.argv)
158-
159-
# Local Variables: ***
160-
# mode: python ***
161-
# End: ***
124+
app = Qt.QApplication(sys.argv)
125+
demo = make()
126+
sys.exit(app.exec_())

examples/MapDemo.py

Lines changed: 10 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
11
#!/usr/bin/env python
22

3-
43
import random
54
import sys
65
import time
7-
try:
8-
import resource
9-
has_resource = 1
10-
except ImportError:
11-
has_resource = 0
126

137
from PyQt4 import Qt
14-
#import PyQt4.Qwt5 as Qwt
158
import qwt as Qwt
16-
from PyQt4.Qwt5.anynumpy import *
9+
import numpy as np
1710

1811

1912
def standard_map(x, y, kappa):
2013
"""provide one interate of the inital conditions (x, y)
21-
for the standard map with parameter kappa.
22-
"""
23-
y_new = y-kappa*sin(2.0*pi*x)
14+
for the standard map with parameter kappa."""
15+
y_new = y-kappa*np.sin(2.0*np.pi*x)
2416
x_new = x+y_new
25-
2617
# bring back to [0,1.0]^2
2718
if( (x_new>1.0) or (x_new<0.0) ):
28-
x_new = x_new - floor(x_new)
19+
x_new = x_new - np.floor(x_new)
2920
if( (y_new>1.0) or (y_new<0.0) ):
30-
y_new = y_new - floor(y_new)
31-
21+
y_new = y_new - np.floor(y_new)
3222
return x_new, y_new
3323

34-
# standard_map
35-
3624

3725
class MapDemo(Qt.QMainWindow):
38-
3926
def __init__(self, *args):
4027
Qt.QMainWindow.__init__(self, *args)
41-
4228
self.plot = Qwt.QwtPlot(self)
4329
self.plot.setTitle("A Simple Map Demonstration")
4430
self.plot.setCanvasBackground(Qt.Qt.white)
@@ -47,82 +33,38 @@ def __init__(self, *args):
4733
self.plot.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 1.0)
4834
self.plot.setAxisScale(Qwt.QwtPlot.yLeft, 0.0, 1.0)
4935
self.setCentralWidget(self.plot)
50-
5136
# Initialize map data
5237
self.count = self.i = 1000
53-
self.xs = zeros(self.count, Float)
54-
self.ys = zeros(self.count, Float)
55-
38+
self.xs = np.zeros(self.count, np.float)
39+
self.ys = np.zeros(self.count, np.float)
5640
self.kappa = 0.2
57-
5841
self.curve = Qwt.QwtPlotCurve("Map")
5942
self.curve.attach(self.plot)
60-
6143
self.curve.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
6244
Qt.QBrush(Qt.Qt.red),
6345
Qt.QPen(Qt.Qt.blue),
6446
Qt.QSize(5, 5)))
65-
6647
self.curve.setPen(Qt.QPen(Qt.Qt.cyan))
67-
6848
toolBar = Qt.QToolBar(self)
6949
self.addToolBar(toolBar)
70-
71-
toolBar.addWidget(Qt.QLabel("Count:", toolBar))
72-
sizeCounter = Qwt.QwtCounter(toolBar)
73-
toolBar.addWidget(sizeCounter)
74-
toolBar.addSeparator()
75-
sizeCounter.setRange(0, 1000000, 100)
76-
sizeCounter.setValue(self.count)
77-
sizeCounter.setNumButtons(3)
78-
self.connect(
79-
sizeCounter, Qt.SIGNAL('valueChanged(double)'), self.setCount)
80-
81-
toolBar.addWidget(Qt.QLabel("Ticks (ms):", toolBar))
82-
tickCounter = Qwt.QwtCounter(toolBar)
83-
toolBar.addWidget(tickCounter)
84-
toolBar.addSeparator()
8550
# 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
8651
self.ticks = 10
87-
tickCounter.setRange(0, 1000, 1)
88-
tickCounter.setValue(self.ticks)
89-
tickCounter.setNumButtons(3)
90-
self.connect(
91-
tickCounter, Qt.SIGNAL('valueChanged(double)'), self.setTicks)
9252
self.tid = self.startTimer(self.ticks)
93-
9453
self.timer_tic = None
9554
self.user_tic = None
96-
self.system_tic = None
97-
55+
self.system_tic = None
9856
self.plot.replot()
9957

100-
# __init__()
101-
102-
def setCount(self, count):
103-
self.count = self.i = count
104-
self.xs = zeros(self.count, Float)
105-
self.ys = zeros(self.count, Float)
106-
self.i = self.count
107-
self.killTimer(self.tid)
108-
self.tid = self.startTimer(self.ticks)
109-
110-
# setCount()
111-
11258
def setTicks(self, ticks):
11359
self.i = self.count
11460
self.ticks = int(ticks)
11561
self.killTimer(self.tid)
11662
self.tid = self.startTimer(ticks)
117-
118-
# setTicks()
11963

12064
def resizeEvent(self, event):
12165
self.plot.resize(event.size())
12266
self.plot.move(0, 0)
12367

124-
# resizeEvent()
125-
12668
def moreData(self):
12769
if self.i == self.count:
12870
self.i = 0
@@ -132,17 +74,6 @@ def moreData(self):
13274
self.ys[self.i] = self.y
13375
self.i += 1
13476
chunks = []
135-
if has_resource:
136-
self.user_toc, self.system_toc = resource.getrusage(
137-
resource.RUSAGE_SELF)[:2]
138-
if self.user_tic:
139-
chunks.append("user: %s s;"
140-
% (self.user_toc-self.user_tic))
141-
self.user_tic = self.user_toc
142-
if self.system_tic:
143-
chunks.append("system: %s s;"
144-
% (self.system_toc-self.system_tic))
145-
self.system_tic = self.system_toc
14677
self.timer_toc = time.time()
14778
if self.timer_tic:
14879
chunks.append("wall: %s s." % (self.timer_toc-self.timer_tic))
@@ -153,45 +84,21 @@ def moreData(self):
15384
self.xs[self.i] = self.x
15485
self.ys[self.i] = self.y
15586
self.i += 1
156-
157-
# moreData()
15887

15988
def timerEvent(self, e):
16089
self.moreData()
16190
self.curve.setData(self.xs[:self.i], self.ys[:self.i])
16291
self.plot.replot()
16392

164-
# timerEvent()
165-
166-
# class MapDemo
167-
16893

16994
def make():
17095
demo = MapDemo()
17196
demo.resize(600, 600)
17297
demo.show()
17398
return demo
17499

175-
# make()
176100

177-
178-
def main(args):
179-
app = Qt.QApplication(args)
101+
if __name__ == '__main__':
102+
app = Qt.QApplication(sys.argv)
180103
demo = make()
181104
sys.exit(app.exec_())
182-
183-
# main()
184-
185-
186-
# Admire!
187-
if __name__ == '__main__':
188-
if 'settracemask' in sys.argv:
189-
# for debugging, requires: python configure.py --trace ...
190-
import sip
191-
sip.settracemask(0x3f)
192-
193-
main(sys.argv)
194-
195-
# Local Variables: ***
196-
# mode: python ***
197-
# End: ***

0 commit comments

Comments
 (0)