Skip to content

Commit

Permalink
made look prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Aug 20, 2024
1 parent 4112446 commit d4625e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
40 changes: 25 additions & 15 deletions rascal2/widgets/controls/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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")
11 changes: 1 addition & 10 deletions rascal2/widgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d4625e3

Please sign in to comment.