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 import QtWidgets, QtGui, QtCore
|
||||||
from PyQt6.QtCore import pyqtSignal, QObject, QSignalBlocker, pyqtSlot
|
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
|
import pyqtgraph as pg
|
||||||
from pglive.sources.data_connector import DataConnector
|
from pglive.sources.data_connector import DataConnector
|
||||||
from pglive.kwargs import Axis
|
from pglive.kwargs import Axis
|
||||||
|
@ -32,6 +33,37 @@ def get_argparser():
|
||||||
return parser
|
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):
|
class WrappedClient(QObject, Client):
|
||||||
connection_error = pyqtSignal()
|
connection_error = pyqtSignal()
|
||||||
|
|
||||||
|
@ -128,7 +160,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
|
{'name': 'Temperature', 'type': 'float', 'siPrefix': True, 'suffix': '°C', 'readonly': True},
|
||||||
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
|
{'name': 'Current through TEC', 'type': 'float', 'siPrefix': True, 'suffix': 'A', 'readonly': True},
|
||||||
{'name': 'Output Config', 'expanded': True, 'type': 'group', 'children': [
|
{'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': [
|
'commands': [f'pwm {ch} pid'], 'children': [
|
||||||
{'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True,
|
{'name': 'Constant Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 3), 'siPrefix': True,
|
||||||
'suffix': 'A', 'param': [('pwm', ch, 'i_set')]},
|
'suffix': 'A', 'param': [('pwm', ch, 'i_set')]},
|
||||||
|
@ -586,6 +618,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
@asyncSlot(object, object)
|
@asyncSlot(object, object)
|
||||||
async def send_command(self, param, changes):
|
async def send_command(self, param, changes):
|
||||||
for inner_param, change, data in changes:
|
for inner_param, change, data in changes:
|
||||||
|
if change == 'value':
|
||||||
if inner_param.opts.get("commands", None) is not None:
|
if inner_param.opts.get("commands", None) is not None:
|
||||||
ch = param.value()
|
ch = param.value()
|
||||||
match inner_param.name():
|
match inner_param.name():
|
||||||
|
|
Loading…
Reference in New Issue