From c2b417ed181d6a1cf8f577546c19e3f212c2e1c1 Mon Sep 17 00:00:00 2001 From: ralajan Date: Wed, 2 Oct 2024 13:44:53 +0200 Subject: [PATCH 1/3] enh: replace findText with findData of comboBox_visc_model --- CHANGELOG | 1 + shapeout2/gui/analysis/ana_slot.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 650b795..7f43b5c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ 2.18.2 + - enh: replace findText with findData of comboBox_visc_model - fix: allow to select R binary when not found automatically - enh: enable lut selection for emodulus computation in bulk actions (#71) - enh: enable lut selection for emodulus computation (#71) diff --git a/shapeout2/gui/analysis/ana_slot.py b/shapeout2/gui/analysis/ana_slot.py index 11afcd8..1c1a085 100644 --- a/shapeout2/gui/analysis/ana_slot.py +++ b/shapeout2/gui/analysis/ana_slot.py @@ -45,6 +45,7 @@ def __init__(self, *args, **kwargs): self._update_emodulus_medium_choices() self._update_emodulus_temp_choices() self._update_emodulus_lut_choices() + self._update_emodulus_visc_model_choices() self.update_content() @@ -63,7 +64,7 @@ def __getstate__(self): else: # "other", user-defined medium emod_visc = self.doubleSpinBox_visc.value() # user input scenario = None - emod_visc_model = self.comboBox_visc_model.currentText() + emod_visc_model = self.comboBox_visc_model.currentData() emod_select_lut = self.comboBox_lut.currentText() state = { "identifier": slot_state["identifier"], @@ -139,11 +140,11 @@ def __setstate__(self, state): self.comboBox_temp.blockSignals(True) self.comboBox_temp.setCurrentIndex(idx_scen) self.comboBox_temp.blockSignals(False) - idx_vm = self.comboBox_visc_model.findText( - emodulus.get("emodulus viscosity model", "")) - if idx_vm == -1: + + idx_vm = self.comboBox_visc_model.findData( # use defaults from previous session (Herold-2107) - idx_vm = 1 + emodulus.get("emodulus viscosity model", "herold-2017")) + self.comboBox_visc_model.setCurrentIndex(idx_vm) # Set current state of the emodulus lut idx_lut = self.comboBox_lut.findData(emodulus.get("emodulus lut", "")) @@ -284,6 +285,20 @@ def _update_emodulus_lut_choices(self): self.comboBox_lut.setCurrentIndex(idx) self.comboBox_lut.blockSignals(False) + def _update_emodulus_visc_model_choices(self): + """update currently available viscosity model choices for YM + + Signals are blocked. + """ + self.comboBox_visc_model.blockSignals(True) + self.comboBox_visc_model.clear() + + choices = {"Herold (2017)": "herold-2017", + "Buyukurganci (2022)": "buyukurganci-2022"} + for name, data in choices: + self.comboBox_visc_model.addItem(name, data) + self.comboBox_visc_model.blockSignals(False) + @property def current_slot_state(self): if self.slot_ids: @@ -369,7 +384,7 @@ def on_ui_changed(self): medium = self.comboBox_medium.currentData() tselec = self.comboBox_temp.currentData() medium_key = ALIAS_MEDIA.get(medium, medium) - visc_model = self.comboBox_visc_model.currentText() + visc_model = self.comboBox_visc_model.currentData() # Only show model selection if we are dealing with MC-PBS self.comboBox_visc_model.setVisible(medium_key.count("MC-PBS")) self.doubleSpinBox_visc.setStyleSheet("") From a842535e5e58645d97a8970165392e33092a3d5d Mon Sep 17 00:00:00 2001 From: ralajan Date: Wed, 2 Oct 2024 14:04:32 +0200 Subject: [PATCH 2/3] fix: reading dict keys and values properly --- shapeout2/gui/analysis/ana_slot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapeout2/gui/analysis/ana_slot.py b/shapeout2/gui/analysis/ana_slot.py index 1c1a085..1e745c3 100644 --- a/shapeout2/gui/analysis/ana_slot.py +++ b/shapeout2/gui/analysis/ana_slot.py @@ -295,7 +295,7 @@ def _update_emodulus_visc_model_choices(self): choices = {"Herold (2017)": "herold-2017", "Buyukurganci (2022)": "buyukurganci-2022"} - for name, data in choices: + for name, data in choices.items(): self.comboBox_visc_model.addItem(name, data) self.comboBox_visc_model.blockSignals(False) From c3eee7e60750b7ed6f28d164e3cf5930e28f5f46 Mon Sep 17 00:00:00 2001 From: ralajan Date: Wed, 2 Oct 2024 14:04:59 +0200 Subject: [PATCH 3/3] test: replace findText with findData --- tests/test_gui_emodulus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_gui_emodulus.py b/tests/test_gui_emodulus.py index 046227d..8cc334e 100644 --- a/tests/test_gui_emodulus.py +++ b/tests/test_gui_emodulus.py @@ -285,7 +285,7 @@ def test_changeable_lut_selection(qtbot): assert wsl.comboBox_medium.currentData() == "CellCarrier" # set viscosity model manually - idvm = wsl.comboBox_visc_model.findText("buyukurganci-2022") + idvm = wsl.comboBox_visc_model.findData("buyukurganci-2022") wsl.comboBox_visc_model.setCurrentIndex(idvm) # set lut manually idlut = wsl.comboBox_lut.findData("HE-2D-FEM-22") @@ -315,7 +315,7 @@ def test_changeable_lut_selection(qtbot): ).config["calculation"]["emodulus lut"] == "HE-3D-FEM-22" # This is the actual test - assert wsl.comboBox_visc_model.currentText() == "buyukurganci-2022" + assert wsl.comboBox_visc_model.currentData() == "buyukurganci-2022" assert wsl.comboBox_lut.currentText() == "HE-3D-FEM-22" try: