Fix crash when entering nonsense numbers like '-'

We shouldn't accept those in the input field at all in my opinion but that is for another time.

Fixes Sentry issue CURA-F5.
This commit is contained in:
Ghostkeeper 2020-04-01 16:34:49 +02:00
parent 07e6cfa693
commit 869f26a5ba
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -104,7 +104,10 @@ class ImageReaderUI(QObject):
def onWidthChanged(self, value): def onWidthChanged(self, value):
if self._ui_view and not self._disable_size_callbacks: if self._ui_view and not self._disable_size_callbacks:
if len(value) > 0: if len(value) > 0:
self._width = float(value.replace(",", ".")) try:
self._width = float(value.replace(",", "."))
except ValueError: # Can happen with incomplete numbers, such as "-".
self._width = 0
else: else:
self._width = 0 self._width = 0
@ -117,7 +120,10 @@ class ImageReaderUI(QObject):
def onDepthChanged(self, value): def onDepthChanged(self, value):
if self._ui_view and not self._disable_size_callbacks: if self._ui_view and not self._disable_size_callbacks:
if len(value) > 0: if len(value) > 0:
self._depth = float(value.replace(",", ".")) try:
self._depth = float(value.replace(",", "."))
except ValueError: # Can happen with incomplete numbers, such as "-".
self._depth = 0
else: else:
self._depth = 0 self._depth = 0
@ -128,15 +134,21 @@ class ImageReaderUI(QObject):
@pyqtSlot(str) @pyqtSlot(str)
def onBaseHeightChanged(self, value): def onBaseHeightChanged(self, value):
if (len(value) > 0): if len(value) > 0:
self.base_height = float(value.replace(",", ".")) try:
self.base_height = float(value.replace(",", "."))
except ValueError: # Can happen with incomplete numbers, such as "-".
self.base_height = 0
else: else:
self.base_height = 0 self.base_height = 0
@pyqtSlot(str) @pyqtSlot(str)
def onPeakHeightChanged(self, value): def onPeakHeightChanged(self, value):
if (len(value) > 0): if len(value) > 0:
self.peak_height = float(value.replace(",", ".")) try:
self.peak_height = float(value.replace(",", "."))
except ValueError: # Can happen with incomplete numbers, such as "-".
self._width = 0
else: else:
self.peak_height = 0 self.peak_height = 0