From b5f8d7663d021b03000d3917e0d189aa3bc3b4ca Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Thu, 10 Oct 2024 14:25:50 +0200 Subject: [PATCH] [ui] updating autorang button --- pyrelacs/ui/mainwindow.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pyrelacs/ui/mainwindow.py b/pyrelacs/ui/mainwindow.py index ebd0589..7f46af9 100644 --- a/pyrelacs/ui/mainwindow.py +++ b/pyrelacs/ui/mainwindow.py @@ -2,7 +2,7 @@ import time from pathlib import Path as path from PyQt6.QtGui import QAction, QIcon, QKeySequence -from PyQt6.QtCore import Qt, QSize, QThreadPool +from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex, QTimer from PyQt6.QtWidgets import ( QGridLayout, QToolBar, @@ -13,6 +13,7 @@ from PyQt6.QtWidgets import ( QStatusBar, ) +from pyqtgraph.Qt.QtCore import QThread import uldaq import nixio as nix import pyqtgraph as pg @@ -44,6 +45,9 @@ class PyRelacs(QMainWindow): Qt.ToolButtonStyle.ToolButtonTextBesideIcon ) # Ensure icons are displayed with text self.setWindowTitle("PyRelacs") + self.mutex = QMutex() + self.timer = QTimer(self) + self.timer.setInterval(200) self.figure = pg.GraphicsLayoutWidget() @@ -80,13 +84,14 @@ class PyRelacs(QMainWindow): end = time.time() log.debug(f"Buffer allocation took {end - start}") - self.buffer = CircBuffer(size=BUFFERSIZE, samplerate=SAMPLERATE) + self.buffer = CircBuffer( + size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex + ) # self.connect_dac() # self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1]) self.sin_producer = SinProducer(self.buffer) self.continously_plot = Continously(self.figure, self.buffer) - self.continously_plot.plot_daq() def create_actions(self): self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self) @@ -129,6 +134,10 @@ class PyRelacs(QMainWindow): self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self) self._stop_recording.triggered.connect(self.stop_recording) + self._refresh = QAction("Refresh", self) + self._refresh.triggered.connect(self.refresh_plot) + self._refresh.setShortcut(QKeySequence("Alt+r")) + self.create_menu() def create_menu(self): @@ -171,6 +180,7 @@ class PyRelacs(QMainWindow): daq_toolbar.addAction(self._run_action) daq_toolbar.addAction(self._run_sinus_action) daq_toolbar.addAction(self._stop_recording) + daq_toolbar.addAction(self._refresh) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar) repro_toolbar = QToolBar("Repros") @@ -184,6 +194,9 @@ class PyRelacs(QMainWindow): repro_toolbar.addAction(repro_action) self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar) + def refresh_plot(self): + self.continously_plot.refresh() + def plot_continously(self): plot_daq = Worker(self.continously_plot.plot_daq) plot_daq.signals.result.connect(self.print_output) @@ -212,13 +225,13 @@ class PyRelacs(QMainWindow): sinus_pro.signals.progress.connect(self.progress_fn) self.threadpool.start(sinus_pro) - # plot_daq = Worker(self.continously_plot.plot_daq) + # plot_daq = Worker(self.continously_plot.plot_daq, self.timer) # plot_daq.signals.result.connect(self.print_output) # plot_daq.signals.finished.connect(self.thread_complete) # plot_daq.signals.progress.connect(self.progress_fn) # self.threadpool.start(plot_daq) - # self.continously_plot.plot_daq() + self.continously_plot.plot_daq() def stop_recording(self): self.add_to_textfield("pressed")