[ui/mainwindow] organising file
This commit is contained in:
parent
85b5a71ccb
commit
9fd4892325
@ -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, QMutex, QTimer
|
||||
from PyQt6.QtCore import Qt, QSize, QThreadPool, QMutex
|
||||
from PyQt6.QtWidgets import (
|
||||
QGridLayout,
|
||||
QToolBar,
|
||||
@ -16,16 +16,17 @@ from PyQt6.QtWidgets import (
|
||||
import uldaq
|
||||
import nixio as nix
|
||||
import pyqtgraph as pg
|
||||
import numpy as np
|
||||
import quantities as pq
|
||||
|
||||
from pyrelacs.devices.mccdaq import MccDaq
|
||||
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
from pyrelacs.dataio.daq_producer import DaqProducer
|
||||
from pyrelacs.dataio.nix_writer import NixWriter
|
||||
from pyrelacs.dataio.sin_producer import SinProducer
|
||||
|
||||
from pyrelacs.worker import Worker
|
||||
from pyrelacs.repros.repros import Repro
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
|
||||
from pyrelacs.ui.about import AboutDialog
|
||||
from pyrelacs.ui.plots.calibration import CalibrationPlot
|
||||
@ -42,28 +43,26 @@ from IPython import embed
|
||||
class PyRelacs(QMainWindow):
|
||||
def __init__(self, config):
|
||||
super().__init__()
|
||||
# loaded config
|
||||
self.config = config
|
||||
if self.config.settings.daq:
|
||||
start = time.time()
|
||||
self.mccdaq = MccDaq()
|
||||
end = time.time()
|
||||
log.debug(f"Connection to DAQ took {end - start}")
|
||||
|
||||
self.repros = Repro()
|
||||
|
||||
self.setToolButtonStyle(
|
||||
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()
|
||||
|
||||
# filename = path.joinpath(path.cwd(), "data.nix")
|
||||
# if filename.exists():
|
||||
# self.nix_file = nix.File.open(str(filename), nix.FileMode.ReadOnly)
|
||||
# filename = path.joinpath(path.cwd(), "calibration.nix")
|
||||
# self.nix_file = nix.File.open(str(filename), nix.FileMode.Overwrite)
|
||||
#
|
||||
# self.calibration_plot = CalibrationPlot(self.figure, self.nix_file)
|
||||
# self.nix_file.close()
|
||||
|
||||
self.threadpool = QThreadPool()
|
||||
self.repros = Repro()
|
||||
|
||||
self.text = QPlainTextEdit()
|
||||
self.text.setReadOnly(True)
|
||||
@ -84,31 +83,29 @@ class PyRelacs(QMainWindow):
|
||||
SAMPLERATE = pq.Quantity(
|
||||
self.config.pyrelacs.data.input.inputsamplerate,
|
||||
self.config.pyrelacs.data.input.inputsamplerateunit,
|
||||
)
|
||||
).rescale("Hz")
|
||||
|
||||
INPUTTRACECAPACITY = pq.Quantity(
|
||||
self.config.pyrelacs.data.input.inputtracecapacity,
|
||||
self.config.pyrelacs.data.input.inputtracecapacityunit,
|
||||
)
|
||||
).rescale("s")
|
||||
start = time.time()
|
||||
BUFFERSIZE = (SAMPLERATE * INPUTTRACECAPACITY).simplified
|
||||
end = time.time()
|
||||
log.debug(f"Buffer allocation took {end - start}")
|
||||
|
||||
self.buffer = CircBuffer(
|
||||
size=BUFFERSIZE, samplerate=SAMPLERATE, mutex=self.mutex
|
||||
size=int(BUFFERSIZE.base),
|
||||
samplerate=float(SAMPLERATE.base),
|
||||
mutex=self.mutex,
|
||||
)
|
||||
self.continously_plot = Continously(self.figure, self.buffer)
|
||||
self.continously_plot.plot()
|
||||
|
||||
start = time.time()
|
||||
self.connect_dac()
|
||||
end = time.time()
|
||||
log.debug(f"Connection to DAQ took {end - start}")
|
||||
|
||||
if hasattr(PyRelacs, "daq_device"):
|
||||
if self.config.settings.daq:
|
||||
log.debug("Creating Daq Generator")
|
||||
self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
else:
|
||||
self.daq_producer = DaqProducer(self.buffer, self.mccdaq.daq_device, [1, 1])
|
||||
|
||||
log.debug("Creating Sinus Generator")
|
||||
self.sinus_producer = SinProducer(self.buffer)
|
||||
|
||||
@ -128,16 +125,17 @@ class PyRelacs(QMainWindow):
|
||||
self._daq_connectaction = QAction(
|
||||
QIcon(":icons/connect.png"), "Connect DAQ", self
|
||||
)
|
||||
if self.config.settings.daq:
|
||||
self._daq_connectaction.setStatusTip("Connect to daq device")
|
||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_connectaction.triggered.connect(self.connect_dac)
|
||||
self._daq_connectaction.triggered.connect(self.mccdaq.connect_dac)
|
||||
|
||||
self._daq_disconnectaction = QAction(
|
||||
QIcon(":/icons/disconnect.png"), "Disconnect DAQ", self
|
||||
)
|
||||
self._daq_disconnectaction.setStatusTip("Disconnect the DAQ device")
|
||||
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
|
||||
self._daq_disconnectaction.triggered.connect(self.disconnect_dac)
|
||||
self._daq_disconnectaction.triggered.connect(self.mccdaq.disconnect_daq)
|
||||
|
||||
# self._daq_calibaction = QAction(
|
||||
# QIcon(":/icons/calibration.png"), "Plot calibration", self
|
||||
@ -176,6 +174,7 @@ class PyRelacs(QMainWindow):
|
||||
file_menu.addAction(self._rlx_aboutaction)
|
||||
|
||||
if device_menu is not None:
|
||||
if self.config.settings.daq:
|
||||
device_menu.addAction(self._daq_connectaction)
|
||||
device_menu.addAction(self._daq_disconnectaction)
|
||||
device_menu.addSeparator()
|
||||
@ -198,6 +197,7 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, rlx_toolbar)
|
||||
daq_toolbar = QToolBar("DAQ")
|
||||
if self.config.settings.daq:
|
||||
daq_toolbar.addAction(self._daq_connectaction)
|
||||
daq_toolbar.addAction(self._daq_disconnectaction)
|
||||
# daq_toolbar.addAction(self._daq_calibaction)
|
||||
@ -210,7 +210,9 @@ class PyRelacs(QMainWindow):
|
||||
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
|
||||
|
||||
repro_toolbar = QToolBar("Repros")
|
||||
repro_names, file_names = self.repros.names_of_repros()
|
||||
repro_names, file_names = self.repros.names_of_repros(
|
||||
include_repros=self.config.settings.repros
|
||||
)
|
||||
for rep, fn in zip(repro_names, file_names):
|
||||
repro_action = QAction(rep, self)
|
||||
repro_action.setStatusTip(rep)
|
||||
@ -271,24 +273,6 @@ class PyRelacs(QMainWindow):
|
||||
log.debug("Stopping DAQ")
|
||||
self.daq_producer.stop_aquisition()
|
||||
|
||||
def connect_dac(self):
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
try:
|
||||
self.daq_device = uldaq.DaqDevice(devices[0])
|
||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||
self.daq_device.connect()
|
||||
log.debug("connected")
|
||||
except IndexError:
|
||||
log.info("DAQ is not connected")
|
||||
log.info("Please connect a DAQ device to the system")
|
||||
|
||||
def disconnect_dac(self):
|
||||
try:
|
||||
self.daq_device.disconnect()
|
||||
self.daq_device.release()
|
||||
except AttributeError:
|
||||
log.debug("DAQ was not connected")
|
||||
|
||||
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)
|
||||
@ -305,7 +289,8 @@ class PyRelacs(QMainWindow):
|
||||
log.info("exit button!")
|
||||
self.stop_recording()
|
||||
self.add_to_textfield("exiting")
|
||||
self.disconnect_dac()
|
||||
if self.config.settings.daq:
|
||||
self.mccdaq.disconnect_daq()
|
||||
log.info("closing GUI")
|
||||
self.close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user