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

[widgets][spinboxes] Refactor numpy_type as a property

parent eb5c5842
......@@ -210,7 +210,7 @@ class TestTypeChange(SpinBoxBaseTest):
qtbot.addWidget(spinbox)
self.numpy_type = np.float64
spinbox.setSpinboxType(self.numpy_type)
spinbox.setNumpyType(self.numpy_type)
spinbox.setRange(-10.45, 10.45)
......
......@@ -49,8 +49,7 @@ class NumpySpinBox(QAbstractSpinBox):
- maximumChanged
"""
numpy_type = None
typeChanged = pyqtSignal()
numpyTypeChanged = pyqtSignal()
valueChanged = pyqtSignal()
minimumChanged = pyqtSignal()
maximumChanged = pyqtSignal()
......@@ -63,7 +62,9 @@ class NumpySpinBox(QAbstractSpinBox):
super(NumpySpinBox, self).__init__(parent)
self.setSpinboxType(numpy_type)
self._numpy_type = None
self.setNumpyType(numpy_type)
self.lineEdit().textEdited.connect(self.__on_text_edited)
......@@ -84,8 +85,8 @@ class NumpySpinBox(QAbstractSpinBox):
:param value numpy_type: value to change to text
"""
text = self.numpy_type(value).astype("str")
if np.issubdtype(self.numpy_type, np.floating):
text = self._numpy_type(value).astype("str")
if np.issubdtype(self._numpy_type, np.floating):
if text.endswith(".0"):
text = text[:-2]
return text
......@@ -97,7 +98,7 @@ class NumpySpinBox(QAbstractSpinBox):
:param pos int: position to start considerating the text from
"""
return self.numpy_type(text)
return self._numpy_type(text)
def minimum(self):
"""Returns the spin box minimum value"""
......@@ -121,7 +122,7 @@ class NumpySpinBox(QAbstractSpinBox):
elif minimum < self._info.min:
minimum = self._info.min
self._minimum = self.numpy_type(minimum)
self._minimum = self._numpy_type(minimum)
self.minimumChanged.emit()
def maximum(self):
......@@ -146,7 +147,7 @@ class NumpySpinBox(QAbstractSpinBox):
elif maximum > self._info.max:
maximum = self._info.max
self._maximum = self.numpy_type(maximum)
self._maximum = self._numpy_type(maximum)
self.maximumChanged.emit()
def setRange(self, minimum, maximum):
......@@ -185,7 +186,7 @@ class NumpySpinBox(QAbstractSpinBox):
value = self.minimum()
self.lineEdit().setText(self.textFromValue(value))
self._value = self.numpy_type(value)
self._value = self._numpy_type(value)
self.valueChanged.emit()
......@@ -234,26 +235,26 @@ class NumpySpinBox(QAbstractSpinBox):
return QAbstractSpinBox.StepUpEnabled | QAbstractSpinBox.StepDownEnabled
def spinboxType(self):
def numpyType(self):
"""Returns the numpy type of the spinbox
:return: the numpy type used
"""
return self.numpy_type
return self._numpy_type
def setSpinboxType(self, numpy_type):
def setNumpyType(self, numpy_type):
"""Sets the input type of the spin box
:param value numpy_type: value to set
"""
if self.numpy_type != numpy_type:
self.numpy_type = numpy_type
if np.issubdtype(self.numpy_type, np.floating):
self._info = np.finfo(self.numpy_type)
if self._numpy_type != numpy_type:
self._numpy_type = numpy_type
if np.issubdtype(self._numpy_type, np.floating):
self._info = np.finfo(self._numpy_type)
else:
self._info = np.iinfo(self.numpy_type)
self._info = np.iinfo(self._numpy_type)
self._minimum = self._info.min
self._maximum = self._info.max
......@@ -263,8 +264,8 @@ class NumpySpinBox(QAbstractSpinBox):
self.setValue(0)
self.typeChanged.emit()
self.numpyTypeChanged.emit()
spinbox_type = pyqtProperty(
str, fget=spinboxType, fset=setSpinboxType, notify=typeChanged
numpy_type = pyqtProperty(
str, fget=numpyType, fset=setNumpyType, notify=numpyTypeChanged
)
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