forked from awendt/pyrelacs
129 lines
4.0 KiB
Python
129 lines
4.0 KiB
Python
from PyQt6.QtGui import QAction
|
|
import sys
|
|
import pathlib
|
|
|
|
from PyQt6.QtCore import QProcess, QSize, QThreadPool, Qt, QSettings
|
|
from PyQt6.QtWidgets import (
|
|
QApplication,
|
|
QGridLayout,
|
|
QPushButton,
|
|
QToolBar,
|
|
QWidget,
|
|
QMainWindow,
|
|
QPlainTextEdit,
|
|
)
|
|
import uldaq
|
|
from IPython import embed
|
|
import numpy as np
|
|
|
|
from pyrelacs.util.logging import config_logging
|
|
import pyrelacs.info as info
|
|
from pyrelacs.worker import Worker
|
|
from pyrelacs.repros.repros import Repro
|
|
|
|
log = config_logging()
|
|
|
|
|
|
class PyRelacs(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("PyRelacs")
|
|
self.setMinimumSize(1000, 1000)
|
|
|
|
self.threadpool = QThreadPool()
|
|
self.repros = Repro()
|
|
|
|
self.daq_connect_button = QPushButton("Connect Daq")
|
|
self.daq_connect_button.setCheckable(True)
|
|
self.daq_connect_button.clicked.connect(self.connect_dac)
|
|
|
|
self.daq_disconnect_button = QPushButton("Disconnect Daq")
|
|
self.daq_disconnect_button.setCheckable(True)
|
|
self.daq_disconnect_button.clicked.connect(self.disconnect_dac)
|
|
|
|
self.text = QPlainTextEdit()
|
|
self.text.setReadOnly(True)
|
|
|
|
layout = QGridLayout()
|
|
layout.addWidget(self.daq_connect_button, 0, 0)
|
|
layout.addWidget(self.daq_disconnect_button, 0, 1)
|
|
layout.addWidget(self.text, 2, 0, 1, 2)
|
|
|
|
self.toolbar = QToolBar("Repros")
|
|
self.addToolBar(self.toolbar)
|
|
self.repros_to_toolbar()
|
|
|
|
self.setFixedSize(QSize(400, 300))
|
|
widget = QWidget()
|
|
widget.setLayout(layout)
|
|
self.setCentralWidget(widget)
|
|
|
|
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.debug("DAQ is not connected, closing")
|
|
QApplication.quit()
|
|
self.daq_connect_button.setDisabled(True)
|
|
|
|
def disconnect_dac(self):
|
|
try:
|
|
log.debug(f"{self.daq_device}")
|
|
self.daq_device.disconnect()
|
|
self.daq_device.release()
|
|
log.debug(f"{self.daq_device}")
|
|
self.daq_disconnect_button.setDisabled(True)
|
|
self.daq_connect_button.setEnabled(True)
|
|
except AttributeError:
|
|
log.debug("DAQ was not connected")
|
|
|
|
def repros_to_toolbar(self):
|
|
repro_names, file_names = self.repros.names_of_repros()
|
|
for rep, fn in zip(repro_names, file_names):
|
|
individual_repro_button = QAction(rep, self)
|
|
individual_repro_button.setStatusTip("Button")
|
|
individual_repro_button.triggered.connect(
|
|
lambda checked, n=rep, f=fn: self.run_repro(n, f)
|
|
)
|
|
self.toolbar.addAction(individual_repro_button)
|
|
|
|
def run_repro(self, n, fn):
|
|
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
|
|
|
|
|
def main():
|
|
app = QApplication(sys.argv)
|
|
app.setApplicationName(info.NAME)
|
|
app.setApplicationVersion(str(info.VERSION))
|
|
app.setOrganizationDomain(info.ORGANIZATION)
|
|
|
|
# read window settings
|
|
settings = QSettings(info.ORGANIZATION, info.NAME)
|
|
width = int(settings.value("app/width", 1024))
|
|
height = int(settings.value("app/height", 768))
|
|
x = int(settings.value("app/pos_x", 100))
|
|
y = int(settings.value("app/pos_y", 100))
|
|
|
|
window = PyRelacs()
|
|
window.setMinimumWidth(200)
|
|
window.setMinimumHeight(200)
|
|
window.resize(width, height)
|
|
window.move(x, y)
|
|
window.show()
|
|
app.exec()
|
|
|
|
# store window position and size
|
|
pos = window.pos()
|
|
settings.setValue("app/width", window.width())
|
|
settings.setValue("app/height", window.height())
|
|
settings.setValue("app/pos_x", pos.x())
|
|
settings.setValue("app/pos_y", pos.y())
|
|
sys.exit(exit_code)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |