Skip to content

Commit

Permalink
fix: possible fix for TypeError in InfDoubleSpinBox
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jul 9, 2021
1 parent eaf78a9 commit 87a4acc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.9.3
- fix: possible fix for TypeError in InfDoubleSpinBox
- setup: bump afmformats from 0.14.3 to 0.15.0 as well as
nanite from 1.7.6 to 1.7.8 (requirement for #14)
0.9.2
Expand Down
17 changes: 11 additions & 6 deletions pyjibe/head/infdoublespinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ def valueFromText(self, text):
return convert_string_to_float(text)

def textFromValue(self, value):
text = f"{value:.7g}"
if not text.count("e"):
# We don't have the exponential notation.
text = str(value)
return text
return convert_float_to_string(value)


class FloatValidator(QtGui.QValidator):
Expand Down Expand Up @@ -66,7 +62,7 @@ def validate(self, string, position):

def fixup(self, text):
try:
text = convert_string_to_float(text)
text = convert_float_to_string(convert_string_to_float(text))
except ValueError:
text = ""
return text
Expand All @@ -82,6 +78,15 @@ def valid_float_string(string):
return valid


def convert_float_to_string(value):
"""Convert float to a string"""
text = f"{value:.7g}"
if not text.count("e"):
# We don't have the exponential notation.
text = str(value)
return text


def convert_string_to_float(string):
"""Convert string of float or +/- "inf" to float"""
try:
Expand Down

0 comments on commit 87a4acc

Please sign in to comment.