Commit 0ec3444c authored by Flavio TARSETTI's avatar Flavio TARSETTI Committed by Samuel GAIST
Browse files

[widgets] Implement spin boxes for 64bit float types

parent b4dca197
......@@ -25,6 +25,7 @@
from ..widgets.spinboxes import Int64SpinBox
from ..widgets.spinboxes import Uint64SpinBox
from ..widgets.spinboxes import Float64SpinBox
class SpinBoxBaseTest:
......@@ -66,6 +67,45 @@ class SpinBoxBaseTest:
assert spinbox.value() == spinbox.numpy_type(expected_value)
class SpinBoxFloat64BaseTest:
klass = None
def test_range(self, qtbot):
spinbox = self.klass()
qtbot.addWidget(spinbox)
minimum = 0
maximum = 10
spinbox.setRange(minimum, maximum)
assert spinbox.minimum() == minimum
assert spinbox.maximum() == maximum
spinbox.setValue(-10)
assert spinbox.value() == spinbox.minimum()
spinbox.setValue(20)
assert spinbox.value() == spinbox.maximum()
def test_valid_input(self, qtbot):
spinbox = self.klass()
qtbot.addWidget(spinbox)
value = "42"
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(value)
def test_invalid_input(self, qtbot):
spinbox = self.klass()
qtbot.addWidget(spinbox)
value = "44444444444444444444444444444444444444444444444444444444444"
expected_value = 4.4444444444444445e58
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(expected_value)
class TestIn64SpinBox(SpinBoxBaseTest):
klass = Int64SpinBox
......@@ -103,3 +143,22 @@ class TestUin64SpinBox(SpinBoxBaseTest):
spinbox.setValue(20)
assert spinbox.value() == spinbox.maximum()
class TestFloat64SpinBox(SpinBoxFloat64BaseTest):
klass = Float64SpinBox
def test_values(self, qtbot):
spinbox = Float64SpinBox()
qtbot.addWidget(spinbox)
spinbox.setRange(-10.45, 10.45)
spinbox.setValue(5.32)
assert spinbox.value() == 5.32
spinbox.setValue(-5.32)
assert spinbox.value() == -5.32
spinbox.setValue(-15)
assert spinbox.value() == spinbox.minimum()
......@@ -59,6 +59,9 @@ class AbstractNumpySpinBox(QAbstractSpinBox):
"""
super(AbstractNumpySpinBox, self).__init__(parent)
if self.numpy_type == np.float64:
self._info = np.finfo(self.numpy_type)
else:
self._info = np.iinfo(self.numpy_type)
self._minimum = self._info.min
......@@ -250,3 +253,13 @@ class Uint64SpinBox(AbstractNumpySpinBox):
valueChanged = pyqtSignal(numpy_type)
minimumChanged = pyqtSignal(numpy_type)
maximumChanged = pyqtSignal(numpy_type)
@frozen
class Float64SpinBox(AbstractNumpySpinBox):
"""Spin box handling the floatt64 type"""
numpy_type = np.float64
valueChanged = pyqtSignal(numpy_type)
minimumChanged = pyqtSignal(numpy_type)
maximumChanged = pyqtSignal(numpy_type)
Supports Markdown
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