[ui] updating autorang button

This commit is contained in:
wendtalexander 2024-10-10 14:25:50 +02:00
parent fe3e142452
commit b5f8d7663d

View File

@ -2,7 +2,7 @@ import time
from pathlib import Path as path from pathlib import Path as path
from PyQt6.QtGui import QAction, QIcon, QKeySequence 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 ( from PyQt6.QtWidgets import (
QGridLayout, QGridLayout,
QToolBar, QToolBar,
@ -13,6 +13,7 @@ from PyQt6.QtWidgets import (
QStatusBar, QStatusBar,
) )
from pyqtgraph.Qt.QtCore import QThread
import uldaq import uldaq
import nixio as nix import nixio as nix
import pyqtgraph as pg import pyqtgraph as pg
@ -44,6 +45,9 @@ class PyRelacs(QMainWindow):
Qt.ToolButtonStyle.ToolButtonTextBesideIcon Qt.ToolButtonStyle.ToolButtonTextBesideIcon
) # Ensure icons are displayed with text ) # Ensure icons are displayed with text
self.setWindowTitle("PyRelacs") self.setWindowTitle("PyRelacs")
self.mutex = QMutex()
self.timer = QTimer(self)
self.timer.setInterval(200)
self.figure = pg.GraphicsLayoutWidget() self.figure = pg.GraphicsLayoutWidget()
@ -80,13 +84,14 @@ class PyRelacs(QMainWindow):
end = time.time() end = time.time()
log.debug(f"Buffer allocation took {end - start}") 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.connect_dac()
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1]) # self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
self.sin_producer = SinProducer(self.buffer) self.sin_producer = SinProducer(self.buffer)
self.continously_plot = Continously(self.figure, self.buffer) self.continously_plot = Continously(self.figure, self.buffer)
self.continously_plot.plot_daq()
def create_actions(self): def create_actions(self):
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", 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 = QAction(QIcon(":/icons/stop.png"), "Stop", self)
self._stop_recording.triggered.connect(self.stop_recording) 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() self.create_menu()
def create_menu(self): def create_menu(self):
@ -171,6 +180,7 @@ class PyRelacs(QMainWindow):
daq_toolbar.addAction(self._run_action) daq_toolbar.addAction(self._run_action)
daq_toolbar.addAction(self._run_sinus_action) daq_toolbar.addAction(self._run_sinus_action)
daq_toolbar.addAction(self._stop_recording) daq_toolbar.addAction(self._stop_recording)
daq_toolbar.addAction(self._refresh)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
repro_toolbar = QToolBar("Repros") repro_toolbar = QToolBar("Repros")
@ -184,6 +194,9 @@ class PyRelacs(QMainWindow):
repro_toolbar.addAction(repro_action) repro_toolbar.addAction(repro_action)
self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar) self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar)
def refresh_plot(self):
self.continously_plot.refresh()
def plot_continously(self): def plot_continously(self):
plot_daq = Worker(self.continously_plot.plot_daq) plot_daq = Worker(self.continously_plot.plot_daq)
plot_daq.signals.result.connect(self.print_output) plot_daq.signals.result.connect(self.print_output)
@ -212,13 +225,13 @@ class PyRelacs(QMainWindow):
sinus_pro.signals.progress.connect(self.progress_fn) sinus_pro.signals.progress.connect(self.progress_fn)
self.threadpool.start(sinus_pro) 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.result.connect(self.print_output)
# plot_daq.signals.finished.connect(self.thread_complete) # plot_daq.signals.finished.connect(self.thread_complete)
# plot_daq.signals.progress.connect(self.progress_fn) # plot_daq.signals.progress.connect(self.progress_fn)
# self.threadpool.start(plot_daq) # self.threadpool.start(plot_daq)
# self.continously_plot.plot_daq() self.continously_plot.plot_daq()
def stop_recording(self): def stop_recording(self):
self.add_to_textfield("pressed") self.add_to_textfield("pressed")