Add example and test demonstrating spinbox bug

This commit is contained in:
Luke Campagnola 2018-01-24 09:11:42 -08:00
parent 4752b77792
commit 0653c8ec59
2 changed files with 14 additions and 1 deletions

View File

@ -26,7 +26,7 @@ spins = [
("Float with SI-prefixed units<br>(n, u, m, k, M, etc)",
pg.SpinBox(value=0.9, suffix='V', siPrefix=True)),
("Float with SI-prefixed units,<br>dec step=0.1, minStep=0.1",
pg.SpinBox(value=1.0, suffix='V', siPrefix=True, dec=True, step=0.1, minStep=0.1)),
pg.SpinBox(value=1.0, suffix='PSI', siPrefix=True, dec=True, step=0.1, minStep=0.1)),
("Float with SI-prefixed units,<br>dec step=0.5, minStep=0.01",
pg.SpinBox(value=1.0, suffix='V', siPrefix=True, dec=True, step=0.5, minStep=0.01)),
("Float with SI-prefixed units,<br>dec step=1.0, minStep=0.001",

View File

@ -18,6 +18,8 @@ def test_spinbox_formatting():
(12345678955, '12345678955', dict(int=True, decimals=100)),
(1.45e-9, '1.45e-09 A', dict(int=False, decimals=6, suffix='A', siPrefix=False)),
(1.45e-9, '1.45 nA', dict(int=False, decimals=6, suffix='A', siPrefix=True)),
(1.45, '1.45 PSI', dict(int=False, decimals=6, suffix='PSI', siPrefix=True)),
(1.45e-3, '1.45 mPSI', dict(int=False, decimals=6, suffix='PSI', siPrefix=True)),
(-2500.3427, '$-2500.34', dict(int=False, format='${value:0.02f}')),
]
@ -26,3 +28,14 @@ def test_spinbox_formatting():
sb.setValue(value)
assert sb.value() == value
assert pg.asUnicode(sb.text()) == text
# test setting value
if not opts.get('int', False):
suf = sb.opts['suffix']
sb.lineEdit().setText('0.1' + suf)
sb.editingFinishedEvent()
assert sb.value() == 0.1
if suf != '':
sb.lineEdit().setText('0.1 m' + suf)
sb.editingFinishedEvent()
assert sb.value() == 0.1e-3