From f7c266539b6a24d7930ee85e005817f21c630427 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 18 Jul 2024 15:50:02 +0800 Subject: [PATCH] ctrl_panel: Code cleanup * Remove unnecessary duplication of `THERMOSTAT_PARAMETERS` * i -> ch * Separate ParameterTree and Parameter initiation * Remove extra "channel" option to root parameters, as the "value" option is already the channel number --- pytec/pytec/gui/view/ctrl_panel.py | 21 +++++++++------------ pytec/tec_qt.py | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pytec/pytec/gui/view/ctrl_panel.py b/pytec/pytec/gui/view/ctrl_panel.py index c98af87..c42330a 100644 --- a/pytec/pytec/gui/view/ctrl_panel.py +++ b/pytec/pytec/gui/view/ctrl_panel.py @@ -66,31 +66,28 @@ class CtrlPanel(QObject): self.trees_ui = trees_ui self.NUM_CHANNELS = len(trees_ui) - self.THERMOSTAT_PARAMETERS = [param_tree for i in range(self.NUM_CHANNELS)] - self.params = [ Parameter.create( name=f"Thermostat Channel {ch} Parameters", type="group", value=ch, - children=self.THERMOSTAT_PARAMETERS[ch], + children=param_tree, ) for ch in range(self.NUM_CHANNELS) ] - for i, param in enumerate(self.params): - param.channel = i - - for i, tree in enumerate(self.trees_ui): + for ch, tree in enumerate(self.trees_ui): tree.setHeaderHidden(True) - tree.setParameters(self.params[i], showTop=False) - self.params[i].setValue = self._setValue - self.params[i].sigTreeStateChanged.connect(sigTreeStateChanged_handle) + tree.setParameters(self.params[ch], showTop=False) set_tree_label_tips(tree) - for handle in sigActivated_handles[i]: - self.params[i].child(*handle[0]).sigActivated.connect(handle[1]) + for ch, param in enumerate(self.params): + self.params[ch].setValue = self._setValue + param.sigTreeStateChanged.connect(sigTreeStateChanged_handle) + + for handle in sigActivated_handles[ch]: + param.child(*handle[0]).sigActivated.connect(handle[1]) def _setValue(self, value, blockSignal=None): """ diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 1269467..af29936 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -262,7 +262,7 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(object, object) async def send_command(self, param, changes): """Translates parameter tree changes into thermostat set_param calls""" - ch = param.channel + ch = param.value() for inner_param, change, data in changes: if change == "value":