Commit d78a74bc authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][spinboxes] Make value the user property like for QSpinBox

This will allow use of the meta object system.
parent 54b88710
......@@ -470,8 +470,8 @@ class TestNumericalSetupWidget:
with qtbot.waitSignal(numerical_setup_widget.dataChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(expected_value)
default_state_dump["default"] = spinbox.value()
assert spinbox.value == spinbox.numpy_type(expected_value)
default_state_dump["default"] = spinbox.value
assert numerical_setup_widget.dump() == default_state_dump
def test_choices_click_add(self, qtbot, monkeypatch, numerical_setup_widget):
......
......@@ -74,10 +74,10 @@ class SpinBoxBaseTest:
assert spinbox.maximum() == maximum
spinbox.setValue(-10)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
spinbox.setValue(20)
assert spinbox.value() == spinbox.maximum()
assert spinbox.value == spinbox.maximum()
def test_valid_input(self, qtbot):
spinbox = NumpySpinBox(self.numpy_type)
......@@ -86,7 +86,7 @@ class SpinBoxBaseTest:
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(value)
assert spinbox.value == spinbox.numpy_type(value)
def test_invalid_input(self, qtbot, expected_values):
spinbox = NumpySpinBox(self.numpy_type)
......@@ -102,7 +102,7 @@ class SpinBoxBaseTest:
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(expected_value)
assert spinbox.value == spinbox.numpy_type(expected_value)
class UintSpinBoxBaseTest(SpinBoxBaseTest):
......@@ -120,10 +120,10 @@ class UintSpinBoxBaseTest(SpinBoxBaseTest):
spinbox.setRange(0, 10)
spinbox.setValue(-10)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
spinbox.setValue(20)
assert spinbox.value() == spinbox.maximum()
assert spinbox.value == spinbox.maximum()
class IntSpinBoxBaseTest(SpinBoxBaseTest):
......@@ -134,10 +134,10 @@ class IntSpinBoxBaseTest(SpinBoxBaseTest):
spinbox.setRange(0, 10)
spinbox.setValue(5)
assert spinbox.value() == 5
assert spinbox.value == 5
spinbox.setValue(-5)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
class FloatSpinBoxBaseTest(SpinBoxBaseTest):
......@@ -148,16 +148,16 @@ class FloatSpinBoxBaseTest(SpinBoxBaseTest):
spinbox.setRange(-10.45, 10.45)
spinbox.setValue(5.32)
assert spinbox.value() == self.numpy_type(5.32)
assert spinbox.value == self.numpy_type(5.32)
spinbox.setValue(-5.32)
assert spinbox.value() == self.numpy_type(-5.32)
assert spinbox.value == self.numpy_type(-5.32)
spinbox.setValue(-15)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
spinbox.setValue(15)
assert spinbox.value() == spinbox.maximum()
assert spinbox.value == spinbox.maximum()
class TestUint8SpinBox(UintSpinBoxBaseTest):
......@@ -217,10 +217,10 @@ class TestTypeChange(SpinBoxBaseTest):
spinbox.setRange(0, 10)
spinbox.setValue(-10)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
spinbox.setValue(20)
assert spinbox.value() == spinbox.maximum()
assert spinbox.value == spinbox.maximum()
def test_values_from_uint8_to_float_64(self, qtbot):
spinbox = NumpySpinBox(self.numpy_type)
......@@ -236,16 +236,16 @@ class TestTypeChange(SpinBoxBaseTest):
spinbox.setRange(-10.45, 10.45)
spinbox.setValue(5.32)
assert spinbox.value() == self.numpy_type(5.32)
assert spinbox.value == self.numpy_type(5.32)
spinbox.setValue(-5.32)
assert spinbox.value() == self.numpy_type(-5.32)
assert spinbox.value == self.numpy_type(-5.32)
spinbox.setValue(-15)
assert spinbox.value() == spinbox.minimum()
assert spinbox.value == spinbox.minimum()
spinbox.setValue(15)
assert spinbox.value() == spinbox.maximum()
assert spinbox.value == spinbox.maximum()
def test_type_change_with_same_type(self, qtbot):
spinbox = NumpySpinBox(self.numpy_type)
......
......@@ -161,7 +161,7 @@ class NumericalChoiceDialog(QDialog):
def value(self):
"""Returns the value selected"""
return self.spinbox.value()
return self.spinbox.value
@staticmethod
def getChoiceValue(selected_type, parent=None):
......@@ -594,13 +594,13 @@ class NumericalSetupWidget(QWidget):
for i in range(self.choices_listwidget.count())
]
elif self.range_button.isChecked():
data["default"] = self.range_default_spinbox.value()
data["default"] = self.range_default_spinbox.value
data["range"] = [
self.range_minimum_spinbox.value(),
self.range_maximum_spinbox.value(),
self.range_minimum_spinbox.value,
self.range_maximum_spinbox.value,
]
else:
data["default"] = self.single_default_spinbox.value()
data["default"] = self.single_default_spinbox.value
return data
......@@ -633,9 +633,9 @@ class NumericalSetupWidget(QWidget):
ensure that a range is really a range.
"""
min_value = self.range_minimum_spinbox.value()
max_value = self.range_maximum_spinbox.value()
default_value = self.range_default_spinbox.value()
min_value = self.range_minimum_spinbox.value
max_value = self.range_maximum_spinbox.value
default_value = self.range_default_spinbox.value
self.range_minimum_spinbox.setMaximum(max_value)
self.range_maximum_spinbox.setMinimum(min_value)
......@@ -649,16 +649,16 @@ class NumericalSetupWidget(QWidget):
self.range_default_spinbox.setValue(max_value)
def restrict_range(self):
min_value = self.range_minimum_spinbox.value()
max_value = self.range_maximum_spinbox.value()
default_value = self.range_default_spinbox.value()
min_value = self.range_minimum_spinbox.value
max_value = self.range_maximum_spinbox.value
default_value = self.range_default_spinbox.value
self.restrict_set_bounds(min_value, max_value, default_value)
def restrict_range_from_min(self):
min_value = self.range_minimum_spinbox.value()
max_value = self.range_maximum_spinbox.value()
default_value = self.range_default_spinbox.value()
min_value = self.range_minimum_spinbox.value
max_value = self.range_maximum_spinbox.value
default_value = self.range_default_spinbox.value
if min_value == max_value:
self.range_maximum_spinbox.setMinimum(min_value)
......@@ -668,9 +668,9 @@ class NumericalSetupWidget(QWidget):
self.restrict_set_bounds(min_value, max_value, default_value)
def restrict_range_from_max(self):
min_value = self.range_minimum_spinbox.value()
max_value = self.range_maximum_spinbox.value()
default_value = self.range_default_spinbox.value()
min_value = self.range_minimum_spinbox.value
max_value = self.range_maximum_spinbox.value
default_value = self.range_default_spinbox.value
if min_value == max_value:
self.range_minimum_spinbox.setMaximum(max_value)
......
......@@ -209,7 +209,7 @@ class RestrictedParameterWidget(QWidget):
if self.modality == "choice":
output = self.choices_combobox.currentText()
else:
output = self.numerical_spinbox.value()
output = self.numerical_spinbox.value
return output
......
......@@ -192,6 +192,10 @@ class NumpySpinBox(QAbstractSpinBox):
self.valueChanged.emit()
value = pyqtProperty(
type="QVariant", fget=value, fset=setValue, notify=valueChanged, user=True
)
def stepBy(self, steps):
"""Update the value of the spin box by steps.
......@@ -201,7 +205,7 @@ class NumpySpinBox(QAbstractSpinBox):
:param steps int: step to increment/decrement the spin box
"""
new_value = self.value()
new_value = self.value
if steps < 0 and new_value + steps < self.minimum():
new_value = self.minimum()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment