gui: lock param tree value when user inputs a new value

- prevent user input from getting overwritten from incoming data
This commit is contained in:
linuswck 2024-06-11 15:03:09 +08:00
parent 0dceb8c3c6
commit f35546b070
1 changed files with 53 additions and 23 deletions

View File

@ -330,19 +330,19 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
]},
{'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'},
'suffix': 'A', 'siPrefix': True, 'lock': False, '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'},
'suffix': 'A', 'siPrefix': True, 'lock': False, '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'},
'suffix': 'W', 'siPrefix': True, 'lock': False, 'target': 'laser', 'action': 'set_ld_pwr_limit'},
{'name': 'LD Terminals Short', 'type': 'bool', 'value': False, 'lock': False, 'target': 'laser', 'action': 'set_ld_terms_short'},
{'name': 'Default Power On', 'type': 'bool', 'value': False, 'lock': 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'},
'suffix': 'A/W', 'siPrefix': True, 'lock': False, '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'},
'suffix': 'A', 'siPrefix': True, 'lock': False, 'target': 'laser', 'action': 'set_pd_mon_dark_current'},
]},
]
@ -360,41 +360,41 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
{'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'},
'decimals': 6, 'suffix': 'A', 'siPrefix': True, 'lock': False, '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'},
'format': '{value:.4f} °C', 'lock': False, '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'},
'suffix': 'A', 'siPrefix': True, 'lock': False, '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'},
'suffix': 'A', 'siPrefix': True, 'lock': False, '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'},
'suffix': 'V', 'siPrefix': True, 'lock': False, 'target': 'thermostat', 'action': 'set_tec_max_v'},
]},
{'name': 'Default Power On', 'type': 'bool', 'value': False, 'target': 'thermostat', 'action': 'set_default_pwr_on'},
{'name': 'Default Power On', 'type': 'bool', 'value': False, 'lock': 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'},
'suffix': '°C', 'lock': False, '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'},
'suffix': '°C', 'lock': False, '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'},
'suffix': '°C', 'lock': False, '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'},
'suffix': 'Ω', 'siPrefix': True, 'lock': False, 'target': 'thermostat', 'action': 'set_sh_r0'},
{'name': 'B', 'type': 'float', 'value': 3950, 'step': 1, 'suffix': 'K', 'decimals': 4, 'lock': False, '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': 'Kp', 'type': 'float', 'step': 0.1, 'suffix': '', 'lock': False, 'target': 'thermostat', 'action': 'set_pid_kp'},
{'name': 'Ki', 'type': 'float', 'step': 0.1, 'suffix': 'Hz', 'lock': False, 'target': 'thermostat', 'action': 'set_pid_ki'},
{'name': 'Kd', 'type': 'float', 'step': 0.1, 'suffix': 's', 'lock': False, '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'},
{'name': 'Minimum', 'type': 'float', 'step': 100, 'limits': (-1, 1), 'decimals': 6, 'suffix': 'A', 'lock': False, 'target': 'thermostat', 'action': 'set_pid_output_min'},
{'name': 'Maximum', 'type': 'float', 'step': 100, 'limits': (-1, 1), 'decimals': 6, 'suffix': 'A', 'lock': False, 'target': 'thermostat', 'action': 'set_pid_output_max'},
]},
# TODO PID AutoTune
]},
@ -581,6 +581,32 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.plot_settings.setMenu(self.plot_menu)
def _set_param_tree(self):
def _setValue(self, value, blockSignal=None):
"""
Implement 'lock' mechanism for Parameter Type
Modified from the source
"""
try:
if blockSignal is not None:
self.sigValueChanged.disconnect(blockSignal)
value = self._interpretValue(value)
if fn.eq(self.opts["value"], value):
return value
if "lock" in self.opts.keys():
if self.opts["lock"]:
return value
self.opts["value"] = value
self.sigValueChanged.emit(
self, value
) # value might change after signal is received by tree item
finally:
if blockSignal is not None:
self.sigValueChanged.connect(blockSignal)
return self.opts["value"]
status = self.ld_status
status.setHeaderHidden(True)
status.setParameters(self.params[0], showTop=False)
@ -589,6 +615,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
tree.setHeaderHidden(True)
tree.setParameters(self.params[1], showTop=False)
self.params[1].sigTreeStateChanged.connect(self.send_command)
self.params[1].setValue = _setValue
status = self.tec_status
status.setHeaderHidden(True)
@ -598,6 +625,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
tree.setHeaderHidden(True)
tree.setParameters(self.params[3], showTop=False)
self.params[3].sigTreeStateChanged.connect(self.send_command)
self.params[3].setValue = _setValue
async def _on_connection_changed(self, result, hard_reset=False):
def ctrl_panel_setEnable(result):
@ -808,7 +836,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
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)
param.child(*param.childPath(inner_param)).setOpts(lock=True)
await cmd()
param.child(*param.childPath(inner_param)).setOpts(lock=False)
continue
""" cmd translation from non-mutex type parameter"""
if inner_param.opts.get("target", None) is not None: