Skip to content

Commit 822fc2a

Browse files
authored
Fix RangeEdit step min (#701)
* fix: fix step of zero on RangeEdit * fix rangetstep tests
1 parent e48fc4b commit 822fc2a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/magicgui/widgets/_concrete.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import builtins
910
import datetime
1011
import inspect
1112
import math
@@ -515,6 +516,12 @@ def __init__(
515516
maxstart, maxstop, maxstep = self._validate_min_max(max, "max", 9999999)
516517
self.start = SpinBox(value=start, min=minstart, max=maxstart, name="start")
517518
self.stop = SpinBox(value=stop, min=minstop, max=maxstop, name="stop")
519+
520+
if self._value_type is range:
521+
if stop >= start:
522+
minstep, maxstep = builtins.max(1, minstep), maxstep
523+
else:
524+
minstep, maxstep = -maxstep, -builtins.min(1, abs(minstep))
518525
self.step = SpinBox(value=step, min=minstep, max=maxstep, name="step")
519526
self.start.changed.connect(self._emit_current_value)
520527
self.stop.changed.connect(self._emit_current_value)

tests/test_widgets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ def add(num1: int, num2: int) -> int:
463463
def test_range_widget():
464464
args = (-100, 1000, 2)
465465
rw = widgets.RangeEdit(*args)
466+
assert rw.step.min == 1
466467
v = rw.value
467468
assert isinstance(v, range)
468469
assert (v.start, v.stop, v.step) == args

0 commit comments

Comments
 (0)