From d4625e3d7475444d9a3ceb3ff6c2e9010a4ea486 Mon Sep 17 00:00:00 2001 From: alexhroom Date: Tue, 20 Aug 2024 09:33:28 +0100 Subject: [PATCH] made look prettier --- rascal2/widgets/controls/view.py | 40 ++++++++++++++++++++------------ rascal2/widgets/inputs.py | 11 +-------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/rascal2/widgets/controls/view.py b/rascal2/widgets/controls/view.py index e033fb5..6d54c28 100644 --- a/rascal2/widgets/controls/view.py +++ b/rascal2/widgets/controls/view.py @@ -60,6 +60,7 @@ def __init__(self, parent): self.chi_squared.setReadOnly(True) chi_layout.addWidget(QtWidgets.QLabel("Current chi-squared:")) chi_layout.addWidget(self.chi_squared) + chi_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) # create dropdown to choose procedure procedure_layout = QtWidgets.QHBoxLayout() @@ -81,15 +82,12 @@ def __init__(self, parent): buttons_layout = QtWidgets.QVBoxLayout() buttons_layout.addWidget(self.run_button) buttons_layout.addWidget(self.stop_button) - buttons_layout.addLayout(procedure_layout) - buttons_layout.addWidget(self.fit_settings_button) - buttons_layout.setSpacing(20) buttons_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignVCenter) - procedure_box.addSpacing(20) procedure_box.addLayout(chi_layout) - procedure_box.addSpacing(50) procedure_box.addLayout(buttons_layout) - procedure_box.addWidget(self.validation_label) + procedure_box.addLayout(procedure_layout) + procedure_box.addWidget(self.fit_settings_button, alignment=QtCore.Qt.AlignmentFlag.AlignVCenter) + procedure_box.addWidget(self.validation_label, alignment=QtCore.Qt.AlignmentFlag.AlignVCenter) widget_layout = QtWidgets.QHBoxLayout() widget_layout.addLayout(procedure_box) @@ -175,23 +173,28 @@ def __init__(self, parent, procedure: Procedures, model: FitSettingsModel): self.model = model self.rows = {} self.datasetter = {} + self.val_labels = {} self.visible_settings = self.model.get_procedure_settings(procedure) self.visible_settings.remove("resampleParams") # FIXME remove when merged - just for testing layout = QtWidgets.QGridLayout() layout.setContentsMargins(10, 10, 10, 10) - layout.setSpacing(10) for i, setting in enumerate(self.visible_settings): field_info = self.model.model_fields[setting] self.rows[setting] = ValidatedInputWidget(field_info) self.datasetter[setting] = self.create_model_data_setter(setting) self.rows[setting].edited_signal.connect(self.datasetter[setting]) - self.update_data(setting) label = QtWidgets.QLabel(setting) - label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop) - label.setStyleSheet("padding : 0.5px") - layout.addWidget(label, i, 0) - layout.addWidget(self.rows[setting], i, 1) + label.setAlignment(QtCore.Qt.AlignmentFlag.AlignVCenter) + self.val_labels[setting] = QtWidgets.QLabel() + self.val_labels[setting].setStyleSheet("QLabel { color : red; }") + self.val_labels[setting].font().setPointSize(10) + self.val_labels[setting].setWordWrap(True) + self.val_labels[setting].setAlignment(QtCore.Qt.AlignmentFlag.AlignTop) + self.update_data(setting) + layout.addWidget(label, 2 * i, 0) + layout.addWidget(self.rows[setting], 2 * i, 1) + layout.addWidget(self.val_labels[setting], 2 * i + 1, 1) layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop) fit_settings = QtWidgets.QWidget(self) @@ -220,9 +223,9 @@ def set_model_data(): value = self.rows[setting].get_data() result = self.model.setData(setting, value) if result is False: - self.rows[setting].set_validation_text(self.model.last_validation_error.errors()[0]["msg"]) + self.set_validation_text(setting, self.model.last_validation_error.errors()[0]["msg"]) else: - self.rows[setting].set_validation_text("") + self.set_validation_text(setting, "") return set_model_data @@ -235,4 +238,11 @@ def get_invalid_inputs(self) -> list[str]: A list of setting names which are currently not valid. """ - return [s for s in self.rows if not self.rows[s].input_is_valid] + return [s for s in self.val_labels if self.val_labels[s].text() != ""] + + def set_validation_text(self, setting, text): + self.val_labels[setting].setText(text) + if text == "": + self.rows[setting].editor.setStyleSheet("") + else: + self.rows[setting].editor.setStyleSheet("color : red") diff --git a/rascal2/widgets/inputs.py b/rascal2/widgets/inputs.py index 88a6d45..78f609a 100644 --- a/rascal2/widgets/inputs.py +++ b/rascal2/widgets/inputs.py @@ -9,13 +9,11 @@ class ValidatedInputWidget(QtWidgets.QWidget): - """Number input for Pydantic field with validation.""" + """Value input generated from Pydantic field info.""" def __init__(self, field_info: FieldInfo, parent=None): super().__init__(parent=parent) layout = QtWidgets.QVBoxLayout() - self.input_is_valid = True - # editor_data and change_editor_data are set to the getter and setter # methods for the actual editor inside the widget self.get_data: Callable @@ -66,13 +64,6 @@ def __init__(self, field_info: FieldInfo, parent=None): self.editor.setDecimals(-floor(log10(abs(field_info.default)))) layout.addWidget(self.editor) - - self.validation_box = QtWidgets.QLabel() - self.validation_box.setStyleSheet("QLabel { color : red; }") - self.validation_box.font().setPointSize(10) - self.validation_box.setWordWrap(True) - layout.addWidget(self.validation_box) - layout.setContentsMargins(5, 0, 0, 0) self.setLayout(layout)