forked from M-Labs/thermostat
Only show either one or another, pid or not
This commit is contained in:
parent
7f7f749e84
commit
68124cd92b
|
@ -1,6 +1,7 @@
|
|||
from PyQt6 import QtWidgets, QtGui, QtCore
|
||||
from PyQt6.QtCore import pyqtSignal, QObject, QSignalBlocker, pyqtSlot
|
||||
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem
|
||||
import pyqtgraph.parametertree.parameterTypes as pTypes
|
||||
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType
|
||||
import pyqtgraph as pg
|
||||
from pglive.sources.data_connector import DataConnector
|
||||
from pglive.kwargs import Axis
|
||||
|
@ -32,6 +33,37 @@ def get_argparser():
|
|||
return parser
|
||||
|
||||
|
||||
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()
|
||||
|
||||
self._get_param_from_value(value.value()).show()
|
||||
|
||||
|
||||
registerParameterType('mutex', MutexParameter)
|
||||
|
||||
|
||||
class WrappedClient(QObject, Client):
|
||||
connection_error = pyqtSignal()
|
||||
|
||||
|
@ -128,7 +160,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
|
||||
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
|
||||
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
|
||||
{'name': 'Control Method', 'type': 'list', 'limits': {'Current Setpoint': False, 'Temperature PID': True},
|
||||
{'name': 'Control Method', 'type': 'mutex', 'limits': {'Current Setpoint': False, 'Temperature PID': True},
|
||||
'commands': [f'pwm {ch} pid'], 'children': [
|
||||
{'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True,
|
||||
'suffix': 'A', 'param': [('pwm', ch, 'i_set')]},
|
||||
|
@ -586,6 +618,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
@asyncSlot(object, object)
|
||||
async def send_command(self, param, changes):
|
||||
for inner_param, change, data in changes:
|
||||
if change == 'value':
|
||||
if inner_param.opts.get("commands", None) is not None:
|
||||
ch = param.value()
|
||||
match inner_param.name():
|
||||
|
|
Loading…
Reference in New Issue