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
2323import pyqtgraph as pg
2424
2525from 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
2727from dvg_pyqt_filelogger import FileLogger
2828from dvg_pyqt_controls import (
2929 create_Toggle_button ,
4848 pg .setConfigOptions (enableExperimental = True )
4949
5050# Global pyqtgraph configuration
51- pg .setConfigOptions (leftButtonPan = False )
51+ # pg.setConfigOptions(leftButtonPan=False)
5252pg .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 ()
0 commit comments