Commit 0a466f6c authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][spinboxes] Move floating type handling in base class

This allows for code simplification and wider range of type
support.
parent ddd7da66
......@@ -59,7 +59,7 @@ class AbstractNumpySpinBox(QAbstractSpinBox):
"""
super(AbstractNumpySpinBox, self).__init__(parent)
if self.numpy_type == np.float64:
if np.issubdtype(self.numpy_type, np.floating):
self._info = np.finfo(self.numpy_type)
else:
self._info = np.iinfo(self.numpy_type)
......@@ -90,7 +90,12 @@ class AbstractNumpySpinBox(QAbstractSpinBox):
:param value numpy_type: value to change to text
"""
return self.numpy_type(value).astype("str")
text = self.numpy_type(value).astype("str")
if np.issubdtype(self.numpy_type, np.floating):
if text.endswith(".0"):
text = text[:-2]
return text
def valueFromText(self, text, pos):
"""Returns the value contained in the text
......@@ -275,13 +280,3 @@ class Float64SpinBox(AbstractNumpySpinBox):
valueChanged = pyqtSignal(numpy_type)
minimumChanged = pyqtSignal(numpy_type)
maximumChanged = pyqtSignal(numpy_type)
def textFromValue(self, value):
"""Returns the text version of value
:param value numpy_type: value to change to text
"""
text = self.numpy_type(value).astype("str")
if text.endswith(".0"):
text = text[:-2]
return text
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