From 31a97bdeb427f18e1b316402522578fbff3587ef Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 10 Apr 2024 16:36:39 +0800 Subject: [PATCH] gui: GUI Initial Commit - Adapted from Thermostat GUI PR #101 --- flake.nix | 33 +- pykirdy/kirdy_qt.py | 835 +++++++++++++++++++++++++++++++++++++++++ pykirdy/kirdy_qt.ui | 762 +++++++++++++++++++++++++++++++++++++ pykirdy/ui_kirdy_qt.py | 368 ++++++++++++++++++ 4 files changed, 1995 insertions(+), 3 deletions(-) create mode 100644 pykirdy/kirdy_qt.py create mode 100644 pykirdy/kirdy_qt.ui create mode 100644 pykirdy/ui_kirdy_qt.py diff --git a/flake.nix b/flake.nix index aa4ca18..49896bd 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,33 @@ dontFixup = true; auditable = false; }; + + pglive = pkgs.python3Packages.buildPythonPackage rec { + pname = "pglive"; + version = "0.7.2"; + format = "pyproject"; + src = pkgs.fetchPypi { + inherit pname version; + hash = "sha256-jqj8X6H1N5mJQ4OrY5ANqRB0YJByqg/bNneEALWmH1A="; + }; + buildInputs = [ pkgs.python3Packages.poetry-core ]; + propagatedBuildInputs = with pkgs.python3Packages; [ pyqtgraph numpy ]; + }; + + kirdy_gui = pkgs.python3Packages.buildPythonPackage { + pname = "kirdy_gui"; + version = "0.0.0"; + format = "pyproject"; + src = "${self}/pykirdy"; + + nativeBuildInputs = [ pkgs.qt6.wrapQtAppsHook ]; + propagatedBuildInputs = [ pkgs.qt6.qtbase ] ++ (with pkgs.python3Packages; [ pyqtgraph pyqt6 qasync pglive ]); + + dontWrapQtApps = true; + postFixup = '' + wrapQtApp "$out/bin/tec_qt" + ''; + }; in { packages.x86_64-linux = { inherit kirdy; @@ -67,12 +94,12 @@ buildInputs = with pkgs; [ rust openocd dfu-util glibc ] ++ (with python3Packages; [ - numpy matplotlib pyqtgraph + numpy matplotlib pyqtgraph setuptools pyqt6 qasync pglive ]); shellHook= '' - export QT_PLUGIN_PATH=${pkgs.qt5.qtbase}/${pkgs.qt5.qtbase.dev.qtPluginPrefix} - export QML2_IMPORT_PATH=${pkgs.qt5.qtbase}/${pkgs.qt5.qtbase.dev.qtQmlPrefix} + export QT_PLUGIN_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.dev.qtPluginPrefix} + export QML2_IMPORT_PATH=${pkgs.qt6.qtbase}/${pkgs.qt6.qtbase.dev.qtQmlPrefix} ''; }; defaultPackage.x86_64-linux = kirdy; diff --git a/pykirdy/kirdy_qt.py b/pykirdy/kirdy_qt.py new file mode 100644 index 0000000..c1bd244 --- /dev/null +++ b/pykirdy/kirdy_qt.py @@ -0,0 +1,835 @@ +from PyQt6 import QtWidgets, QtGui, QtCore +from PyQt6.QtCore import pyqtSignal, QObject, QSignalBlocker, pyqtSlot +import pyqtgraph.parametertree.parameterTypes as pTypes +from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType +import pyqtgraph as pg +pg.setConfigOptions(antialias=True) +from pyqtgraph import mkPen +from pglive.sources.live_axis_range import LiveAxisRange +from pglive.sources.data_connector import DataConnector +from pglive.kwargs import Axis, LeadingLine +from pglive.sources.live_plot import LiveLinePlot +from pglive.sources.live_plot_widget import LivePlotWidget +from pglive.sources.live_axis import LiveAxis +import sys +import argparse +import logging +import asyncio +from driver.kirdy_async import Kirdy, StoppedConnecting +import qasync +from qasync import asyncSlot, asyncClose +from collections import deque +from datetime import datetime, timezone, timedelta +from time import time +from typing import Any, Optional, List +from ui_kirdy_qt import Ui_MainWindow +from dateutil import tz +import math + +def get_argparser(): + parser = argparse.ArgumentParser(description="ARTIQ master") + + parser.add_argument("--connect", default=None, action="store_true", + help="Automatically connect to the specified Thermostat in IP:port format") + parser.add_argument('IP', metavar="ip", default=None, nargs='?') + parser.add_argument('PORT', metavar="port", default=None, nargs='?') + parser.add_argument("-l", "--log", dest="logLevel", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], + help="Set the logging level") + + return parser + +class KirdyDataWatcher(QObject): + """ + This class provides various signals for Mainwindow to update various kinds of GUI objects + """ + connection_error_sig = pyqtSignal() + setting_update_sig = pyqtSignal(dict) + report_update_sig = pyqtSignal(dict) + + def __init__(self, parent, kirdy, update_s): + self._update_s = update_s + self._kirdy = kirdy + self._watch_task = None + self._report_mode_task = None + self._poll_for_report = True + super().__init__(parent) + + async def signal_emitter(self): + try: + settings_summary = await self._kirdy.device.get_settings_summary() + self.setting_update_sig.emit(settings_summary) + if self._poll_for_report: + status_report = await self._kirdy.device.get_status_report() + self.report_update_sig.emit(status_report) + # TODO: Identify the possible types of error that is connection related + except: + logging.error("Client connection error, disconnecting", exc_info=True) + self._kirdy.stop_report_mode() + self.connection_error_sig.emit() + + async def run(self): + while True: + asyncio.ensure_future(self.signal_emitter()) + await asyncio.sleep(self._update_s) + + def start_watching(self): + self._watch_task = asyncio.create_task(self.run()) + + def stop_watching(self): + if self._watch_task is not None: + self._watch_task.cancel() + self._watch_task = None + + async def set_report_mode(self, enabled: bool): + self._poll_for_report = not enabled + if enabled: + self._report_mode_task = asyncio.create_task(self.report_mode()) + else: + self._kirdy.stop_report_mode() + if self._report_mode_task is not None: + await self._report_mode_task + self._report_mode_task = None + + async def report_mode(self): + try: + async for status_report in self._kirdy.report_mode(): + self.report_update_sig.emit(status_report) + except: + logging.error("Client connection error, disconnecting", exc_info=True) + self._kirdy.stop_report_mode() + self.connection_error_sig.emit() + + @pyqtSlot(float) + def set_update_s(self, update_s): + self._update_s = update_s + +class Graphs: + def __init__(self, ld_i_set_graph, pd_mon_pwr_graph, tec_i_graph, tec_temp_graph, max_samples=1000): + self.graphs = [ld_i_set_graph, pd_mon_pwr_graph, tec_i_graph, tec_temp_graph] + self.connectors = [] + + self._pd_mon_pwr_plot = LiveLinePlot(pen=pg.mkPen('r')) + self._ld_i_set_plot = LiveLinePlot(name="Set", pen=pg.mkPen('r')) + self._tec_temp_plot = LiveLinePlot(pen=pg.mkPen('r')) + self._tec_setpoint_plot = LiveLinePlot(pen=pg.mkPen('r')) + self._tec_i_target_plot = LiveLinePlot(name="Target", pen=pg.mkPen('r')) + self._tec_i_measure_plot = LiveLinePlot(name="Measure", pen=pg.mkPen('g')) + + self._temp_setpoint_line = tec_temp_graph.getPlotItem().addLine(label='{value} °C', pen=pg.mkPen('g')) + # Render the temperature setpoint line on top of the temperature being plotted + self._temp_setpoint_line.setZValue(10) + self._temp_setpoint_line.setVisible(False) + + def tickStrings(values: List, scale: float, spacing: float) -> List: + return [datetime.fromtimestamp(value/1000, tz=timezone.utc).strftime("%H:%M:%S") for value in values] + + for graph in ld_i_set_graph, pd_mon_pwr_graph, tec_i_graph, tec_temp_graph: + time_axis = LiveAxis('bottom', text="Time since Kirdy Reset (Hr:Min:Sec)", tick_angle=-45, units="") + # Display the relative ts in custom %H:%M:%S format without local timezone + time_axis.tickStrings = tickStrings + # Prevent scaling prefix being added to the back fo axis label + time_axis.autoSIPrefix = False + time_axis.showLabel() + + graph.setAxisItems({'bottom': time_axis}) + graph.add_crosshair(pg.mkPen(color='red', width=1), {'color': 'green'}) + + #TODO: x_range should not be updated on every tick + graph.x_range_controller = LiveAxisRange(roll_on_tick=17, offset_left=4900) + graph.x_range_controller.crop_left_offset_to_data = True + # Enable linking of axes in the graph widget's context menu + graph.register(graph.getPlotItem().titleLabel.text) # Slight hack getting the title + + self.max_samples = max_samples + ld_i_set_axis = LiveAxis('left', text="Current", units="A") + ld_i_set_axis.showLabel() + ld_i_set_graph.setAxisItems({'left': ld_i_set_axis}) + ld_i_set_graph.addItem(self._ld_i_set_plot) + self.ld_i_set_connector = DataConnector(self._ld_i_set_plot, max_points=self.max_samples) + self.connectors += [self.ld_i_set_connector] + + pd_mon_pwr_axis = LiveAxis('left', text="Power", units="W") + pd_mon_pwr_axis.showLabel() + pd_mon_pwr_graph.setAxisItems({'left': pd_mon_pwr_axis}) + pd_mon_pwr_graph.addItem(self._pd_mon_pwr_plot) + self.pd_mon_pwr_connector = DataConnector(self._pd_mon_pwr_plot, max_points=self.max_samples) + self.connectors += [self.pd_mon_pwr_connector] + + tec_temp_axis = LiveAxis('left', text="Temperature", units="°C") + tec_temp_axis.showLabel() + tec_temp_graph.setAxisItems({'left': tec_temp_axis}) + tec_temp_graph.addItem(self._tec_setpoint_plot) + tec_temp_graph.addItem(self._tec_temp_plot) + self.tec_setpoint_connector = DataConnector(self._tec_setpoint_plot, max_points=1) + self.tec_temp_connector = DataConnector(self._tec_temp_plot, max_points=self.max_samples) + self.connectors += [self.tec_temp_connector, self.tec_setpoint_connector] + + tec_i_axis = LiveAxis('left', text="Current", units="A") + tec_i_axis.showLabel() + tec_i_graph.setAxisItems({'left': tec_i_axis}) + tec_i_graph.addLegend(brush=(50, 50, 200, 150)) + tec_i_graph.y_range_controller = LiveAxisRange(fixed_range=[-1.0, 1.0]) + tec_i_graph.addItem(self._tec_i_target_plot) + tec_i_graph.addItem(self._tec_i_measure_plot) + self.tec_i_target_connector = DataConnector(self._tec_i_target_plot, max_points=self.max_samples) + self.tec_i_measure_connector = DataConnector(self._tec_i_measure_plot, max_points=self.max_samples) + self.connectors += [self.tec_i_target_connector, self.tec_i_measure_connector] + + def set_max_samples(self, max_samples): + self.max_samples = max_samples + for connector in self.connectors: + with connector.data_lock: + connector.max_points = self.max_samples + connector.x = deque(maxlen=int(connector.max_points)) + connector.y = deque(maxlen=int(connector.max_points)) + + def plot_append(self, report): + try: + ld_i_set = report['laser']['ld_i_set'] + pd_pwr = report['laser']['pd_pwr'] + + tec_i_set = report['thermostat']['i_set'] + tec_i_measure = report['thermostat']['tec_i'] + tec_temp = report['thermostat']['temperature'] + + ts = report['ts'] + + self.ld_i_set_connector.cb_append_data_point(ld_i_set, ts) + self.pd_mon_pwr_connector.cb_append_data_point(pd_pwr, ts) + + if tec_temp is not None: + self.tec_temp_connector.cb_append_data_point(tec_temp, ts) + if self._temp_setpoint_line.isVisible(): + self.tec_setpoint_connector.cb_append_data_point(self._temp_setpoint_line.value(), ts) + else: + self.tec_setpoint_connector.cb_append_data_point(tec_temp, ts) + if tec_i_measure is not None: + self.tec_i_measure_connector.cb_append_data_point(tec_i_measure, ts) + self.tec_i_target_connector.cb_append_data_point(tec_i_set, ts) + except Exception as e: + logging.error(f"Graph Value cannot be updated. Error:{e}. Data:{report}") + + def clear_data_pts(self): + for connector in self.connectors: + connector.clear() + connector.resume() + + def set_temp_setpoint_line(self, temp=None, visible=None): + if visible is not None: + self._temp_setpoint_line.setVisible(visible) + if temp is not None: + self._temp_setpoint_line.setValue(temp) + + # PyQtGraph normally does not update this text when the line + # is not visible, so make sure that the temperature label + # gets updated always, and doesn't stay at an old value. + self._temp_setpoint_line.label.setText(f"{temp} °C", color='g') + +class MutexParameter(pTypes.ListParameter): + """ + Mutually exclusive parameter where only one of its children is visible at a time, list selectable. + + The ordering of the list items determines which children will be visible. + """ + def __init__(self, **opts): + super().__init__(**opts) + + self.sigValueChanged.connect(self.show_chosen_child) + self.sigValueChanged.emit(self, self.opts['value']) + + def _get_param_from_value(self, value): + if isinstance(self.opts['limits'], dict): + values_list = list(self.opts['limits'].values()) + else: + values_list = self.opts['limits'] + + return self.children()[values_list.index(value)] + + @pyqtSlot(object, object) + def show_chosen_child(self, value): + for param in self.children(): + param.hide() + + child_to_show = self._get_param_from_value(value.value()) + child_to_show.show() + + if child_to_show.opts.get('triggerOnShow', None): + child_to_show.sigValueChanged.emit(child_to_show, child_to_show.value()) + +registerParameterType('mutex', MutexParameter) + +class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): + """The maximum number of sample points to store.""" + DEFAULT_MAX_SAMPLES = 1000 + + LASER_DIODE_STATUS = [ + {'name': 'Power', 'type': 'color', 'value': 'w', 'readonly': True}, + {'name': 'Alarm', 'type': 'color', 'value': 'w', 'readonly': True}, + ] + + LASER_DIODE_PARAMETERS = [ + {'name': 'Readings', 'expanded': True, 'type': 'group', 'children': [ + {'name': 'LD Current Set', 'type': 'float', 'suffix': 'A', 'siPrefix': True, 'readonly': True}, + {'name': 'PD Current', 'type': 'float', 'suffix': 'A', 'siPrefix': True, 'readonly': True}, + {'name': 'PD Power', 'type': 'float', 'suffix': 'W', 'siPrefix': True, 'readonly': True}, + {'name': 'LF Mod Impedance', 'type': 'list', 'limits': ['Is50Ohm', 'Not50Ohm'], 'readonly': True} + ]}, + {'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [ + {'name': 'LD Current Set', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 1), + 'suffix': 'A', 'siPrefix': True, 'target': 'laser', 'action': 'set_i'}, + {'name': 'LD Current Set Soft Limit', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 1), + 'suffix': 'A', 'siPrefix': True, 'target': 'laser', 'action': 'set_i_soft_limit'}, + {'name': 'LD Power Limit', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 0.3), + 'suffix': 'W', 'siPrefix': True, 'target': 'laser', 'action': 'set_ld_pwr_limit'}, + {'name': 'LD Terminals Short', 'type': 'bool', 'value': False, 'target': 'laser', 'action': 'set_ld_terms_short'}, + {'name': 'Default Power On', 'type': 'bool', 'value': False, 'target': 'laser', 'action': 'set_default_pwr_on'}, + ]}, + {'name': 'Photodiode Monitor Config', 'expanded': False, 'type': 'group', 'children': [ + {'name': 'Responsitivity', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 3000), + 'suffix': 'A/W', 'siPrefix': True, 'target': 'laser', 'action': 'set_pd_mon_responsitivity'}, + {'name': 'Dark Current', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (0, 3000), + 'suffix': 'A', 'siPrefix': True, 'target': 'laser', 'action': 'set_pd_mon_dark_current'}, + ]}, + ] + + THERMOSTAT_STATUS = [ + {'name': 'Power', 'type': 'color', 'value': 'w', 'readonly': True}, + {'name': 'Alarm', 'type': 'color', 'value': 'w', 'readonly': True}, + ] + + THERMOSTAT_PARAMETERS = [ + {'name': 'Readings', 'expanded': True, 'type': 'group', 'children': [ + {'name': 'Temperature', 'type': 'float', 'format': '{value:.4f} °C', 'readonly': True}, + {'name': 'Current through TEC', 'type': 'float', 'suffix': 'A', 'siPrefix': True, 'decimals': 6, 'readonly': True}, + ]}, + {'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [ + {'name': 'Control Method', 'type': 'mutex', 'limits': ['Constant Current', 'Temperature PID'], + 'target_action_pair': [['thermostat', 'set_constant_current_control_mode'], ['thermostat', 'set_pid_control_mode']], 'children': [ + {'name': 'Set Current', 'type': 'float', 'value': 0, 'step': 0.001, 'limits': (-1, 1), 'triggerOnShow': True, + 'decimals': 6, 'suffix': 'A', 'siPrefix': True, 'target': 'thermostat', 'action': 'set_tec_i_out'}, + {'name': 'Set Temperature', 'type': 'float', 'value': 25, 'step': 0.1, 'limits': (-273, 300), + 'format': '{value:.4f} °C', 'target': 'thermostat', 'action': 'set_temperature_setpoint'}, + ]}, + {'name': 'Limits', 'expanded': False, 'type': 'group', 'children': [ + {'name': 'Max Cooling Current', 'type': 'float', 'value': 0, 'step': 0.001, 'decimals': 6, 'limits': (0, 1), + 'suffix': 'A', 'siPrefix': True, 'target': 'thermostat', 'action': 'set_tec_max_cooling_i'}, + {'name': 'Max Heating Current', 'type': 'float', 'value': 0, 'step': 0.001, 'decimals': 6, 'limits': (0, 1), + 'suffix': 'A', 'siPrefix': True, 'target': 'thermostat', 'action': 'set_tec_max_heating_i'}, + {'name': 'Max Voltage Difference', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), + 'suffix': 'V', 'siPrefix': True, 'target': 'thermostat', 'action': 'set_tec_max_v'}, + ]}, + {'name': 'Default Power On', 'type': 'bool', 'value': False, 'target': 'thermostat', 'action': 'set_default_pwr_on'}, + ]}, + # TODO Temperature ADC Filter Settings + {'name': 'Temperature Monitor Config', 'expanded': False, 'type': 'group', 'children': [ + {'name': 'Upper Limit', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (-273, 300), + 'suffix': '°C', 'target': 'thermostat', 'action': 'set_temp_mon_upper_limit'}, + {'name': 'Lower Limit', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (-273, 300), + 'suffix': '°C', 'target': 'thermostat', 'action': 'set_temp_mon_upper_limit'}, + ]}, + {'name': 'Thermistor Settings','expanded': False, 'type': 'group', 'children': [ + {'name': 'T₀', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, 'limits': (-273, 300), + 'suffix': '°C', 'target': 'thermostat', 'action': 'set_sh_t0'}, + {'name': 'R₀', 'type': 'float', 'value': 0, 'step': 1, 'decimals': 6, + 'suffix': 'Ω', 'siPrefix': True, 'target': 'thermostat', 'action': 'set_sh_r0'}, + {'name': 'B', 'type': 'float', 'value': 3950, 'step': 1, 'suffix': 'K', 'decimals': 4, 'target': 'thermostat', 'action': 'set_sh_beta'}, + ]}, + {'name': 'PID Config', 'expanded': False, 'type': 'group', 'children': [ + {'name': 'Kp', 'type': 'float', 'step': 0.1, 'suffix': '', 'target': 'thermostat', 'action': 'set_pid_kp'}, + {'name': 'Ki', 'type': 'float', 'step': 0.1, 'suffix': 'Hz', 'target': 'thermostat', 'action': 'set_pid_ki'}, + {'name': 'Kd', 'type': 'float', 'step': 0.1, 'suffix': 's', 'target': 'thermostat', 'action': 'set_pid_kd'}, + {'name': "PID Output Clamping", 'expanded': True, 'type': 'group', 'children': [ + {'name': 'Minimum', 'type': 'float', 'step': 100, 'limits': (-1, 1), 'decimals': 6, 'suffix': 'A', 'target': 'thermostat', 'action': 'set_pid_output_min'}, + {'name': 'Maximum', 'type': 'float', 'step': 100, 'limits': (-1, 1), 'decimals': 6, 'suffix': 'A', 'target': 'thermostat', 'action': 'set_pid_output_max'}, + ]}, + # TODO PID AutoTune + ]}, + ] + def __init__(self, args): + super().__init__() + self.kirdy = Kirdy() + self.setupUi(self) + + self.max_samples = self.DEFAULT_MAX_SAMPLES + + self._set_up_connection_menu() + self._set_up_kirdy_menu() + self._set_up_ctrl_btns() + self._set_up_plot_menu() + + self.params = [ + Parameter.create(name=f"Laser Diode Status", type='group', value=0, children=self.LASER_DIODE_STATUS), + Parameter.create(name=f"Laser Diode Parameters", type='group', value=1, children=self.LASER_DIODE_PARAMETERS), + Parameter.create(name=f"Thermostat Status", type='group', value=2, children=self.THERMOSTAT_STATUS), + Parameter.create(name=f"Thermostat Parameters", type='group', value=3, children=self.THERMOSTAT_PARAMETERS), + ] + self._set_param_tree() + + self.tec_i_graph.setTitle("TEC Current") + self.tec_temp_graph.setTitle("TEC Temperature") + self.ld_i_set_graph.setTitle("LD Current Set") + self.pd_mon_pwr_graph.setTitle("PD Mon Power") + + self.report_box.stateChanged.connect(self.on_report_box_stateChanged) + + self.kirdy_data_watcher = KirdyDataWatcher(self, self.kirdy, self.report_refresh_spin.value()) + self.kirdy_data_watcher.connection_error_sig.connect(self.bail) + # TODO: Identify the usable range of set_update_s + self.report_apply_btn.clicked.connect( + lambda: self.kirdy_data_watcher.set_update_s(self.report_refresh_spin.value()) + ) + self.kirdy_data_watcher.setting_update_sig.connect(self.update_ld_ctrl_panel_settings) + self.kirdy_data_watcher.setting_update_sig.connect(self.update_thermostat_ctrl_panel_settings) + self.kirdy_data_watcher.report_update_sig.connect(self.update_ld_ctrl_panel_readings) + self.kirdy_data_watcher.report_update_sig.connect(self.update_thermostat_ctrl_panel_readings) + + self.graphs = Graphs(self.ld_i_set_graph, self.pd_mon_pwr_graph, self.tec_i_graph, self.tec_temp_graph, max_samples=self.max_samples) + self.kirdy_data_watcher.report_update_sig.connect(self.graphs.plot_append) + + self.save_flash_btn.clicked.connect( + lambda: self.save_ld_thermostat_settings_to_flash() + ) + + self.load_flash_btn.clicked.connect( + lambda: self.load_ld_thermostat_settings_from_flash() + ) + + self.loading_spinner.hide() + + def _set_up_ctrl_btns(self): + @asyncSlot(bool) + async def ld_pwr_on(_): + await self.kirdy.laser.set_power_on(True) + self.ld_pwr_on_btn.clicked.connect(ld_pwr_on) + + @asyncSlot(bool) + async def ld_pwr_off(_): + await self.kirdy.laser.set_power_on(False) + self.ld_pwr_off_btn.clicked.connect(ld_pwr_off) + + @asyncSlot(bool) + async def ld_clear_alarm(_): + await self.kirdy.laser.clear_alarm() + self.ld_clear_alarm_btn.clicked.connect(ld_clear_alarm) + + @asyncSlot(bool) + async def tec_pwr_on(_): + await self.kirdy.thermostat.set_power_on(True) + self.tec_pwr_on_btn.clicked.connect(tec_pwr_on) + + @asyncSlot(bool) + async def tec_pwr_off(_): + await self.kirdy.thermostat.set_power_on(False) + self.tec_pwr_off_btn.clicked.connect(tec_pwr_off) + + @asyncSlot(bool) + async def tec_clear_alarm(_): + await self.kirdy.thermostat.clear_alarm() + self.tec_clear_alarm_btn.clicked.connect(tec_clear_alarm) + + def _set_up_kirdy_menu(self): + self.kirdy_menu = QtWidgets.QMenu() + self.kirdy_menu.setTitle('Kirdy Settings') + + @asyncSlot(int) + async def on_report_box_stateChanged(self, enabled): + await self.kirdy_data_watcher.set_report_mode(enabled) + + @asyncSlot(bool) + async def reset_kirdy(_): + await self.kirdy.device.hard_reset() + await self._on_connection_changed(False) + await asyncio.sleep(0.1) # Wait for the reset to start + # TODO: Attempt to reconnect after resetting + + self.actionReset.triggered.connect(reset_kirdy) + self.kirdy_menu.addAction(self.actionReset) + + @asyncSlot(bool) + async def dfu_mode(_): + await self._on_connection_changed(False) + await self.kirdy.device.dfu() + + self.actionEnter_DFU_Mode.triggered.connect(dfu_mode) + self.kirdy_menu.addAction(self.actionEnter_DFU_Mode) + + # TODO: Add a form for user to set ip settings in multiple text boxes + @asyncSlot(bool) + async def network_settings(_): + ask_network = QtWidgets.QInputDialog(self) + ask_network.setWindowTitle("Network Settings") + ask_network.setLabelText("Set the kirdy's IPv4 address, port, prefix length and gateway") + ask_network.setTextValue("192.168.1.128 1337 24 192.168.1.1") + + @pyqtSlot(str) + def set_ipv4(ipv4_settings): + sure = QtWidgets.QMessageBox(self) + sure.setWindowTitle("Set network?") + sure.setText(f"Setting this as network and disconnecting:
{ipv4_settings}") + + @asyncSlot(object) + async def really_set(button): + addr, port, prefix_len, gateway = ipv4_settings.split() + addr = list(map(int, addr.split("."))) + gateway = list(map(int, gateway.split("."))) + + await self.kirdy.device.set_ip_settings(addr, int(port), int(prefix_len), gateway) + + # TODO: Add a dialogue box and ask if the user wanna reboot Kirdy immediately + await self.kirdy.device.hard_reset() + + await self._on_connection_changed(False) + sure.buttonClicked.connect(really_set) + sure.show() + ask_network.textValueSelected.connect(set_ipv4) + ask_network.show() + + self.actionNetwork_Settings.triggered.connect(network_settings) + self.kirdy_menu.addAction(self.actionNetwork_Settings) + + @asyncSlot(bool) + async def load(_): + await self.kirdy.device.load_current_settings_to_flash() + loaded = QtWidgets.QMessageBox(self) + loaded.setWindowTitle("Config loaded") + loaded.setText(f"All channel configs have been loaded from flash.") + loaded.setIcon(QtWidgets.QMessageBox.Icon.Information) + loaded.show() + + self.actionLoad_all_configs.triggered.connect(load) + self.kirdy_menu.addAction(self.actionLoad_all_configs) + + @asyncSlot(bool) + async def save(_): + await self.kirdy.device.save_current_settings_to_flash() + saved = QtWidgets.QMessageBox(self) + saved.setWindowTitle("Config saved") + saved.setText(f"All channel configs have been saved to flash.") + saved.setIcon(QtWidgets.QMessageBox.Icon.Information) + saved.show() + self.actionSave_all_configs.triggered.connect(save) + self.kirdy_menu.addAction(self.actionSave_all_configs) + + def about_kirdy(): + # TODO: Replace the hardware revision placeholder + QtWidgets.QMessageBox.about( + self, + "About Kirdy", + f""" +

Sinara 1550 Kirdy v"major rev"."minor rev"

+ """ + ) + + self.actionAbout_Kirdy.triggered.connect(about_kirdy) + self.kirdy_menu.addAction(self.actionAbout_Kirdy) + self.kirdy_settings.setMenu(self.kirdy_menu) + + def _set_up_plot_menu(self): + self.plot_menu = QtWidgets.QMenu() + self.plot_menu.setTitle("Plot Settings") + + clear = QtGui.QAction("Clear graphs", self.plot_menu) + clear.triggered.connect(self.clear_graphs) + self.plot_menu.addAction(clear) + self.plot_menu.clear = clear + + self.samples_spinbox = QtWidgets.QSpinBox() + self.samples_spinbox.setRange(2, 100000) + self.samples_spinbox.setSuffix(' samples') + self.samples_spinbox.setValue(self.max_samples) + self.samples_spinbox.valueChanged.connect(self.set_max_samples) + + limit_samples = QtWidgets.QWidgetAction(self.plot_menu) + limit_samples.setDefaultWidget(self.samples_spinbox) + self.plot_menu.addAction(limit_samples) + self.plot_menu.limit_samples = limit_samples + + self.plot_settings.setMenu(self.plot_menu) + + def _set_param_tree(self): + status = self.ld_status + status.setHeaderHidden(True) + status.setParameters(self.params[0], showTop=False) + + tree = self.ld_tree + tree.setHeaderHidden(True) + tree.setParameters(self.params[1], showTop=False) + self.params[1].sigTreeStateChanged.connect(self.send_command) + + status = self.tec_status + status.setHeaderHidden(True) + status.setParameters(self.params[2], showTop=False) + + tree = self.tec_tree + tree.setHeaderHidden(True) + tree.setParameters(self.params[3], showTop=False) + self.params[3].sigTreeStateChanged.connect(self.send_command) + + def _set_up_connection_menu(self): + self.connection_menu = QtWidgets.QMenu() + self.connection_menu.setTitle('Connection Settings') + + self.host_set_line = QtWidgets.QLineEdit() + self.host_set_line.setMinimumSize(QtCore.QSize(160, 0)) + self.host_set_line.setMaximumSize(QtCore.QSize(160, 16777215)) + self.host_set_line.setMaxLength(15) + self.host_set_line.setClearButtonEnabled(True) + + def connect_on_enter_press(): + self.connect_btn.click() + self.connection_menu.hide() + self.host_set_line.returnPressed.connect(connect_on_enter_press) + + self.host_set_line.setText("192.168.1.128") + self.host_set_line.setPlaceholderText("IP for the Kirdy") + + host = QtWidgets.QWidgetAction(self.connection_menu) + host.setDefaultWidget(self.host_set_line) + self.connection_menu.addAction(host) + self.connection_menu.host = host + + self.port_set_spin = QtWidgets.QSpinBox() + self.port_set_spin.setMinimumSize(QtCore.QSize(70, 0)) + self.port_set_spin.setMaximumSize(QtCore.QSize(70, 16777215)) + self.port_set_spin.setMaximum(65535) + self.port_set_spin.setValue(1337) + + def connect_only_if_enter_pressed(): + if not self.port_set_spin.hasFocus(): # Don't connect if the spinbox only lost focus + return; + connect_on_enter_press() + self.port_set_spin.editingFinished.connect(connect_only_if_enter_pressed) + + port = QtWidgets.QWidgetAction(self.connection_menu) + port.setDefaultWidget(self.port_set_spin) + self.connection_menu.addAction(port) + self.connection_menu.port = port + + self.exit_button = QtWidgets.QPushButton() + self.exit_button.setText("Exit GUI") + self.exit_button.pressed.connect(QtWidgets.QApplication.instance().quit) + + exit_action = QtWidgets.QWidgetAction(self.exit_button) + exit_action.setDefaultWidget(self.exit_button) + self.connection_menu.addAction(exit_action) + self.connection_menu.exit_action = exit_action + + self.connect_btn.setMenu(self.connection_menu) + + async def _on_connection_changed(self, result): + def ctrl_panel_setEnable(result): + self.ld_status.setEnabled(result) + self.ld_tree.setEnabled(result) + self.ld_pwr_on_btn.setEnabled(result) + self.ld_pwr_off_btn.setEnabled(result) + self.ld_clear_alarm_btn.setEnabled(result) + self.tec_status.setEnabled(result) + self.tec_tree.setEnabled(result) + self.tec_pwr_on_btn.setEnabled(result) + self.tec_pwr_off_btn.setEnabled(result) + self.tec_clear_alarm_btn.setEnabled(result) + ctrl_panel_setEnable(result) + + def graph_group_setEnable(result): + self.ld_i_set_graph.setEnabled(result) + self.pd_mon_pwr_graph.setEnabled(result) + self.tec_i_graph.setEnabled(result) + self.tec_temp_graph.setEnabled(result) + graph_group_setEnable(result) + + self.kirdy_settings.setEnabled(result) + self.report_refresh_spin.setEnabled(result) + + self.report_group.setEnabled(result) + self.report_refresh_spin.setEnabled(result) + self.report_box.setEnabled(result) + self.report_apply_btn.setEnabled(result) + self.save_flash_btn.setEnabled(result) + self.load_flash_btn.setEnabled(result) + + self.host_set_line.setEnabled(not result) + self.port_set_spin.setEnabled(not result) + self.connect_btn.setText("Disconnect" if result else "Connect") + if result: + # TODO: self.hw_rev_data = await self.kirdy.hw_rev() + self._status() + self.kirdy_data_watcher.start_watching() + else: + pass + self.status_lbl.setText("Disconnected") + self.clear_graphs() + self.report_box.setChecked(False) + await self.kirdy_data_watcher.set_report_mode(False) + self.kirdy_data_watcher.stop_watching() + self.status_lbl.setText("Disconnected") + + def _status(self): + # TODO: Get rev no from Kirdy and then add revision into the text + self.status_lbl.setText(f"Connected to Kirdy ") + + def clear_graphs(self): + self.graphs.clear_data_pts() + + @asyncSlot() + async def save_ld_thermostat_settings_to_flash(self): + await self.kirdy.device.save_current_settings_to_flash() + + @asyncSlot() + async def load_ld_thermostat_settings_from_flash(self): + await self.kirdy.device.load_current_settings_from_flash() + + @asyncSlot(dict) + async def graphs_update(self, report): + self.graphs.plot_append(report) + + @asyncSlot(dict) + async def update_ld_ctrl_panel_settings(self, settings): + try: + settings = settings['laser'] + with QSignalBlocker(self.params[1]): + self.params[1].child('Output Config', 'LD Current Set').setValue(settings["ld_drive_current"]['value']) + self.params[1].child('Output Config', 'LD Current Set Soft Limit').setValue(settings["ld_drive_current_limit"]['value']) + self.params[1].child('Output Config', 'LD Power Limit').setValue(settings["ld_pwr_limit"]) + self.params[1].child('Output Config', 'LD Terminals Short').setValue(settings["ld_terms_short"]) + self.params[1].child('Output Config', 'Default Power On').setValue(settings["default_pwr_on"]) + if settings["pd_mon_params"]["responsitivity"] is not None: + self.params[1].child('Photodiode Monitor Config', 'Responsitivity').setValue(settings["pd_mon_params"]["responsitivity"]) + else: + self.params[1].child('Photodiode Monitor Config', 'Responsitivity').setValue(0) + self.params[1].child('Photodiode Monitor Config', 'Dark Current').setValue(settings["pd_mon_params"]["i_dark"]) + except Exception as e: + logging.error(f"Params tree cannot be updated. Error:{e}. Data:{settings}") + + @asyncSlot(dict) + async def update_ld_ctrl_panel_readings(self, report): + try: + report = report['laser'] + with QSignalBlocker(self.params[0]): + self.params[0].child('Power').setValue('g' if report['pwr_on'] else 'w') + self.params[0].child('Alarm').setValue('r' if report['pwr_excursion'] else 'w') + + with QSignalBlocker(self.params[1]): + self.params[1].child('Readings', 'LD Current Set').setValue(report["ld_i_set"]) + self.params[1].child('Readings', 'PD Current').setValue(report["pd_i"]) + if report["pd_pwr"] is not None: + self.params[1].child('Readings', 'PD Power').setValue(report["pd_pwr"]) + else: + self.params[1].child('Readings', 'PD Power').setValue(0) + self.params[1].child('Readings', 'LF Mod Impedance').setValue(report["term_status"]) + except Exception as e: + logging.error(f"Params tree cannot be updated. Error:{e}. Data:{report}") + + @asyncSlot(dict) + async def update_thermostat_ctrl_panel_settings(self, settings): + try: + settings = settings['thermostat'] + with QSignalBlocker(self.params[3]): + self.params[3].child('Output Config', 'Control Method').setValue("Temperature PID" if settings["pid_engaged"] else "Constant Current") + self.params[3].child('Output Config', 'Control Method', 'Set Current').setValue(settings["tec_settings"]['i_set']['value']) + self.params[3].child('Output Config', 'Control Method', 'Set Temperature').setValue(float(settings["temperature_setpoint"])) + self.params[3].child('Output Config', 'Limits', 'Max Cooling Current').setValue(settings["tec_settings"]['max_i_pos']['value']) + self.params[3].child('Output Config', 'Limits', 'Max Heating Current').setValue(settings["tec_settings"]['max_i_neg']['value']) + self.params[3].child('Output Config', 'Limits', 'Max Voltage Difference').setValue(settings["tec_settings"]['max_v']['value']) + self.params[3].child('Output Config', 'Default Power On').setValue(settings["default_pwr_on"]) + # TODO: Update the Temperature ADC Settings here as well + self.params[3].child('Temperature Monitor Config', 'Upper Limit').setValue(settings["temp_mon_settings"]['upper_limit']) + self.params[3].child('Temperature Monitor Config', 'Lower Limit').setValue(settings["temp_mon_settings"]['lower_limit']) + self.params[3].child('PID Config', 'Kp').setValue(settings["pid_params"]['kp']) + self.params[3].child('PID Config', 'Ki').setValue(settings["pid_params"]['ki']) + self.params[3].child('PID Config', 'Kd').setValue(settings["pid_params"]['kd']) + self.params[3].child('PID Config', 'PID Output Clamping', 'Minimum').setValue(settings["pid_params"]['output_min']) + self.params[3].child('PID Config', 'PID Output Clamping', 'Maximum').setValue(settings["pid_params"]['output_max']) + self.params[3].child('Thermistor Settings', 'T₀').setValue(settings["thermistor_params"]['t0']) + self.params[3].child('Thermistor Settings', 'R₀').setValue(settings["thermistor_params"]['r0']) + self.params[3].child('Thermistor Settings', 'B').setValue(settings["thermistor_params"]['b']) + self.graphs.set_temp_setpoint_line(temp=round(settings["temperature_setpoint"], 6)) + self.graphs.set_temp_setpoint_line(visible=settings['pid_engaged']) + except Exception as e: + logging.error(f"Params tree cannot be updated. Error:{e}. Data:{settings}") + + @asyncSlot(dict) + async def update_thermostat_ctrl_panel_readings(self, report): + try: + report = report['thermostat'] + with QSignalBlocker(self.params[2]): + self.params[2].child('Power').setValue('g' if report['pwr_on'] else 'w') + self.params[2].child('Alarm').setValue('r' if report['temp_mon_status']['over_temp_alarm'] else 'w') + with QSignalBlocker(self.params[3]): + self.params[3].child('Readings', 'Temperature').setValue(report["temperature"]) + self.params[3].child('Readings', 'Current through TEC').setValue(report["tec_i"]) + except Exception as e: + logging.error(f"Params tree cannot be updated. Error:{e}. Data:{report}") + + @pyqtSlot(int) + def set_max_samples(self, samples: int): + self.graphs.set_max_samples(samples) + + @asyncSlot(int) + async def on_report_box_stateChanged(self, enabled): + await self.kirdy_data_watcher.set_report_mode(enabled) + + @asyncSlot() + async def on_connect_btn_clicked(self): + host, port = self.host_set_line.text(), self.port_set_spin.value() + try: + if not (self.kirdy.connecting() or self.kirdy.connected()): + self.status_lbl.setText("Connecting...") + self.connect_btn.setText("Stop") + self.host_set_line.setEnabled(False) + self.port_set_spin.setEnabled(False) + + try: + await self.kirdy.start_session(host=host, port=port, timeout=0.1) + except StoppedConnecting: + return + await self._on_connection_changed(True) + else: + await self.bail() + + except (OSError, TimeoutError) as e: + logging.error(f"Failed communicating to {host}:{port}: {e}") + await self.bail() + + @asyncSlot() + async def bail(self): + await self._on_connection_changed(False) + await self.kirdy.end_session() + + @asyncSlot(object, object) + async def send_command(self, param, changes): + for inner_param, change, data in changes: + if change == 'value': + """ cmd translation from mutex type parameter """ + if inner_param.opts.get('target_action_pair', None) is not None: + target, action = inner_param.opts['target_action_pair'][inner_param.opts['limits'].index(data)] + cmd = getattr(getattr(self.kirdy, target), action) + await cmd() + continue + """ cmd translation from non-mutex type parameter""" + if inner_param.opts.get("target", None) is not None: + if inner_param.opts.get("action", None) is not None: + cmd = getattr(getattr(self.kirdy, inner_param.opts["target"]), inner_param.opts["action"]) + await cmd(data) + continue + +async def coro_main(): + args = get_argparser().parse_args() + if args.logLevel: + logging.basicConfig(level=getattr(logging, args.logLevel)) + + app_quit_event = asyncio.Event() + + app = QtWidgets.QApplication.instance() + app.aboutToQuit.connect(app_quit_event.set) + + main_window = MainWindow(args) + main_window.show() + + await app_quit_event.wait() + +def main(): + qasync.run(coro_main()) + + +if __name__ == '__main__': + main() diff --git a/pykirdy/kirdy_qt.ui b/pykirdy/kirdy_qt.ui new file mode 100644 index 0000000..d58e42c --- /dev/null +++ b/pykirdy/kirdy_qt.ui @@ -0,0 +1,762 @@ + + + MainWindow + + + + 0 + 0 + 1280 + 720 + + + + + 1280 + 720 + + + + + 3840 + 2160 + + + + Kirdy Control Panel + + + + + + + + 1 + 1 + + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + 0 + + + + + 0 + + + QLayout::SetDefaultConstraint + + + + + 0 + + + QLayout::SetMaximumSize + + + + + + 14 + true + + + + Laser Diode + + + false + + + 0 + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 55 + + + + + + + + false + + + + + + + 30 + + + 10 + + + 10 + + + + + false + + + POWER ON + + + + + + + false + + + POWER OFF + + + + + + + false + + + CLEAR ALARM + + + + + + + + + + 14 + true + + + + Thermostat + + + false + + + 0 + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 55 + + + + + + + + false + + + + + + + 30 + + + 10 + + + 10 + + + + + false + + + POWER ON + + + + + + + false + + + POWER OFF + + + + + + + false + + + CLEAR ALAM + + + + + + + + + + + QLayout::SetNoConstraint + + + 0 + + + + + false + + + + + + + false + + + + + + + false + + + + + + + false + + + + + + + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 16777215 + 40 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + + 100 + 0 + + + + Connect + + + QToolButton::MenuButtonPopup + + + Qt::ToolButtonFollowStyle + + + + + + + + 0 + 0 + + + + + 240 + 0 + + + + + 120 + 16777215 + + + + + 120 + 50 + + + + Disconnected + + + + + + + false + + + + + + QToolButton::InstantPopup + + + + + + + Plot Settings + + + 📉 + + + QToolButton::InstantPopup + + + + + + + 1000000000 + + + + + + + Ready. + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 10 + + + 10 + + + 10 + + + + + false + + + Save Settings to Flash + + + + + + + false + + + Load Settings from Flash + + + + + + + + + false + + + + 0 + 0 + + + + + 40 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 6 + + + QLayout::SetDefaultConstraint + + + 0 + + + + + Poll every: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + + 0 + 0 + + + + + 70 + 0 + + + + + 70 + 16777215 + + + + + 70 + 0 + + + + s + + + 1 + + + 0.100000000000000 + + + 0.100000000000000 + + + QAbstractSpinBox::AdaptiveDecimalStepType + + + 1.000000000000000 + + + + + + + false + + + + 0 + 0 + + + + + 80 + 16777215 + + + + + 80 + 0 + + + + Report + + + + + + + false + + + + 0 + 0 + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + + 80 + 0 + + + + Apply + + + + + + + + + + + + + + + + + + + + Reset + + + Reset the Kirdy + + + QAction::NoRole + + + + + Enter DFU Mode + + + Reset kirdy and enter USB device firmware update (DFU) mode + + + QAction::NoRole + + + + + Network Settings + + + Configure IPv4 address, netmask length, and optional default gateway + + + QAction::NoRole + + + + + About Kirdy + + + Show Kirdy hardware revision, and settings related to i + + + QAction::NoRole + + + + + Load all channel configs from flash + + + Restore configuration for all channels from flash + + + QAction::NoRole + + + + + Save all channel configs to flash + + + Save configuration for all channels to flash + + + QAction::NoRole + + + + + + ParameterTree + QWidget +
pyqtgraph.parametertree
+ 1 +
+ + LivePlotWidget + QWidget +
pglive.sources.live_plot_widget
+ 1 +
+ + QtWaitingSpinner + QWidget +
waitingspinnerwidget
+ 1 +
+
+ + +
diff --git a/pykirdy/ui_kirdy_qt.py b/pykirdy/ui_kirdy_qt.py new file mode 100644 index 0000000..5863269 --- /dev/null +++ b/pykirdy/ui_kirdy_qt.py @@ -0,0 +1,368 @@ +# Form implementation generated from reading ui file 'kirdy_qt.ui' +# +# Created by: PyQt6 UI code generator 6.6.0 +# +# WARNING: Any manual changes made to this file will be lost when pyuic6 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt6 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(1280, 720) + MainWindow.setMinimumSize(QtCore.QSize(1280, 720)) + MainWindow.setMaximumSize(QtCore.QSize(3840, 2160)) + icon = QtGui.QIcon.fromTheme("application-x-executable") + MainWindow.setWindowIcon(icon) + self.main_widget = QtWidgets.QWidget(parent=MainWindow) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(1) + sizePolicy.setVerticalStretch(1) + sizePolicy.setHeightForWidth(self.main_widget.sizePolicy().hasHeightForWidth()) + self.main_widget.setSizePolicy(sizePolicy) + self.main_widget.setObjectName("main_widget") + self.gridLayout_2 = QtWidgets.QGridLayout(self.main_widget) + self.gridLayout_2.setContentsMargins(3, 3, 3, 3) + self.gridLayout_2.setSpacing(3) + self.gridLayout_2.setObjectName("gridLayout_2") + self.main_layout = QtWidgets.QVBoxLayout() + self.main_layout.setSpacing(0) + self.main_layout.setObjectName("main_layout") + self.horizontalLayout = QtWidgets.QHBoxLayout() + self.horizontalLayout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetDefaultConstraint) + self.horizontalLayout.setSpacing(0) + self.horizontalLayout.setObjectName("horizontalLayout") + self.ctrl_vertical_layout = QtWidgets.QVBoxLayout() + self.ctrl_vertical_layout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetMaximumSize) + self.ctrl_vertical_layout.setSpacing(0) + self.ctrl_vertical_layout.setObjectName("ctrl_vertical_layout") + self.ld_section_label = QtWidgets.QLabel(parent=self.main_widget) + font = QtGui.QFont() + font.setPointSize(14) + font.setBold(True) + self.ld_section_label.setFont(font) + self.ld_section_label.setWordWrap(False) + self.ld_section_label.setObjectName("ld_section_label") + self.ctrl_vertical_layout.addWidget(self.ld_section_label) + self.ld_status = ParameterTree(parent=self.main_widget) + self.ld_status.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.ld_status.sizePolicy().hasHeightForWidth()) + self.ld_status.setSizePolicy(sizePolicy) + self.ld_status.setMaximumSize(QtCore.QSize(16777215, 55)) + self.ld_status.setObjectName("ld_status") + self.ctrl_vertical_layout.addWidget(self.ld_status) + self.ld_tree = ParameterTree(parent=self.main_widget) + self.ld_tree.setEnabled(False) + self.ld_tree.setObjectName("ld_tree") + self.ctrl_vertical_layout.addWidget(self.ld_tree) + self.ld_btns_layout = QtWidgets.QHBoxLayout() + self.ld_btns_layout.setContentsMargins(10, -1, 10, -1) + self.ld_btns_layout.setSpacing(30) + self.ld_btns_layout.setObjectName("ld_btns_layout") + self.ld_pwr_on_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.ld_pwr_on_btn.setEnabled(False) + self.ld_pwr_on_btn.setObjectName("ld_pwr_on_btn") + self.ld_btns_layout.addWidget(self.ld_pwr_on_btn) + self.ld_pwr_off_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.ld_pwr_off_btn.setEnabled(False) + self.ld_pwr_off_btn.setObjectName("ld_pwr_off_btn") + self.ld_btns_layout.addWidget(self.ld_pwr_off_btn) + self.ld_clear_alarm_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.ld_clear_alarm_btn.setEnabled(False) + self.ld_clear_alarm_btn.setObjectName("ld_clear_alarm_btn") + self.ld_btns_layout.addWidget(self.ld_clear_alarm_btn) + self.ctrl_vertical_layout.addLayout(self.ld_btns_layout) + self.tec_section_label = QtWidgets.QLabel(parent=self.main_widget) + font = QtGui.QFont() + font.setPointSize(14) + font.setBold(True) + self.tec_section_label.setFont(font) + self.tec_section_label.setWordWrap(False) + self.tec_section_label.setObjectName("tec_section_label") + self.ctrl_vertical_layout.addWidget(self.tec_section_label) + self.tec_status = ParameterTree(parent=self.main_widget) + self.tec_status.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.tec_status.sizePolicy().hasHeightForWidth()) + self.tec_status.setSizePolicy(sizePolicy) + self.tec_status.setMaximumSize(QtCore.QSize(16777215, 55)) + self.tec_status.setObjectName("tec_status") + self.ctrl_vertical_layout.addWidget(self.tec_status) + self.tec_tree = ParameterTree(parent=self.main_widget) + self.tec_tree.setEnabled(False) + self.tec_tree.setObjectName("tec_tree") + self.ctrl_vertical_layout.addWidget(self.tec_tree) + self.tec_btns_layout = QtWidgets.QHBoxLayout() + self.tec_btns_layout.setContentsMargins(10, -1, 10, -1) + self.tec_btns_layout.setSpacing(30) + self.tec_btns_layout.setObjectName("tec_btns_layout") + self.tec_pwr_on_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.tec_pwr_on_btn.setEnabled(False) + self.tec_pwr_on_btn.setObjectName("tec_pwr_on_btn") + self.tec_btns_layout.addWidget(self.tec_pwr_on_btn) + self.tec_pwr_off_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.tec_pwr_off_btn.setEnabled(False) + self.tec_pwr_off_btn.setObjectName("tec_pwr_off_btn") + self.tec_btns_layout.addWidget(self.tec_pwr_off_btn) + self.tec_clear_alarm_btn = QtWidgets.QPushButton(parent=self.main_widget) + self.tec_clear_alarm_btn.setEnabled(False) + self.tec_clear_alarm_btn.setObjectName("tec_clear_alarm_btn") + self.tec_btns_layout.addWidget(self.tec_clear_alarm_btn) + self.ctrl_vertical_layout.addLayout(self.tec_btns_layout) + self.ctrl_vertical_layout.setStretch(0, 1) + self.ctrl_vertical_layout.setStretch(1, 1) + self.ctrl_vertical_layout.setStretch(2, 10) + self.ctrl_vertical_layout.setStretch(3, 1) + self.ctrl_vertical_layout.setStretch(4, 1) + self.ctrl_vertical_layout.setStretch(5, 1) + self.ctrl_vertical_layout.setStretch(6, 10) + self.ctrl_vertical_layout.setStretch(7, 1) + self.horizontalLayout.addLayout(self.ctrl_vertical_layout) + self.graphgroup = QtWidgets.QGridLayout() + self.graphgroup.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetNoConstraint) + self.graphgroup.setSpacing(0) + self.graphgroup.setObjectName("graphgroup") + self.tec_temp_graph = LivePlotWidget(parent=self.main_widget) + self.tec_temp_graph.setEnabled(False) + self.tec_temp_graph.setObjectName("tec_temp_graph") + self.graphgroup.addWidget(self.tec_temp_graph, 1, 0, 1, 1) + self.tec_i_graph = LivePlotWidget(parent=self.main_widget) + self.tec_i_graph.setEnabled(False) + self.tec_i_graph.setObjectName("tec_i_graph") + self.graphgroup.addWidget(self.tec_i_graph, 1, 2, 1, 1) + self.pd_mon_pwr_graph = LivePlotWidget(parent=self.main_widget) + self.pd_mon_pwr_graph.setEnabled(False) + self.pd_mon_pwr_graph.setObjectName("pd_mon_pwr_graph") + self.graphgroup.addWidget(self.pd_mon_pwr_graph, 0, 0, 1, 1) + self.ld_i_set_graph = LivePlotWidget(parent=self.main_widget) + self.ld_i_set_graph.setEnabled(False) + self.ld_i_set_graph.setObjectName("ld_i_set_graph") + self.graphgroup.addWidget(self.ld_i_set_graph, 0, 2, 1, 1) + self.horizontalLayout.addLayout(self.graphgroup) + self.horizontalLayout.setStretch(0, 1) + self.horizontalLayout.setStretch(1, 2) + self.main_layout.addLayout(self.horizontalLayout) + self.bottom_settings_group = QtWidgets.QFrame(parent=self.main_widget) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.bottom_settings_group.sizePolicy().hasHeightForWidth()) + self.bottom_settings_group.setSizePolicy(sizePolicy) + self.bottom_settings_group.setMinimumSize(QtCore.QSize(0, 40)) + self.bottom_settings_group.setMaximumSize(QtCore.QSize(16777215, 40)) + self.bottom_settings_group.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) + self.bottom_settings_group.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) + self.bottom_settings_group.setObjectName("bottom_settings_group") + self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.bottom_settings_group) + self.horizontalLayout_2.setContentsMargins(3, 3, 3, 3) + self.horizontalLayout_2.setSpacing(3) + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.settings_layout = QtWidgets.QHBoxLayout() + self.settings_layout.setObjectName("settings_layout") + self.connect_btn = QtWidgets.QToolButton(parent=self.bottom_settings_group) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.connect_btn.sizePolicy().hasHeightForWidth()) + self.connect_btn.setSizePolicy(sizePolicy) + self.connect_btn.setMinimumSize(QtCore.QSize(100, 0)) + self.connect_btn.setMaximumSize(QtCore.QSize(100, 16777215)) + self.connect_btn.setBaseSize(QtCore.QSize(100, 0)) + self.connect_btn.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.MenuButtonPopup) + self.connect_btn.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonFollowStyle) + self.connect_btn.setObjectName("connect_btn") + self.settings_layout.addWidget(self.connect_btn) + self.status_lbl = QtWidgets.QLabel(parent=self.bottom_settings_group) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.status_lbl.sizePolicy().hasHeightForWidth()) + self.status_lbl.setSizePolicy(sizePolicy) + self.status_lbl.setMinimumSize(QtCore.QSize(240, 0)) + self.status_lbl.setMaximumSize(QtCore.QSize(120, 16777215)) + self.status_lbl.setBaseSize(QtCore.QSize(120, 50)) + self.status_lbl.setObjectName("status_lbl") + self.settings_layout.addWidget(self.status_lbl) + self.kirdy_settings = QtWidgets.QToolButton(parent=self.bottom_settings_group) + self.kirdy_settings.setEnabled(False) + self.kirdy_settings.setText("⚙") + self.kirdy_settings.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.InstantPopup) + self.kirdy_settings.setObjectName("kirdy_settings") + self.settings_layout.addWidget(self.kirdy_settings) + self.plot_settings = QtWidgets.QToolButton(parent=self.bottom_settings_group) + self.plot_settings.setPopupMode(QtWidgets.QToolButton.ToolButtonPopupMode.InstantPopup) + self.plot_settings.setObjectName("plot_settings") + self.settings_layout.addWidget(self.plot_settings) + self.limits_warning = QtWidgets.QLabel(parent=self.bottom_settings_group) + self.limits_warning.setToolTipDuration(1000000000) + self.limits_warning.setObjectName("limits_warning") + self.settings_layout.addWidget(self.limits_warning) + self.background_task_lbl = QtWidgets.QLabel(parent=self.bottom_settings_group) + self.background_task_lbl.setObjectName("background_task_lbl") + self.settings_layout.addWidget(self.background_task_lbl) + self.loading_spinner = QtWaitingSpinner(parent=self.bottom_settings_group) + self.loading_spinner.setObjectName("loading_spinner") + self.settings_layout.addWidget(self.loading_spinner) + spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) + self.settings_layout.addItem(spacerItem) + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setContentsMargins(10, -1, 10, -1) + self.horizontalLayout_3.setSpacing(10) + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.save_flash_btn = QtWidgets.QPushButton(parent=self.bottom_settings_group) + self.save_flash_btn.setEnabled(False) + self.save_flash_btn.setObjectName("save_flash_btn") + self.horizontalLayout_3.addWidget(self.save_flash_btn) + self.load_flash_btn = QtWidgets.QPushButton(parent=self.bottom_settings_group) + self.load_flash_btn.setEnabled(False) + self.load_flash_btn.setObjectName("load_flash_btn") + self.horizontalLayout_3.addWidget(self.load_flash_btn) + self.settings_layout.addLayout(self.horizontalLayout_3) + self.report_group = QtWidgets.QWidget(parent=self.bottom_settings_group) + self.report_group.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.report_group.sizePolicy().hasHeightForWidth()) + self.report_group.setSizePolicy(sizePolicy) + self.report_group.setMinimumSize(QtCore.QSize(40, 0)) + self.report_group.setObjectName("report_group") + self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.report_group) + self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) + self.horizontalLayout_4.setSpacing(0) + self.horizontalLayout_4.setObjectName("horizontalLayout_4") + self.report_layout = QtWidgets.QHBoxLayout() + self.report_layout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetDefaultConstraint) + self.report_layout.setContentsMargins(0, -1, -1, -1) + self.report_layout.setSpacing(6) + self.report_layout.setObjectName("report_layout") + self.report_lbl = QtWidgets.QLabel(parent=self.report_group) + self.report_lbl.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) + self.report_lbl.setObjectName("report_lbl") + self.report_layout.addWidget(self.report_lbl) + self.report_refresh_spin = QtWidgets.QDoubleSpinBox(parent=self.report_group) + self.report_refresh_spin.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.report_refresh_spin.sizePolicy().hasHeightForWidth()) + self.report_refresh_spin.setSizePolicy(sizePolicy) + self.report_refresh_spin.setMinimumSize(QtCore.QSize(70, 0)) + self.report_refresh_spin.setMaximumSize(QtCore.QSize(70, 16777215)) + self.report_refresh_spin.setBaseSize(QtCore.QSize(70, 0)) + self.report_refresh_spin.setDecimals(1) + self.report_refresh_spin.setMinimum(0.1) + self.report_refresh_spin.setSingleStep(0.1) + self.report_refresh_spin.setStepType(QtWidgets.QAbstractSpinBox.StepType.AdaptiveDecimalStepType) + self.report_refresh_spin.setProperty("value", 1.0) + self.report_refresh_spin.setObjectName("report_refresh_spin") + self.report_layout.addWidget(self.report_refresh_spin) + self.report_box = QtWidgets.QCheckBox(parent=self.report_group) + self.report_box.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.report_box.sizePolicy().hasHeightForWidth()) + self.report_box.setSizePolicy(sizePolicy) + self.report_box.setMaximumSize(QtCore.QSize(80, 16777215)) + self.report_box.setBaseSize(QtCore.QSize(80, 0)) + self.report_box.setObjectName("report_box") + self.report_layout.addWidget(self.report_box) + self.report_apply_btn = QtWidgets.QPushButton(parent=self.report_group) + self.report_apply_btn.setEnabled(False) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.report_apply_btn.sizePolicy().hasHeightForWidth()) + self.report_apply_btn.setSizePolicy(sizePolicy) + self.report_apply_btn.setMinimumSize(QtCore.QSize(80, 0)) + self.report_apply_btn.setMaximumSize(QtCore.QSize(80, 16777215)) + self.report_apply_btn.setBaseSize(QtCore.QSize(80, 0)) + self.report_apply_btn.setObjectName("report_apply_btn") + self.report_layout.addWidget(self.report_apply_btn) + self.report_layout.setStretch(1, 1) + self.report_layout.setStretch(2, 1) + self.report_layout.setStretch(3, 1) + self.horizontalLayout_4.addLayout(self.report_layout) + self.settings_layout.addWidget(self.report_group) + self.horizontalLayout_2.addLayout(self.settings_layout) + self.main_layout.addWidget(self.bottom_settings_group) + self.gridLayout_2.addLayout(self.main_layout, 0, 0, 1, 1) + MainWindow.setCentralWidget(self.main_widget) + self.actionReset = QtGui.QAction(parent=MainWindow) + self.actionReset.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionReset.setObjectName("actionReset") + self.actionEnter_DFU_Mode = QtGui.QAction(parent=MainWindow) + self.actionEnter_DFU_Mode.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionEnter_DFU_Mode.setObjectName("actionEnter_DFU_Mode") + self.actionNetwork_Settings = QtGui.QAction(parent=MainWindow) + self.actionNetwork_Settings.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionNetwork_Settings.setObjectName("actionNetwork_Settings") + self.actionAbout_Kirdy = QtGui.QAction(parent=MainWindow) + self.actionAbout_Kirdy.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionAbout_Kirdy.setObjectName("actionAbout_Kirdy") + self.actionLoad_all_configs = QtGui.QAction(parent=MainWindow) + self.actionLoad_all_configs.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionLoad_all_configs.setObjectName("actionLoad_all_configs") + self.actionSave_all_configs = QtGui.QAction(parent=MainWindow) + self.actionSave_all_configs.setMenuRole(QtGui.QAction.MenuRole.NoRole) + self.actionSave_all_configs.setObjectName("actionSave_all_configs") + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "Kirdy Control Panel")) + self.ld_section_label.setText(_translate("MainWindow", " Laser Diode")) + self.ld_pwr_on_btn.setText(_translate("MainWindow", "POWER ON")) + self.ld_pwr_off_btn.setText(_translate("MainWindow", "POWER OFF")) + self.ld_clear_alarm_btn.setText(_translate("MainWindow", "CLEAR ALARM")) + self.tec_section_label.setText(_translate("MainWindow", " Thermostat")) + self.tec_pwr_on_btn.setText(_translate("MainWindow", "POWER ON")) + self.tec_pwr_off_btn.setText(_translate("MainWindow", "POWER OFF")) + self.tec_clear_alarm_btn.setText(_translate("MainWindow", "CLEAR ALAM")) + self.connect_btn.setText(_translate("MainWindow", "Connect")) + self.status_lbl.setText(_translate("MainWindow", "Disconnected")) + self.plot_settings.setToolTip(_translate("MainWindow", "Plot Settings")) + self.plot_settings.setText(_translate("MainWindow", "📉")) + self.background_task_lbl.setText(_translate("MainWindow", "Ready.")) + self.save_flash_btn.setText(_translate("MainWindow", "Save Settings to Flash")) + self.load_flash_btn.setText(_translate("MainWindow", "Load Settings from Flash")) + self.report_lbl.setText(_translate("MainWindow", "Poll every: ")) + self.report_refresh_spin.setSuffix(_translate("MainWindow", " s")) + self.report_box.setText(_translate("MainWindow", "Report")) + self.report_apply_btn.setText(_translate("MainWindow", "Apply")) + self.actionReset.setText(_translate("MainWindow", "Reset")) + self.actionReset.setToolTip(_translate("MainWindow", "Reset the Kirdy")) + self.actionEnter_DFU_Mode.setText(_translate("MainWindow", "Enter DFU Mode")) + self.actionEnter_DFU_Mode.setToolTip(_translate("MainWindow", "Reset kirdy and enter USB device firmware update (DFU) mode")) + self.actionNetwork_Settings.setText(_translate("MainWindow", "Network Settings")) + self.actionNetwork_Settings.setToolTip(_translate("MainWindow", "Configure IPv4 address, netmask length, and optional default gateway")) + self.actionAbout_Kirdy.setText(_translate("MainWindow", "About Kirdy")) + self.actionAbout_Kirdy.setToolTip(_translate("MainWindow", "Show Kirdy hardware revision, and settings related to i")) + self.actionLoad_all_configs.setText(_translate("MainWindow", "Load all channel configs from flash")) + self.actionLoad_all_configs.setToolTip(_translate("MainWindow", "Restore configuration for all channels from flash")) + self.actionSave_all_configs.setText(_translate("MainWindow", "Save all channel configs to flash")) + self.actionSave_all_configs.setToolTip(_translate("MainWindow", "Save configuration for all channels to flash")) +from pglive.sources.live_plot_widget import LivePlotWidget +from pyqtgraph.parametertree import ParameterTree +from waitingspinnerwidget import QtWaitingSpinner + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + MainWindow = QtWidgets.QMainWindow() + ui = Ui_MainWindow() + ui.setupUi(MainWindow) + MainWindow.show() + sys.exit(app.exec())