From 4a7a949918d4c749a19be214afcf8f54073a7344 Mon Sep 17 00:00:00 2001 From: Brianna Major Date: Thu, 9 Jan 2025 16:50:36 -0500 Subject: [PATCH] Allow users to disable detector coating, filter or phosphor Signed-off-by: Brianna Major --- .../absorption_correction_options_dialog.py | 43 ++++++++++++++++- hexrdgui/hexrd_config.py | 6 ++- .../absorption_correction_options_dialog.ui | 48 ++++++++++++++++--- 3 files changed, 87 insertions(+), 10 deletions(-) diff --git a/hexrdgui/absorption_correction_options_dialog.py b/hexrdgui/absorption_correction_options_dialog.py index 5fa5bc13c..a2e13ae33 100644 --- a/hexrdgui/absorption_correction_options_dialog.py +++ b/hexrdgui/absorption_correction_options_dialog.py @@ -79,6 +79,7 @@ def update_gui(self): self.ui.filter_material.setCurrentText(filter.material) self.ui.filter_density.setValue(filter.density) self.ui.filter_thickness.setValue(filter.thickness) + self.ui.apply_filters.setChecked(filter.thickness > 0) # COATING if coating.material not in self.mat_options: self.ui.coating_material_input.setText(coating.material) @@ -86,6 +87,7 @@ def update_gui(self): self.ui.coating_material.setCurrentText(coating.material) self.ui.coating_density.setValue(coating.density) self.ui.coating_thickness.setValue(coating.thickness) + self.ui.apply_coating.setChecked(coating.thickness > 0) # PHOSPHOR if phosphor.material not in self.mat_options: self.ui.phosphor_material_input.setText(phosphor.material) @@ -93,6 +95,7 @@ def update_gui(self): self.ui.phosphor_material.setCurrentText(phosphor.material) self.ui.phosphor_density.setValue(phosphor.density) self.ui.phosphor_thickness.setValue(phosphor.thickness) + self.ui.apply_phosphor.setChecked(phosphor.thickness > 0) self.ui.phosphor_readout_length.setValue(phosphor.readout_length) self.ui.phosphor_pre_U0.setValue(phosphor.pre_U0) @@ -106,6 +109,9 @@ def setup_connections(self): self.ui.button_box.accepted.connect(self.accept_changes) self.ui.button_box.accepted.connect(self.ui.accept) self.ui.button_box.rejected.connect(self.ui.reject) + self.ui.apply_filters.toggled.connect(self.toggle_apply_filters) + self.ui.apply_coating.toggled.connect(self.toggle_apply_coating) + self.ui.apply_phosphor.toggled.connect(self.toggle_apply_phosphor) def exec(self): return self.ui.exec() @@ -130,8 +136,9 @@ def material_changed(self, index, category): else: self.density_inputs[category].setValue(0.0) - def filter_info_changed(self): - det_name = self.ui.detectors.currentText() + def filter_info_changed(self, new_value=None, det_name=None): + if det_name is None: + det_name = self.ui.detectors.currentText() self.filters.setdefault(det_name, {}) self.filters[det_name]['density'] = self.ui.filter_density.value() self.filters[det_name]['thickness'] = self.ui.filter_thickness.value() @@ -176,3 +183,35 @@ def accept_changes(self): density=self.ui.phosphor_density.value(), thickness=self.ui.phosphor_thickness.value() ) + + def toggle_apply_filters(self, checked): + if not checked: + self.ui.filter_thickness.setValue(0.0) + for det in HexrdConfig().detector_names: + self.filter_info_changed(det_name=det) + self.ui.detectors.setEnabled(checked) + self.ui.filter_material.setEnabled(checked) + index = self.ui.filter_material.currentIndex() + self.ui.filter_material_input.setEnabled(checked and index == 0) + self.ui.filter_density.setEnabled(checked) + self.ui.filter_thickness.setEnabled(checked) + + def toggle_apply_coating(self, checked): + if not checked: + self.ui.coating_thickness.setValue(0.0) + self.ui.coating_material.setEnabled(checked) + index = self.ui.coating_material.currentIndex() + self.ui.coating_material_input.setEnabled(checked and index == 0) + self.ui.coating_density.setEnabled(checked) + self.ui.coating_thickness.setEnabled(checked) + + def toggle_apply_phosphor(self, checked): + if not checked: + self.ui.phosphor_thickness.setValue(0.0) + self.ui.phosphor_material.setEnabled(checked) + index = self.ui.phosphor_material.currentIndex() + self.ui.phosphor_material_input.setEnabled(checked and index == 0) + self.ui.phosphor_density.setEnabled(checked) + self.ui.phosphor_thickness.setEnabled(checked) + self.ui.phosphor_readout_length.setEnabled(checked) + self.ui.phosphor_pre_U0.setEnabled(checked) diff --git a/hexrdgui/hexrd_config.py b/hexrdgui/hexrd_config.py index b215a361c..1e72cc5ff 100644 --- a/hexrdgui/hexrd_config.py +++ b/hexrdgui/hexrd_config.py @@ -3058,8 +3058,10 @@ def use_physics_package(self, v): if v != self.use_physics_package: self._use_physics_package = v self.physics_package_modified.emit() - if self.use_physics_package and self.physics_package is None: - self.create_default_physics_package() + if self.use_physics_package: + self.create_default_physics_package() + else: + self.physics_package = None @property def physics_package_dictified(self): diff --git a/hexrdgui/resources/ui/absorption_correction_options_dialog.ui b/hexrdgui/resources/ui/absorption_correction_options_dialog.ui index 979a4519c..347f8afe3 100644 --- a/hexrdgui/resources/ui/absorption_correction_options_dialog.ui +++ b/hexrdgui/resources/ui/absorption_correction_options_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 332 + 347 + 365 @@ -20,16 +20,46 @@ Absorption Correction Editor - + + + + Filter + + + true + + + + + + + Coating + + + true + + + + + + + Phosphor + + + true + + + + - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + QTabWidget::North @@ -308,6 +338,13 @@ + + + + Apply: + + + @@ -318,7 +355,6 @@ - tab_widget detectors filter_material filter_material_input