Skip to content

Commit af7aad8

Browse files
committed
Improved curve benchmark test + added curve styles test
1 parent 5402648 commit af7aad8

File tree

3 files changed

+106
-18
lines changed

3 files changed

+106
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.spyderproject
2+
qwt-6.1.2
23

34
# Created by https://www.gitignore.io/api/python
45

qwt/tests/curve_benchmark.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,22 @@ def __init__(self, title, xdata, ydata, style, symbol=None, *args):
5050

5151

5252
class BMWidget(QWidget):
53-
def __init__(self, points, parent=None):
54-
super(BMWidget, self).__init__(parent)
55-
layout = QGridLayout()
53+
def __init__(self, points, *args):
54+
super(BMWidget, self).__init__()
55+
self.setup(points, *args)
56+
57+
def params(self, *args):
58+
return (
59+
('Lines', None),
60+
('Dots', None),
61+
)
62+
63+
def setup(self, points, *args):
5664
x = np.linspace(.001, 20., points)
5765
y = (np.sin(x)/x)*np.cos(20*x)
58-
symb1 = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow),
59-
QPen(Qt.blue), QSize(5, 5))
60-
symb2 = QwtSymbol(QwtSymbol.XCross, QBrush(),
61-
QPen(Qt.darkMagenta), QSize(5, 5))
66+
layout = QGridLayout()
6267
nbcol, col, row = 2, 0, 0
63-
# for style, symbol in (('Lines', None),
64-
# ('Lines', None),
65-
# ('Lines', None),
66-
# ('Lines', None)):
67-
for style, symbol in (('Sticks', symb1),
68-
('Lines', None),
69-
('Steps', None),
70-
('NoCurve', symb2)):
68+
for style, symbol in self.params(*args):
7169
layout.addWidget(BMPlot(style, x, y, getattr(QwtPlotCurve, style),
7270
symbol=symbol), row, col)
7371
col += 1
@@ -103,17 +101,24 @@ def __init__(self, max_n, parent=None, **kwargs):
103101
self.setCentralWidget(tabs)
104102
contents = BMText()
105103
tabs.addTab(contents, 'Contents')
106-
self.resize(1000, 800)
104+
self.resize(1000, 600)
105+
106+
# Force window to show up and refresh (for test purpose only)
107107
self.show()
108+
QApplication.processEvents()
109+
108110
t0g = time.time()
109-
for idx in range(3, -1, -1):
111+
for idx in range(4, -1, -1):
110112
points = max_n/10**idx
111113
t0 = time.time()
112114
widget = BMWidget(points)
113115
title = '%d points' % points
114116
tabs.addTab(widget, title)
115117
tabs.setCurrentWidget(widget)
118+
119+
# Force widget to refresh (for test purpose only)
116120
QApplication.processEvents()
121+
117122
time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000)
118123
widget.text.setText(time_str)
119124
contents.append("<br><i>%s:</i><br>%s" % (title, time_str))
@@ -128,5 +133,5 @@ def __init__(self, max_n, parent=None, **kwargs):
128133
if name in QFontDatabase().families():
129134
app.setFont(QFont(name))
130135
break
131-
demo = BMDemo(100000)
136+
demo = BMDemo(1000000)
132137
app.exec_()

qwt/tests/curve_styles.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the MIT License
4+
# Copyright (c) 2015 Pierre Raybaut
5+
# (see LICENSE file for more details)
6+
7+
"""Curve styles"""
8+
9+
SHOW = True # Show test in GUI-based test launcher
10+
11+
import time
12+
13+
from qwt.qt.QtGui import (QApplication, QPen, QBrush, QMainWindow, QTabWidget,
14+
QFont, QFontDatabase)
15+
from qwt.qt.QtCore import QSize
16+
from qwt.qt.QtCore import Qt
17+
18+
from qwt.tests import curve_benchmark as cb
19+
from qwt import QwtSymbol
20+
21+
22+
class CSWidget(cb.BMWidget):
23+
def params(self, *args):
24+
symbols, = args
25+
symb1 = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow),
26+
QPen(Qt.blue), QSize(5, 5))
27+
symb2 = QwtSymbol(QwtSymbol.XCross, QBrush(),
28+
QPen(Qt.darkMagenta), QSize(5, 5))
29+
if symbols:
30+
return (
31+
('Sticks', symb1),
32+
('Lines', symb1),
33+
('Steps', symb2),
34+
('Dots', symb2),
35+
)
36+
else:
37+
return (
38+
('Sticks', None),
39+
('Lines', None),
40+
('Steps', None),
41+
('Dots', None),
42+
)
43+
44+
45+
class BMDemo(QMainWindow):
46+
def __init__(self, max_n, parent=None, **kwargs):
47+
super(BMDemo, self).__init__(parent=parent)
48+
self.setWindowTitle('Curve styles')
49+
tabs = QTabWidget()
50+
self.resize(1000, 800)
51+
52+
# Force window to show up and refresh (for test purpose only)
53+
self.show()
54+
QApplication.processEvents()
55+
56+
self.setCentralWidget(tabs)
57+
pts = 1000
58+
for points, symbols in zip((pts/10, pts/10, pts, pts),
59+
(True, False)*2):
60+
t0 = time.time()
61+
widget = CSWidget(points, symbols)
62+
symtext = "with%s symbols" % ("" if symbols else "out")
63+
title = '%d points, %s' % (points, symtext)
64+
tabs.addTab(widget, title)
65+
tabs.setCurrentWidget(widget)
66+
67+
# Force widget to refresh (for test purpose only)
68+
QApplication.processEvents()
69+
70+
time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000)
71+
widget.text.setText(time_str)
72+
tabs.setCurrentIndex(0)
73+
74+
75+
if __name__ == '__main__':
76+
app = QApplication([])
77+
for name in ('Calibri', 'Verdana', 'Arial'):
78+
if name in QFontDatabase().families():
79+
app.setFont(QFont(name))
80+
break
81+
demo = BMDemo(100000)
82+
app.exec_()

0 commit comments

Comments
 (0)