diff --git a/pyrelacs/ui/mainwindow.py b/pyrelacs/ui/mainwindow.py index 351c7a0..709a06c 100644 --- a/pyrelacs/ui/mainwindow.py +++ b/pyrelacs/ui/mainwindow.py @@ -7,7 +7,10 @@ from PyQt6.QtGui import QAction, QIcon, QKeySequence from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex from PyQt6.QtWidgets import ( QGridLayout, + QPushButton, + QTabWidget, QToolBar, + QVBoxLayout, QWidget, QMainWindow, QPlainTextEdit, @@ -52,6 +55,8 @@ class PyRelacs(QMainWindow): self.mccdaq = MccDaq() end = time.time() log.debug(f"Connection to DAQ took {end - start}") + else: + self.mccdaq = None self.repros = Repro() @@ -60,6 +65,8 @@ class PyRelacs(QMainWindow): ) # Ensure icons are displayed with text self.setWindowTitle("PyRelacs") + self.create_nix_file(f"{_root}/test.nix", self.config.metadata) + self.mutex = QMutex() self.figure = pg.GraphicsLayoutWidget() @@ -73,10 +80,13 @@ class PyRelacs(QMainWindow): self.setStatusBar(QStatusBar(self)) self.create_actions() self.create_toolbars() + self.repro_tabs = QTabWidget() + self.create_repros_tabs() layout = QGridLayout() layout.addWidget(self.figure, 0, 0, 2, 2) - layout.addWidget(self.text, 2, 0, 1, 2) + layout.addWidget(self.repro_tabs, 2, 0, 2, 2) + layout.addWidget(self.text, 4, 0, 1, 1) widget = QWidget() widget.setLayout(layout) @@ -104,14 +114,13 @@ class PyRelacs(QMainWindow): self.continously_plot = Continously(self.figure, self.buffer) # self.continously_plot.plot() - if self.config.settings.daq: + if self.mccdaq: log.debug("Creating Daq Generator") self.daq_producer = DaqProducer(self.buffer, self.mccdaq.daq_device, [1, 1]) log.debug("Creating Sinus Generator") self.sinus_producer = SinProducer(self.buffer) self.nix_writer = NixWriter(self.buffer) - self.create_nix_file(f"{_root}/test.nix", self.config.metadata) def create_actions(self): self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self) @@ -127,7 +136,7 @@ class PyRelacs(QMainWindow): self._daq_connectaction = QAction( QIcon(":icons/connect.png"), "Connect DAQ", self ) - if self.config.settings.daq: + if self.mccdaq: self._daq_connectaction.setStatusTip("Connect to daq device") # self._daq_connectaction.setShortcut(QKeySequence("Alt+d")) self._daq_connectaction.triggered.connect(self.mccdaq.connect_dac) @@ -146,7 +155,7 @@ class PyRelacs(QMainWindow): # # self._daq_calibaction.setShortcut(QKeySequence("Alt+d")) # self._daq_calibaction.triggered.connect(self.calibration_plot.plot) - self._run_action = QAction(QIcon(":/icons/record.png"), "Run", self) + self._run_action = QAction(QIcon(":/icons/record.png"), "RunDAQ", self) self._run_action.triggered.connect(self.run_daq) self._run_sinus_action = QAction(QIcon(":/icons/record.png"), "Sinus", self) @@ -211,18 +220,60 @@ class PyRelacs(QMainWindow): daq_toolbar.addAction(self._record) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar) - repro_toolbar = QToolBar("Repros") + def create_repros_tabs(self): repro_names, file_names = self.repros.names_of_repros( include_repros=self.config.settings.repros ) + nix_blocks = { + rep: self.nix_file.create_block(f"{rep}", "Data Repro") + for rep in repro_names + } + figures_repros = {rep: pg.GraphicsLayoutWidget() for rep in repro_names} for rep, fn in zip(repro_names, file_names): - repro_action = QAction(rep, self) - repro_action.setStatusTip(rep) - repro_action.triggered.connect( - lambda checked, n=rep, f=fn: self.run_repro(n, f) + tab = QWidget() + tab_layout = QGridLayout() + + run_repro_button = QPushButton(f"Run {rep}") + run_repro_button.setCheckable(True) + run_repro_button.clicked.connect( + lambda checked, n=rep, f=fn: self.run_repro( + n, + f, + nix_blocks, + figures_repros, + self.mccdaq, + self.config, + ) ) - repro_toolbar.addAction(repro_action) - self.addToolBar(Qt.ToolBarArea.BottomToolBarArea, repro_toolbar) + tab_layout.addWidget(run_repro_button, 0, 0, 1, 0) + tab_layout.addWidget(figures_repros[rep], 1, 0, 1, 1) + tab.setLayout(tab_layout) + self.repro_tabs.addTab(tab, f"{rep}") + + def run_repro( + self, + name_of_repro: str, + file_of_repro: str, + nix_block, + figures, + *args, + ): + self.text.appendPlainText(f"started Repro {name_of_repro}, {file_of_repro}") + nix_block_repro = nix_block[name_of_repro] + figure_repro = figures[name_of_repro] + worker = Worker( + self.repros.run_repro, + name_of_repro, + file_of_repro, + nix_block_repro, + figure_repro, + *args[-2:], + ) + worker.signals.result.connect(self.print_output) + worker.signals.finished.connect(self.thread_complete) + worker.signals.progress.connect(self.progress_fn) + + self.threadpool.start(worker) def create_nix_file(self, file_path, metadata): self.nix_file = nixio.File.open( @@ -311,17 +362,6 @@ class PyRelacs(QMainWindow): if hasattr(PyRelacs, "daq_device"): log.debug("Stopping DAQ") self.daq_producer.stop_aquisition() - embed() - exit() - - def run_repro(self, n, fn): - self.text.appendPlainText(f"started Repro {n}, {fn}") - worker = Worker(self.repros.run_repro, self.nix_calibration, n, fn) - worker.signals.result.connect(self.print_output) - worker.signals.finished.connect(self.thread_complete) - worker.signals.progress.connect(self.progress_fn) - - self.threadpool.start(worker) def add_to_textfield(self, s: str): self.text.appendPlainText(s) @@ -330,7 +370,7 @@ class PyRelacs(QMainWindow): log.info("exit button!") self.stop_recording() self.add_to_textfield("exiting") - if self.config.settings.daq: + if self.mccdaq: self.mccdaq.disconnect_daq() log.info("closing GUI") self.close()