From 43bedad9c567e9d8bac0bacc66ac2c536b2b3084 Mon Sep 17 00:00:00 2001 From: George O'Neill Date: Wed, 18 Oct 2023 23:38:15 +0200 Subject: [PATCH] json complete but units written twice --- nexus_constructor/common_attrs.py | 1 + nexus_constructor/model/transformation.py | 9 +++++++++ nexus_constructor/transformation_view.py | 4 ++++ ui/transformation.py | 10 +++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nexus_constructor/common_attrs.py b/nexus_constructor/common_attrs.py index cbedf1a70..a3dfe1fa6 100644 --- a/nexus_constructor/common_attrs.py +++ b/nexus_constructor/common_attrs.py @@ -7,6 +7,7 @@ class CommonAttrs: NX_CLASS = "NX_class" DEPENDS_ON = "depends_on" TRANSFORMATION_TYPE = "transformation_type" + OFFSET_UNITS = "offset_units" VECTOR = "vector" UNITS = "units" VERTICES = "vertices" diff --git a/nexus_constructor/model/transformation.py b/nexus_constructor/model/transformation.py index 2ec83f2c7..9eb22d9f3 100644 --- a/nexus_constructor/model/transformation.py +++ b/nexus_constructor/model/transformation.py @@ -145,6 +145,15 @@ def units(self, new_units): self._evaluate_ui_scale_factor(new_units) self.attributes.set_attribute_value(CommonAttrs.UNITS, new_units) + @property + def offset_units(self): + return self.attributes.get_attribute_value(CommonAttrs.OFFSET_UNITS) + + @offset_units.setter + def offset_units(self, new_units): + self._evaluate_ui_scale_factor(new_units) + self.attributes.set_attribute_value(CommonAttrs.OFFSET_UNITS, new_units) + def _evaluate_ui_scale_factor(self, units): try: if self.transform_type == TransformationType.TRANSLATION: diff --git a/nexus_constructor/transformation_view.py b/nexus_constructor/transformation_view.py index c4f04c96a..14d94165a 100644 --- a/nexus_constructor/transformation_view.py +++ b/nexus_constructor/transformation_view.py @@ -50,6 +50,9 @@ def _init_connections(self): self.transformation_frame.magnitude_widget.units_line_edit.textChanged.connect( self.save_magnitude ) + self.transformation_frame.offset_units_line_edit.textChanged.connect( + self.save_offset + ) if self.model: self.model.signals.transformation_changed.connect(self.update_depends_on_ui) @@ -119,6 +122,7 @@ def save_offset(self): self.transformation.offset_vector = QVector3D( *[spinbox.value() for spinbox in self.transformation_frame.offset_spinboxes] ) + self.transformation.offset_units = self.transformation_frame.offset_units self.model.signals.transformation_changed.emit() def save_all_changes(self): diff --git a/ui/transformation.py b/ui/transformation.py index 1546a3957..935422ebb 100644 --- a/ui/transformation.py +++ b/ui/transformation.py @@ -116,7 +116,7 @@ def setup_offset_layout(self, transformation): self.offset_unit_validator.is_valid.connect( partial(validate_line_edit, self.offset_units_line_edit) ) - self.offset_units_line_edit.setPlaceholderText(CommonAttrs.UNITS) + self.offset_units_line_edit.setPlaceholderText(CommonAttrs.OFFSET_UNITS) self.main_layout.addWidget(self.offset_units_line_edit) self._add_line() @@ -187,6 +187,14 @@ def set_spinbox_ranges(self): spinbox.setRange(-10000000, 10000000) spinbox.setDecimals(5) + @property + def offset_units(self) -> str: + return self.offset_units_line_edit.text() + + @offset_units.setter + def offset_units(self, new_units: str): + self.offset_units_line_edit.setText(new_units) + @staticmethod def _make_text_bold(label: QLabel): font = label.font()