Skip to content

Commit 2488fa4

Browse files
Update dependence dvg-pyqtgraph-threadsafe==3.0.0
1 parent 0f880b8 commit 2488fa4

File tree

5 files changed

+118
-88
lines changed

5 files changed

+118
-88
lines changed

demo_A_GUI_full.py

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = "Dennis van Gils"
77
__authoremail__ = "vangils.dennis@gmail.com"
88
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo"
9-
__date__ = "05-08-2020"
9+
__date__ = "07-08-2020"
1010
__version__ = "7.0"
1111
# pylint: disable=bare-except, broad-except, unnecessary-lambda
1212

@@ -23,7 +23,7 @@
2323
import pyqtgraph as pg
2424

2525
from dvg_debug_functions import tprint, dprint, print_fancy_traceback as pft
26-
from dvg_pyqtgraph_threadsafe import HistoryChartCurve
26+
from dvg_pyqtgraph_threadsafe import HistoryChartCurve, PlotManager
2727
from dvg_pyqt_filelogger import FileLogger
2828
from dvg_pyqt_controls import (
2929
create_Toggle_button,
@@ -48,7 +48,7 @@
4848
pg.setConfigOptions(enableExperimental=True)
4949

5050
# Global pyqtgraph configuration
51-
pg.setConfigOptions(leftButtonPan=False)
51+
# pg.setConfigOptions(leftButtonPan=False)
5252
pg.setConfigOption("foreground", "#EEE")
5353

5454
# Constants
@@ -116,7 +116,7 @@ def __init__(self, parent=None, **kwargs):
116116
if USE_LARGER_TEXT:
117117
self.setGeometry(50, 50, 1024, 768)
118118
else:
119-
self.setGeometry(350, 50, 800, 660)
119+
self.setGeometry(350, 50, 960, 660)
120120

121121
# -------------------------
122122
# Top frame
@@ -178,17 +178,18 @@ def __init__(self, parent=None, **kwargs):
178178
# -------------------------
179179

180180
# GraphicsLayoutWidget
181-
self.gw_chart = pg.GraphicsLayoutWidget()
182-
self.pi_chart = self.gw_chart.addPlot()
181+
self.gw = pg.GraphicsLayoutWidget()
182+
self.plot = self.gw.addPlot()
183183

184184
p = {
185185
"color": "#EEE",
186186
"font-size": "20pt" if USE_LARGER_TEXT else "10pt",
187187
}
188-
self.pi_chart.showGrid(x=1, y=1)
189-
self.pi_chart.setLabel("bottom", text="history (sec)", **p)
190-
self.pi_chart.setLabel("left", text="amplitude", **p)
191-
self.pi_chart.setRange(
188+
self.plot.setClipToView(True)
189+
self.plot.showGrid(x=1, y=1)
190+
self.plot.setLabel("bottom", text="history (sec)", **p)
191+
self.plot.setLabel("left", text="amplitude", **p)
192+
self.plot.setRange(
192193
xRange=[-1.04 * CHART_HISTORY_TIME, CHART_HISTORY_TIME * 0.04],
193194
yRange=[-1.1, 1.1],
194195
disableAutoRange=True,
@@ -197,16 +198,16 @@ def __init__(self, parent=None, **kwargs):
197198
if USE_LARGER_TEXT:
198199
font = QtGui.QFont()
199200
font.setPixelSize(26)
200-
self.pi_chart.getAxis("bottom").setTickFont(font)
201-
self.pi_chart.getAxis("bottom").setStyle(tickTextOffset=20)
202-
self.pi_chart.getAxis("bottom").setHeight(90)
203-
self.pi_chart.getAxis("left").setTickFont(font)
204-
self.pi_chart.getAxis("left").setStyle(tickTextOffset=20)
205-
self.pi_chart.getAxis("left").setWidth(120)
201+
self.plot.getAxis("bottom").setTickFont(font)
202+
self.plot.getAxis("bottom").setStyle(tickTextOffset=20)
203+
self.plot.getAxis("bottom").setHeight(90)
204+
self.plot.getAxis("left").setTickFont(font)
205+
self.plot.getAxis("left").setStyle(tickTextOffset=20)
206+
self.plot.getAxis("left").setWidth(120)
206207

207208
self.history_chart_curve = HistoryChartCurve(
208209
capacity=round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS),
209-
linked_curve=self.pi_chart.plot(
210+
linked_curve=self.plot.plot(
210211
pen=pg.mkPen(color=[255, 255, 0], width=3)
211212
),
212213
)
@@ -255,15 +256,39 @@ def __init__(self, parent=None, **kwargs):
255256
qgrp_wave_type.setLayout(grid)
256257

257258
# 'Chart'
258-
self.qpbt_clear_chart = QtWid.QPushButton("Clear")
259-
self.qpbt_clear_chart.clicked.connect(self.process_qpbt_clear_chart)
260-
261-
grid = QtWid.QGridLayout()
262-
grid.addWidget(self.qpbt_clear_chart, 0, 0)
263-
grid.setAlignment(QtCore.Qt.AlignTop)
259+
self.plot_manager = PlotManager(parent=self)
260+
self.plot_manager.add_autorange_buttons(linked_plots=self.plot)
261+
self.plot_manager.add_preset_buttons(
262+
linked_plots=self.plot,
263+
linked_curves=self.history_chart_curve,
264+
presets=[
265+
{
266+
"button_label": "0.100",
267+
"x_axis_label": "history (msec)",
268+
"x_axis_divisor": 1e-3,
269+
"x_axis_range": (-101, 0),
270+
},
271+
{
272+
"button_label": "0:05",
273+
"x_axis_label": "history (sec)",
274+
"x_axis_divisor": 1,
275+
"x_axis_range": (-5.05, 0),
276+
},
277+
{
278+
"button_label": "0:10",
279+
"x_axis_label": "history (sec)",
280+
"x_axis_divisor": 1,
281+
"x_axis_range": (-10.1, 0),
282+
},
283+
],
284+
)
285+
self.plot_manager.add_clear_button(
286+
linked_curves=self.history_chart_curve
287+
)
288+
self.plot_manager.perform_preset(1)
264289

265290
qgrp_chart = QtWid.QGroupBox("Chart")
266-
qgrp_chart.setLayout(grid)
291+
qgrp_chart.setLayout(self.plot_manager.grid)
267292

268293
vbox = QtWid.QVBoxLayout()
269294
vbox.addWidget(qgrp_readings)
@@ -273,7 +298,7 @@ def __init__(self, parent=None, **kwargs):
273298

274299
# Round up bottom frame
275300
hbox_bot = QtWid.QHBoxLayout()
276-
hbox_bot.addWidget(self.gw_chart, 1)
301+
hbox_bot.addWidget(self.gw, 1)
277302
hbox_bot.addLayout(vbox, 0)
278303

279304
# -------------------------
@@ -289,20 +314,6 @@ def __init__(self, parent=None, **kwargs):
289314
# Handle controls
290315
# --------------------------------------------------------------------------
291316

292-
@QtCore.pyqtSlot()
293-
def process_qpbt_clear_chart(self):
294-
str_msg = "Are you sure you want to clear the chart?"
295-
reply = QtWid.QMessageBox.warning(
296-
window,
297-
"Clear chart",
298-
str_msg,
299-
QtWid.QMessageBox.Yes | QtWid.QMessageBox.No,
300-
QtWid.QMessageBox.No,
301-
)
302-
303-
if reply == QtWid.QMessageBox.Yes:
304-
self.history_chart_curve.clear()
305-
306317
@QtCore.pyqtSlot()
307318
def process_qpbt_wave_sine(self):
308319
qdev_ard.send(ard.write, "sine")
@@ -532,7 +543,7 @@ def start_stop():
532543
qdev_ard.start(DAQ_priority=QtCore.QThread.TimeCriticalPriority)
533544

534545
# --------------------------------------------------------------------------
535-
# Create chart refresh timer
546+
# Create plot refresh timer
536547
# --------------------------------------------------------------------------
537548

538549
timer_chart = QtCore.QTimer()

demo_B_GUI_minimal.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = "Dennis van Gils"
77
__authoremail__ = "vangils.dennis@gmail.com"
88
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo"
9-
__date__ = "05-08-2020"
9+
__date__ = "07-08-2020"
1010
__version__ = "7.0"
1111
# pylint: disable=bare-except, broad-except
1212

@@ -40,7 +40,7 @@
4040
pg.setConfigOptions(enableExperimental=True)
4141

4242
# Global pyqtgraph configuration
43-
pg.setConfigOptions(leftButtonPan=False)
43+
# pg.setConfigOptions(leftButtonPan=False)
4444
pg.setConfigOption("foreground", "#EEE")
4545

4646
# Constants
@@ -99,28 +99,29 @@ def __init__(self, parent=None, **kwargs):
9999
self.setGeometry(350, 50, 800, 660)
100100

101101
# GraphicsLayoutWidget
102-
self.gw_chart = pg.GraphicsLayoutWidget()
103-
self.pi_chart = self.gw_chart.addPlot()
102+
self.gw = pg.GraphicsLayoutWidget()
103+
self.plot = self.gw.addPlot()
104104

105105
p = {"color": "#EEE", "font-size": "10pt"}
106-
self.pi_chart.showGrid(x=1, y=1)
107-
self.pi_chart.setLabel("bottom", text="history (sec)", **p)
108-
self.pi_chart.setLabel("left", text="amplitude", **p)
109-
self.pi_chart.setRange(
106+
self.plot.setClipToView(True)
107+
self.plot.showGrid(x=1, y=1)
108+
self.plot.setLabel("bottom", text="history (sec)", **p)
109+
self.plot.setLabel("left", text="amplitude", **p)
110+
self.plot.setRange(
110111
xRange=[-1.04 * CHART_HISTORY_TIME, CHART_HISTORY_TIME * 0.04],
111112
yRange=[-1.1, 1.1],
112113
disableAutoRange=True,
113114
)
114115

115116
self.history_chart_curve = HistoryChartCurve(
116117
capacity=round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS),
117-
linked_curve=self.pi_chart.plot(
118+
linked_curve=self.plot.plot(
118119
pen=pg.mkPen(color=[255, 255, 0], width=3)
119120
),
120121
)
121122

122123
vbox = QtWid.QVBoxLayout(self)
123-
vbox.addWidget(self.gw_chart, 1)
124+
vbox.addWidget(self.gw, 1)
124125

125126

126127
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)