Skip to content

Commit 6289bc5

Browse files
Bump dependence dvg-pyqtgraph-threadsafe==1.0
1 parent 14f12ab commit 6289bc5

10 files changed

+93
-231
lines changed

DvG_pyqt_ChartHistory.py

Lines changed: 0 additions & 131 deletions
This file was deleted.

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Other depencies you'll need for this demo can be installed by running::
2424
* `dvg-debug-functions <https://pypi.org/project/dvg-debug-functions/>`_
2525
* `dvg-qdeviceio <https://pypi.org/project/dvg-qdeviceio/>`_
2626
* `dvg-devices <https://pypi.org/project/dvg-devices/>`_
27+
* `dvg-pyqtgraph-threadsafe <https://pypi.org/project/dvg-pyqtgraph-threadsafe/>`_
2728
* `psutil <https://pypi.org/project/psutil/>`_
2829
* `pySerial <https://pypi.org/project/pyserial/>`_
2930
* `NumPy <http://www.numpy.org/>`_

demo_A_GUI_full.py

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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__ = "24-07-2020"
10-
__version__ = "5.0"
9+
__date__ = "30-07-2020"
10+
__version__ = "6.0"
1111
# pylint: disable=bare-except, broad-except
1212

1313
import os
@@ -23,11 +23,11 @@
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
2627
from dvg_devices.Arduino_protocol_serial import Arduino
2728
from dvg_qdeviceio import QDeviceIO
2829

2930
from DvG_pyqt_FileLogger import FileLogger
30-
from DvG_pyqt_ChartHistory import ChartHistory
3131
from DvG_pyqt_controls import create_Toggle_button, SS_GROUP
3232

3333
try:
@@ -184,7 +184,7 @@ def __init__(self, parent=None, **kwargs):
184184
# Bottom frame
185185
# -------------------------
186186

187-
# Create PlotItem
187+
# GraphicsWindow
188188
self.gw_chart = pg.GraphicsWindow()
189189
self.gw_chart.setBackground([20, 20, 20])
190190
self.pi_chart = self.gw_chart.addPlot()
@@ -209,10 +209,12 @@ def __init__(self, parent=None, **kwargs):
209209
self.pi_chart.getAxis("left").setStyle(tickTextOffset=20)
210210
self.pi_chart.getAxis("left").setWidth(120)
211211

212-
# Create ChartHistory and PlotDataItem and link them together
213-
PEN_01 = pg.mkPen(color=[255, 255, 90], width=3)
214-
num_samples = round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS)
215-
self.CH_1 = ChartHistory(num_samples, self.pi_chart.plot(pen=PEN_01))
212+
self.history_chart_curve = HistoryChartCurve(
213+
capacity=round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS),
214+
linked_curve=self.pi_chart.plot(
215+
pen=pg.mkPen(color=[255, 255, 90], width=3)
216+
),
217+
)
216218

217219
# 'Readings'
218220
p = {"readOnly": True}
@@ -300,7 +302,7 @@ def process_qpbt_clear_chart(self):
300302
)
301303

302304
if reply == QtWid.QMessageBox.Yes:
303-
self.CH_1.clear()
305+
self.history_chart_curve.clear()
304306

305307
@QtCore.pyqtSlot()
306308
def process_qpbt_record(self):
@@ -309,6 +311,10 @@ def process_qpbt_record(self):
309311
else:
310312
file_logger.stopping = True
311313

314+
@QtCore.pyqtSlot(str)
315+
def set_text_qpbt_record(self, text_str):
316+
self.qpbt_record.setText(text_str)
317+
312318
@QtCore.pyqtSlot()
313319
def process_qpbt_wave_sine(self):
314320
qdev_ard.send(ard.write, "sine")
@@ -321,37 +327,25 @@ def process_qpbt_wave_square(self):
321327
def process_qpbt_wave_sawtooth(self):
322328
qdev_ard.send(ard.write, "sawtooth")
323329

324-
@QtCore.pyqtSlot(str)
325-
def set_text_qpbt_record(self, text_str):
326-
self.qpbt_record.setText(text_str)
327-
328-
329-
# ------------------------------------------------------------------------------
330-
# update_GUI
331-
# ------------------------------------------------------------------------------
332-
333-
334-
@QtCore.pyqtSlot()
335-
def update_GUI():
336-
str_cur_date, str_cur_time, _ = get_current_date_time()
337-
window.qlbl_cur_date_time.setText("%s %s" % (str_cur_date, str_cur_time))
338-
window.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ)
339-
window.qlbl_DAQ_rate.setText("DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz)
340-
window.qlin_reading_t.setText("%.3f" % state.time)
341-
window.qlin_reading_1.setText("%.4f" % state.reading_1)
342-
343-
344-
# ------------------------------------------------------------------------------
345-
# update_chart
346-
# ------------------------------------------------------------------------------
347-
330+
@QtCore.pyqtSlot()
331+
def update_GUI(self):
332+
str_cur_date, str_cur_time, _ = get_current_date_time()
333+
self.qlbl_cur_date_time.setText(
334+
"%s %s" % (str_cur_date, str_cur_time)
335+
)
336+
self.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ)
337+
self.qlbl_DAQ_rate.setText(
338+
"DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz
339+
)
340+
self.qlin_reading_t.setText("%.3f" % state.time)
341+
self.qlin_reading_1.setText("%.4f" % state.reading_1)
348342

349-
@QtCore.pyqtSlot()
350-
def update_chart():
351-
if DEBUG:
352-
tprint("update_curve")
343+
@QtCore.pyqtSlot()
344+
def update_chart(self):
345+
if DEBUG:
346+
tprint("update_curve")
353347

354-
window.CH_1.update_curve()
348+
self.history_chart_curve.update()
355349

356350

357351
# ------------------------------------------------------------------------------
@@ -430,8 +424,8 @@ def DAQ_function():
430424
if use_PC_time:
431425
state.time = time.perf_counter()
432426

433-
# Add readings to chart histories
434-
window.CH_1.add_new_reading(state.time, state.reading_1)
427+
# Add readings to chart history
428+
window.history_chart_curve.append_data(state.time, state.reading_1)
435429

436430
# Logging to file
437431
if file_logger.starting:
@@ -515,14 +509,14 @@ def DAQ_function():
515509
qdev_ard.create_worker_DAQ(
516510
DAQ_function = DAQ_function,
517511
DAQ_interval_ms = DAQ_INTERVAL_MS,
518-
critical_not_alive_count = 3,
512+
critical_not_alive_count = 1,
519513
debug = DEBUG,
520514
)
521515
# fmt: on
522516
qdev_ard.create_worker_jobs(debug=DEBUG)
523517

524518
# Connect signals to slots
525-
qdev_ard.signal_DAQ_updated.connect(update_GUI)
519+
qdev_ard.signal_DAQ_updated.connect(window.update_GUI)
526520
qdev_ard.signal_connection_lost.connect(notify_connection_lost)
527521

528522
# Start workers
@@ -534,7 +528,7 @@ def DAQ_function():
534528

535529
timer_chart = QtCore.QTimer()
536530
# timer_chart.setTimerType(QtCore.Qt.PreciseTimer)
537-
timer_chart.timeout.connect(update_chart)
531+
timer_chart.timeout.connect(window.update_chart)
538532
timer_chart.start(CHART_INTERVAL_MS)
539533

540534
# --------------------------------------------------------------------------

demo_B_GUI_minimal.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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__ = "24-07-2020"
10-
__version__ = "5.0"
9+
__date__ = "30-07-2020"
10+
__version__ = "6.0"
1111
# pylint: disable=bare-except, broad-except
1212

1313
import os
@@ -23,11 +23,10 @@
2323
import pyqtgraph as pg
2424

2525
from dvg_debug_functions import dprint, print_fancy_traceback as pft
26+
from dvg_pyqtgraph_threadsafe import HistoryChartCurve
2627
from dvg_devices.Arduino_protocol_serial import Arduino
2728
from dvg_qdeviceio import QDeviceIO
2829

29-
from DvG_pyqt_ChartHistory import ChartHistory
30-
3130
try:
3231
import OpenGL.GL as gl # pylint: disable=unused-import
3332
except:
@@ -98,7 +97,7 @@ def __init__(self, parent=None, **kwargs):
9897
self.setGeometry(350, 50, 800, 660)
9998
self.setWindowTitle("Arduino & PyQt multithread demo")
10099

101-
# Create PlotItem
100+
# GraphicsWindow
102101
self.gw_chart = pg.GraphicsWindow()
103102
self.gw_chart.setBackground([20, 20, 20])
104103
self.pi_chart = self.gw_chart.addPlot()
@@ -113,10 +112,12 @@ def __init__(self, parent=None, **kwargs):
113112
disableAutoRange=True,
114113
)
115114

116-
# Create ChartHistory and PlotDataItem and link them together
117-
PEN_01 = pg.mkPen(color=[255, 255, 90], width=3)
118-
num_samples = round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS)
119-
self.CH_1 = ChartHistory(num_samples, self.pi_chart.plot(pen=PEN_01))
115+
self.history_chart_curve = HistoryChartCurve(
116+
capacity=round(CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS),
117+
linked_curve=self.pi_chart.plot(
118+
pen=pg.mkPen(color=[255, 255, 90], width=3)
119+
),
120+
)
120121

121122
vbox = QtWid.QVBoxLayout(self)
122123
vbox.addWidget(self.gw_chart, 1)
@@ -175,8 +176,8 @@ def DAQ_function():
175176
if use_PC_time:
176177
state.time = time.perf_counter()
177178

178-
# Add readings to chart histories
179-
window.CH_1.add_new_reading(state.time, state.reading_1)
179+
# Add readings to chart history
180+
window.history_chart_curve.append_data(state.time, state.reading_1)
180181

181182
return True
182183

@@ -234,7 +235,7 @@ def DAQ_function():
234235
qdev_ard.create_worker_DAQ(
235236
DAQ_function = DAQ_function,
236237
DAQ_interval_ms = DAQ_INTERVAL_MS,
237-
critical_not_alive_count = 3,
238+
critical_not_alive_count = 1,
238239
debug = DEBUG,
239240
)
240241
# fmt: on
@@ -247,7 +248,7 @@ def DAQ_function():
247248
# --------------------------------------------------------------------------
248249

249250
timer_chart = QtCore.QTimer()
250-
timer_chart.timeout.connect(window.CH_1.update_curve)
251+
timer_chart.timeout.connect(window.history_chart_curve.update)
251252
timer_chart.start(CHART_INTERVAL_MS)
252253

253254
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)