Skip to content

Commit

Permalink
Bump dependence dvg-pyqtgraph-threadsafe==1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis-van-Gils committed Jul 30, 2020
1 parent 14f12ab commit 6289bc5
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 231 deletions.
131 changes: 0 additions & 131 deletions DvG_pyqt_ChartHistory.py

This file was deleted.

1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Other depencies you'll need for this demo can be installed by running::
* `dvg-debug-functions <https://pypi.org/project/dvg-debug-functions/>`_
* `dvg-qdeviceio <https://pypi.org/project/dvg-qdeviceio/>`_
* `dvg-devices <https://pypi.org/project/dvg-devices/>`_
* `dvg-pyqtgraph-threadsafe <https://pypi.org/project/dvg-pyqtgraph-threadsafe/>`_
* `psutil <https://pypi.org/project/psutil/>`_
* `pySerial <https://pypi.org/project/pyserial/>`_
* `NumPy <http://www.numpy.org/>`_
Expand Down
80 changes: 37 additions & 43 deletions demo_A_GUI_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
__author__ = "Dennis van Gils"
__authoremail__ = "vangils.dennis@gmail.com"
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo"
__date__ = "24-07-2020"
__version__ = "5.0"
__date__ = "30-07-2020"
__version__ = "6.0"
# pylint: disable=bare-except, broad-except

import os
Expand All @@ -23,11 +23,11 @@
import pyqtgraph as pg

from dvg_debug_functions import tprint, dprint, print_fancy_traceback as pft
from dvg_pyqtgraph_threadsafe import HistoryChartCurve
from dvg_devices.Arduino_protocol_serial import Arduino
from dvg_qdeviceio import QDeviceIO

from DvG_pyqt_FileLogger import FileLogger
from DvG_pyqt_ChartHistory import ChartHistory
from DvG_pyqt_controls import create_Toggle_button, SS_GROUP

try:
Expand Down Expand Up @@ -184,7 +184,7 @@ def __init__(self, parent=None, **kwargs):
# Bottom frame
# -------------------------

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

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

# 'Readings'
p = {"readOnly": True}
Expand Down Expand Up @@ -300,7 +302,7 @@ def process_qpbt_clear_chart(self):
)

if reply == QtWid.QMessageBox.Yes:
self.CH_1.clear()
self.history_chart_curve.clear()

@QtCore.pyqtSlot()
def process_qpbt_record(self):
Expand All @@ -309,6 +311,10 @@ def process_qpbt_record(self):
else:
file_logger.stopping = True

@QtCore.pyqtSlot(str)
def set_text_qpbt_record(self, text_str):
self.qpbt_record.setText(text_str)

@QtCore.pyqtSlot()
def process_qpbt_wave_sine(self):
qdev_ard.send(ard.write, "sine")
Expand All @@ -321,37 +327,25 @@ def process_qpbt_wave_square(self):
def process_qpbt_wave_sawtooth(self):
qdev_ard.send(ard.write, "sawtooth")

@QtCore.pyqtSlot(str)
def set_text_qpbt_record(self, text_str):
self.qpbt_record.setText(text_str)


# ------------------------------------------------------------------------------
# update_GUI
# ------------------------------------------------------------------------------


@QtCore.pyqtSlot()
def update_GUI():
str_cur_date, str_cur_time, _ = get_current_date_time()
window.qlbl_cur_date_time.setText("%s %s" % (str_cur_date, str_cur_time))
window.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ)
window.qlbl_DAQ_rate.setText("DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz)
window.qlin_reading_t.setText("%.3f" % state.time)
window.qlin_reading_1.setText("%.4f" % state.reading_1)


# ------------------------------------------------------------------------------
# update_chart
# ------------------------------------------------------------------------------

@QtCore.pyqtSlot()
def update_GUI(self):
str_cur_date, str_cur_time, _ = get_current_date_time()
self.qlbl_cur_date_time.setText(
"%s %s" % (str_cur_date, str_cur_time)
)
self.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ)
self.qlbl_DAQ_rate.setText(
"DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz
)
self.qlin_reading_t.setText("%.3f" % state.time)
self.qlin_reading_1.setText("%.4f" % state.reading_1)

@QtCore.pyqtSlot()
def update_chart():
if DEBUG:
tprint("update_curve")
@QtCore.pyqtSlot()
def update_chart(self):
if DEBUG:
tprint("update_curve")

window.CH_1.update_curve()
self.history_chart_curve.update()


# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -430,8 +424,8 @@ def DAQ_function():
if use_PC_time:
state.time = time.perf_counter()

# Add readings to chart histories
window.CH_1.add_new_reading(state.time, state.reading_1)
# Add readings to chart history
window.history_chart_curve.append_data(state.time, state.reading_1)

# Logging to file
if file_logger.starting:
Expand Down Expand Up @@ -515,14 +509,14 @@ def DAQ_function():
qdev_ard.create_worker_DAQ(
DAQ_function = DAQ_function,
DAQ_interval_ms = DAQ_INTERVAL_MS,
critical_not_alive_count = 3,
critical_not_alive_count = 1,
debug = DEBUG,
)
# fmt: on
qdev_ard.create_worker_jobs(debug=DEBUG)

# Connect signals to slots
qdev_ard.signal_DAQ_updated.connect(update_GUI)
qdev_ard.signal_DAQ_updated.connect(window.update_GUI)
qdev_ard.signal_connection_lost.connect(notify_connection_lost)

# Start workers
Expand All @@ -534,7 +528,7 @@ def DAQ_function():

timer_chart = QtCore.QTimer()
# timer_chart.setTimerType(QtCore.Qt.PreciseTimer)
timer_chart.timeout.connect(update_chart)
timer_chart.timeout.connect(window.update_chart)
timer_chart.start(CHART_INTERVAL_MS)

# --------------------------------------------------------------------------
Expand Down
27 changes: 14 additions & 13 deletions demo_B_GUI_minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
__author__ = "Dennis van Gils"
__authoremail__ = "vangils.dennis@gmail.com"
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo"
__date__ = "24-07-2020"
__version__ = "5.0"
__date__ = "30-07-2020"
__version__ = "6.0"
# pylint: disable=bare-except, broad-except

import os
Expand All @@ -23,11 +23,10 @@
import pyqtgraph as pg

from dvg_debug_functions import dprint, print_fancy_traceback as pft
from dvg_pyqtgraph_threadsafe import HistoryChartCurve
from dvg_devices.Arduino_protocol_serial import Arduino
from dvg_qdeviceio import QDeviceIO

from DvG_pyqt_ChartHistory import ChartHistory

try:
import OpenGL.GL as gl # pylint: disable=unused-import
except:
Expand Down Expand Up @@ -98,7 +97,7 @@ def __init__(self, parent=None, **kwargs):
self.setGeometry(350, 50, 800, 660)
self.setWindowTitle("Arduino & PyQt multithread demo")

# Create PlotItem
# GraphicsWindow
self.gw_chart = pg.GraphicsWindow()
self.gw_chart.setBackground([20, 20, 20])
self.pi_chart = self.gw_chart.addPlot()
Expand All @@ -113,10 +112,12 @@ def __init__(self, parent=None, **kwargs):
disableAutoRange=True,
)

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

vbox = QtWid.QVBoxLayout(self)
vbox.addWidget(self.gw_chart, 1)
Expand Down Expand Up @@ -175,8 +176,8 @@ def DAQ_function():
if use_PC_time:
state.time = time.perf_counter()

# Add readings to chart histories
window.CH_1.add_new_reading(state.time, state.reading_1)
# Add readings to chart history
window.history_chart_curve.append_data(state.time, state.reading_1)

return True

Expand Down Expand Up @@ -234,7 +235,7 @@ def DAQ_function():
qdev_ard.create_worker_DAQ(
DAQ_function = DAQ_function,
DAQ_interval_ms = DAQ_INTERVAL_MS,
critical_not_alive_count = 3,
critical_not_alive_count = 1,
debug = DEBUG,
)
# fmt: on
Expand All @@ -247,7 +248,7 @@ def DAQ_function():
# --------------------------------------------------------------------------

timer_chart = QtCore.QTimer()
timer_chart.timeout.connect(window.CH_1.update_curve)
timer_chart.timeout.connect(window.history_chart_curve.update)
timer_chart.start(CHART_INTERVAL_MS)

# --------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6289bc5

Please sign in to comment.