Skip to content
Snippets Groups Projects
Commit 588e02bc authored by Samuel GAIST's avatar Samuel GAIST Committed by 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 ca845dac
No related branches found
No related tags found
1 merge request!69Implement spin boxes for 32bit unsigned int types
Pipeline #29589 passed
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment