Skip to content

Commit

Permalink
Merge pull request #956 from jbellister-slac/fix_precision
Browse files Browse the repository at this point in the history
FIX: Take precision into account for the line edit widget
  • Loading branch information
YektaY authored Jan 23, 2023
2 parents 42862a2 + 1cd4a08 commit 563820a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pydm/tests/widgets/test_lineedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def test_change_display_format_type(qtbot, display_format):

@pytest.mark.parametrize("value, display_format, precision, scale, unit, show_unit, expected_display", [
(123, DisplayFormat.Default, 3, 1, "s", True, "123.000 s"),
(123.47, DisplayFormat.Decimal, 3, 2, "seconds", False, "246.94"),
(123.47, DisplayFormat.Decimal, 3, 2, "seconds", False, "246.940"),
(123.4567, DisplayFormat.String, 2, 1, "", False, "123.46"),
(123.4567, DisplayFormat.Decimal, 1, 1, "", False, "123.5"),
(1e2, DisplayFormat.Exponential, 2, 2, "light years", True, "2.00e+02 light years"),
(0x1FF, DisplayFormat.Hex, 0, 1, "Me", True, "0x1ff Me"),
(0b100, DisplayFormat.Binary, 0, 1, "KB", True, "0b100 KB"),
Expand Down
12 changes: 5 additions & 7 deletions pydm/widgets/line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def send_value(self):
self.send_value_signal[str].emit(send_value)
except ValueError:
logger.exception("Error trying to set data '{0}' with type '{1}' and format '{2}' at widget '{3}'."
.format(self.text(), self.channeltype, self._display_format_type, self.objectName()))
.format(self.text(), self.channeltype, self._display_format_type, self.objectName()))

self.clearFocus()
self.set_display()
Expand Down Expand Up @@ -260,11 +260,10 @@ def set_display(self):
else:
self._display = str(new_value)

if self._display_format_type == DisplayFormat.Default:
if isinstance(new_value, (int, float)):
self._display = str(self.format_string.format(new_value))
self.setText(self._display)
return
if isinstance(new_value, (int, float)):
self._display = str(self.format_string.format(new_value))
self.setText(self._display)
return

if self._show_units:
self._display = "{} {}".format(self._display, self._unit)
Expand Down Expand Up @@ -292,4 +291,3 @@ def strtobool(val):
return 0
else:
raise ValueError("invalid boolean input")

0 comments on commit 563820a

Please sign in to comment.