forked from awendt/pyrelacs
Merge branch 'main' of https://whale.am28.uni-tuebingen.de/git/Awendt/pyrelacs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from PyQt6.QtGui import QAction
|
||||
import sys
|
||||
import pathlib
|
||||
import ctypes
|
||||
|
||||
from PyQt6.QtCore import QProcess, QSize, QThreadPool, Qt, QSettings
|
||||
from PyQt6.QtWidgets import (
|
||||
@@ -13,13 +12,14 @@ from PyQt6.QtWidgets import (
|
||||
QMainWindow,
|
||||
QPlainTextEdit,
|
||||
)
|
||||
import tomli
|
||||
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()
|
||||
|
||||
@@ -31,8 +31,7 @@ class PyRelacs(QMainWindow):
|
||||
self.setMinimumSize(1000, 1000)
|
||||
|
||||
self.threadpool = QThreadPool()
|
||||
# for starting a Qprocess
|
||||
self.p = None
|
||||
self.repros = Repro()
|
||||
|
||||
self.daq_connect_button = QPushButton("Connect Daq")
|
||||
self.daq_connect_button.setCheckable(True)
|
||||
@@ -52,7 +51,7 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
self.toolbar = QToolBar("Repros")
|
||||
self.addToolBar(self.toolbar)
|
||||
self.repro()
|
||||
self.repros_to_toolbar()
|
||||
|
||||
self.setFixedSize(QSize(400, 300))
|
||||
widget = QWidget()
|
||||
@@ -82,60 +81,18 @@ class PyRelacs(QMainWindow):
|
||||
except AttributeError:
|
||||
log.debug("DAQ was not connected")
|
||||
|
||||
def repro(self):
|
||||
repos_path = pathlib.Path(__file__).parent / "repros"
|
||||
repos_names = list(repos_path.glob("*.py"))
|
||||
# exclude the repos.py file
|
||||
repos_names = [
|
||||
f.with_suffix("").name for f in repos_names if not f.name == "repos.py"
|
||||
]
|
||||
for rep in repos_names:
|
||||
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: self.run_repro(n)
|
||||
lambda checked, n=rep, f=fn: self.run_repro(n, f)
|
||||
)
|
||||
self.toolbar.addAction(individual_repro_button)
|
||||
|
||||
def message(self, s):
|
||||
self.text.appendPlainText(s)
|
||||
|
||||
def run_repro(self, name_of_repo):
|
||||
if self.p is None:
|
||||
self.message(f"Executing process {name_of_repo}")
|
||||
self.p = QProcess()
|
||||
self.p.setWorkingDirectory(str(pathlib.Path(__file__).parent / "repros/"))
|
||||
# log.debug(pathlib.Path(__file__).parent / "repos")
|
||||
self.p.readyReadStandardOutput.connect(self.handle_stdout)
|
||||
self.p.readyReadStandardError.connect(self.handle_stderr)
|
||||
self.p.stateChanged.connect(self.handle_state)
|
||||
self.p.finished.connect(self.process_finished)
|
||||
self.p.start("python3", [f"{name_of_repo}" + ".py"])
|
||||
|
||||
def handle_stderr(self):
|
||||
if self.p is not None:
|
||||
data = self.p.readAllStandardError()
|
||||
stderr = bytes(data).decode("utf8")
|
||||
self.message(stderr)
|
||||
|
||||
def handle_stdout(self):
|
||||
if self.p is not None:
|
||||
data = self.p.readAllStandardOutput()
|
||||
stdout = bytes(data).decode("utf8")
|
||||
self.message(stdout)
|
||||
|
||||
def handle_state(self, state):
|
||||
states = {
|
||||
QProcess.ProcessState.NotRunning: "Not running",
|
||||
QProcess.ProcessState.Starting: "Starting",
|
||||
QProcess.ProcessState.Running: "Running",
|
||||
}
|
||||
state_name = states[state]
|
||||
self.message(f"State changed: {state_name}")
|
||||
|
||||
def process_finished(self):
|
||||
self.text.appendPlainText("Process finished")
|
||||
self.p = None
|
||||
def run_repro(self, n, fn):
|
||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user