2
0
forked from awendt/pyrelacs

[resources] add some icons

This commit is contained in:
2024-09-29 00:14:30 +02:00
parent d241d88168
commit fe6e438189
10 changed files with 3804 additions and 21 deletions

View File

@@ -1,13 +1,14 @@
from PyQt6.QtGui import QAction
from PyQt6.QtCore import QSize, QThreadPool
from PyQt6.QtGui import QAction, QIcon, QKeySequence
from PyQt6.QtCore import Qt, QSize, QThreadPool
from PyQt6.QtWidgets import (
QApplication,
QGridLayout,
QPushButton,
QToolBar,
QWidget,
QMainWindow,
QPlainTextEdit,
QMenuBar,
QStatusBar
)
import uldaq
import pathlib
@@ -15,9 +16,10 @@ import numpy as np
import nixio as nix
import pyqtgraph as pg
from importlib.resources import files as rsrc_files
from scipy.signal import welch, find_peaks
from ..worker import Worker
from pyrelacs.worker import Worker
from ..repros.repros import Repro
from ..util.logging import config_logging
log = config_logging()
@@ -27,6 +29,7 @@ from IPython import embed
class PyRelacs(QMainWindow):
def __init__(self):
super().__init__()
# self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) # Ensure icons are displayed with text
self.setWindowTitle("PyRelacs")
self.beat_plot = pg.PlotWidget()
self.power_plot = pg.PlotWidget()
@@ -34,20 +37,14 @@ class PyRelacs(QMainWindow):
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.text = QPlainTextEdit()
self.text.setReadOnly(True)
self.daq_disconnect_button = QPushButton("Disconnect Daq")
self.daq_disconnect_button.setCheckable(True)
self.daq_disconnect_button.clicked.connect(self.disconnect_dac)
self.plot_calibration_button = QPushButton("Plot Calibration")
self.plot_calibration_button.setCheckable(True)
self.plot_calibration_button.clicked.connect(self.plot_calibration)
# self.text = QPlainTextEdit()
# self.text.setReadOnly(True)
self.setMenuBar(QMenuBar(self))
self.setStatusBar(QStatusBar(self))
self.create_actions()
self.create_buttons()
self.create_toolbars()
layout = QGridLayout()
layout.addWidget(self.plot_calibration_button, 0, 0)
@@ -69,6 +66,85 @@ class PyRelacs(QMainWindow):
str(filename), nix.FileMode.Overwrite
)
def create_actions(self):
icon_path = str(rsrc_files("pyrelacs.icons").joinpath("exit.png"))
self._rlx_exitaction = QAction(QIcon(":icons/exit.png"), "Exit", self)
self._rlx_exitaction.setStatusTip("Close relacs")
self._rlx_exitaction.setShortcut(QKeySequence("Alt+q"))
self._rlx_exitaction.triggered.connect(self.on_exit)
# icon_path = str(rsrc_files("pyrelacs.icons").joinpath("connect.png"))
self._daq_connectaction = QAction(QIcon(":/icons/connect.png"), "Connect DAQ", self)
self._daq_connectaction.setStatusTip("Connect to daq device")
# self._daq_connectaction.setShortcut(QKeySequence("Alt+d"))
self._daq_connectaction.triggered.connect(self.connect_dac)
icon_path = str(rsrc_files("pyrelacs.icons").joinpath("disconnect.png"))
self._daq_disconnectaction = QAction(QIcon(icon_path), "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)
# icon_path = str(rsrc_files("pyrelacs.icons").joinpath("calibration.png"))
self._daq_calibaction = QAction(QIcon(icon_path), "Plot calibration", self)
self._daq_calibaction.setStatusTip("Calibrate the attenuator device")
# self._daq_calibaction.setShortcut(QKeySequence("Alt+d"))
self._daq_calibaction.triggered.connect(self.plot_calibration)
self.create_menu()
def create_menu(self):
menu = self.menuBar()
file_menu = menu.addMenu("&File")
file_menu.addAction(self._rlx_exitaction)
device_menu = menu.addMenu("&DAQ")
device_menu.addAction(self._daq_connectaction)
device_menu.addAction(self._daq_disconnectaction)
device_menu.addSeparator()
device_menu.addAction(self._daq_calibaction)
help_menu = menu.addMenu("&Help")
help_menu.addSeparator()
# help_menu.addAction(self._about_action)
# help_menu.addAction(self._help_action)
self.setMenuBar(menu)
def create_toolbars(self):
rlx_toolbar = QToolBar("Relacs")
rlx_toolbar.addAction(self._rlx_exitaction)
rlx_toolbar.setIconSize(QSize(24, 24))
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, rlx_toolbar)
daq_toolbar = QToolBar("DAQ")
daq_toolbar.addAction(self._daq_connectaction)
daq_toolbar.addAction(self._daq_disconnectaction)
daq_toolbar.addAction(self._daq_calibaction)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, daq_toolbar)
repro_toolbar = QToolBar("Repros")
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(rep)
individual_repro_button.triggered.connect(
lambda checked, n=rep, f=fn: self.run_repro(n, f)
)
repro_toolbar.addAction(individual_repro_button)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, repro_toolbar)
def create_buttons(self):
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.plot_calibration_button = QPushButton("Plot Calibration")
self.plot_calibration_button.setCheckable(True)
self.plot_calibration_button.clicked.connect(self.plot_calibration)
def plot_calibration(self):
def decibel(power, ref_power=1.0, min_power=1e-20):
"""Transform power to decibel relative to ref_power.
@@ -141,7 +217,7 @@ class PyRelacs(QMainWindow):
log.debug("Connected")
except IndexError:
log.debug("DAQ is not connected, closing")
QApplication.quit()
self.on_exit()
self.daq_connect_button.setDisabled(True)
def disconnect_dac(self):
@@ -174,6 +250,10 @@ class PyRelacs(QMainWindow):
self.threadpool.start(worker)
def on_exit(self):
print("exit button!")
self.close()
def print_output(self, s):
print(s)