def test_slider_extremes(sld: _GenericSlider, mag, qtbot):
    if type(sld) is QLabeledSlider:
        pytest.skip()

    _mag = 10 ** mag
    with qtbot.waitSignal(sld.rangeChanged, timeout=400):
        sld.setRange(-_mag, _mag)
    for i in _linspace(-_mag, _mag, 10):
        sld.setValue(i)
        assert math.isclose(sld.value(), i, rel_tol=1e-8)
def test_press_move_release(gslider: _GenericSlider, qtbot):
    assert gslider._pressedControl == QStyle.SubControl.SC_None

    opt = QStyleOptionSlider()
    gslider.initStyleOption(opt)
    style = gslider.style()
    hrect = style.subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle)
    handle_pos = gslider.mapToGlobal(hrect.center())

    with qtbot.waitSignal(gslider.sliderPressed):
        qtbot.mousePress(gslider, Qt.LeftButton, pos=handle_pos)

    assert gslider._pressedControl == QStyle.SubControl.SC_SliderHandle

    with qtbot.waitSignals([gslider.sliderMoved, gslider.valueChanged]):
        shift = QPoint(
            0, -8) if gslider.orientation() == Qt.Vertical else QPoint(8, 0)
        gslider.mouseMoveEvent(_mouse_event(handle_pos + shift))

    with qtbot.waitSignal(gslider.sliderReleased):
        qtbot.mouseRelease(gslider, Qt.LeftButton, pos=handle_pos)

    assert gslider._pressedControl == QStyle.SubControl.SC_None

    gslider.show()
    with qtbot.waitSignal(gslider.sliderPressed):
        qtbot.mousePress(gslider, Qt.LeftButton, pos=handle_pos)
def test_slider_extremes(gslider: _GenericSlider, mag, qtbot):
    _mag = 10**mag
    with qtbot.waitSignal(gslider.rangeChanged):
        gslider.setRange(-_mag, _mag)
    for i in _linspace(-_mag, _mag, 10):
        gslider.setValue(i)
        assert math.isclose(gslider.value(), i, rel_tol=1e-8)
        gslider.initStyleOption(QStyleOptionSlider())
def test_position(sld: _GenericSlider, qtbot):
    sld.setSliderPosition(21)
    assert sld.sliderPosition() == 21

    if type(sld) is not QLabeledSlider:
        sld.setSliderPosition(21.5)
        assert sld.sliderPosition() == 21.5
def test_hover(gslider: _GenericSlider):

    opt = QStyleOptionSlider()
    gslider.initStyleOption(opt)
    style = gslider.style()
    hrect = style.subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle)
    handle_pos = QPointF(gslider.mapToGlobal(hrect.center()))

    assert gslider._hoverControl == QStyle.SubControl.SC_None

    gslider.event(QHoverEvent(QEvent.HoverEnter, handle_pos, QPointF()))
    assert gslider._hoverControl == QStyle.SubControl.SC_SliderHandle

    gslider.event(
        QHoverEvent(QEvent.HoverLeave, QPointF(-1000, -1000), handle_pos))
    assert gslider._hoverControl == QStyle.SubControl.SC_None
def test_press_move_release(sld: _GenericSlider, qtbot):

    _real_sld = getattr(sld, "_slider", sld)

    with suppress(AttributeError):  # for QSlider
        assert _real_sld._pressedControl == QStyle.SubControl.SC_None

    opt = QStyleOptionSlider()
    _real_sld.initStyleOption(opt)
    style = _real_sld.style()
    hrect = style.subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle)
    handle_pos = _real_sld.mapToGlobal(hrect.center())

    with qtbot.waitSignal(_real_sld.sliderPressed, timeout=300):
        qtbot.mousePress(_real_sld, Qt.LeftButton, pos=handle_pos)

    with suppress(AttributeError):
        assert sld._pressedControl == QStyle.SubControl.SC_SliderHandle

    with qtbot.waitSignals(
        [_real_sld.sliderMoved, _real_sld.valueChanged], timeout=300
    ):
        shift = (
            QPoint(0, -8) if _real_sld.orientation() == Qt.Vertical else QPoint(8, 0)
        )
        _real_sld.mouseMoveEvent(_mouse_event(handle_pos + shift))

    with qtbot.waitSignal(_real_sld.sliderReleased, timeout=300):
        qtbot.mouseRelease(_real_sld, Qt.LeftButton, pos=handle_pos)

    with suppress(AttributeError):
        assert _real_sld._pressedControl == QStyle.SubControl.SC_None

    sld.show()
    with qtbot.waitSignal(_real_sld.sliderPressed, timeout=300):
        qtbot.mousePress(_real_sld, Qt.LeftButton, pos=handle_pos)
def test_hover(sld: _GenericSlider):

    _real_sld = getattr(sld, "_slider", sld)

    opt = QStyleOptionSlider()
    _real_sld.initStyleOption(opt)
    hrect = _real_sld.style().subControlRect(
        QStyle.CC_Slider, opt, QStyle.SC_SliderHandle
    )
    handle_pos = QPointF(sld.mapToGlobal(hrect.center()))

    with suppress(AttributeError):  # for QSlider
        assert _real_sld._hoverControl == QStyle.SubControl.SC_None

    _real_sld.event(QHoverEvent(QEvent.HoverEnter, handle_pos, QPointF()))
    with suppress(AttributeError):  # for QSlider
        assert _real_sld._hoverControl == QStyle.SubControl.SC_SliderHandle

    _real_sld.event(QHoverEvent(QEvent.HoverLeave, QPointF(-1000, -1000), handle_pos))
    with suppress(AttributeError):  # for QSlider
        assert _real_sld._hoverControl == QStyle.SubControl.SC_None
def test_ticks(sld: _GenericSlider, qtbot):
    sld.setTickInterval(3)
    assert sld.tickInterval() == 3
    sld.setTickPosition(QSlider.TicksAbove)
    sld.show()
def test_steps(sld: _GenericSlider, qtbot):

    sld.setSingleStep(11)
    assert sld.singleStep() == 11

    sld.setPageStep(16)
    assert sld.pageStep() == 16

    if type(sld) is not QLabeledSlider:

        sld.setSingleStep(0.1)
        assert sld.singleStep() == 0.1

        sld.setSingleStep(1.5e20)
        assert sld.singleStep() == 1.5e20

        sld.setPageStep(0.2)
        assert sld.pageStep() == 0.2

        sld.setPageStep(1.5e30)
        assert sld.pageStep() == 1.5e30
Exemplo n.º 10
0
def test_ticks(gslider: _GenericSlider, qtbot):
    gslider.setTickInterval(0.3)
    assert gslider.tickInterval() == 0.3
    gslider.setTickPosition(gslider.TicksAbove)
    gslider.show()
Exemplo n.º 11
0
def test_float_values(gslider: _GenericSlider, qtbot):
    with qtbot.waitSignal(gslider.rangeChanged):
        gslider.setRange(0.25, 0.75)
    assert gslider.minimum() == 0.25
    assert gslider.maximum() == 0.75

    with qtbot.waitSignal(gslider.valueChanged):
        gslider.setValue(0.55)
    assert gslider.value() == 0.55

    with qtbot.waitSignal(gslider.valueChanged):
        gslider.setValue(1.55)
    assert gslider.value() == 0.75 == gslider.maximum()
Exemplo n.º 12
0
def test_change_floatslider_range(gslider: _GenericSlider, qtbot):
    with qtbot.waitSignals([gslider.rangeChanged, gslider.valueChanged]):
        gslider.setMinimum(10)

    assert gslider.value() == 10 == gslider.minimum()
    assert gslider.maximum() == 99

    with qtbot.waitSignal(gslider.rangeChanged):
        gslider.setMaximum(90)
    assert gslider.value() == 10 == gslider.minimum()
    assert gslider.maximum() == 90

    with qtbot.waitSignals([gslider.rangeChanged, gslider.valueChanged]):
        gslider.setRange(20, 40)
    assert gslider.value() == 20 == gslider.minimum()
    assert gslider.maximum() == 40

    with qtbot.waitSignal(gslider.valueChanged):
        gslider.setValue(30)
    assert gslider.value() == 30

    with qtbot.waitSignals([gslider.rangeChanged, gslider.valueChanged]):
        gslider.setMaximum(25)
    assert gslider.value() == 25 == gslider.maximum()
    assert gslider.minimum() == 20
Exemplo n.º 13
0
def test_steps(gslider: _GenericSlider, qtbot):
    gslider.setSingleStep(0.1)
    assert gslider.singleStep() == 0.1

    gslider.setSingleStep(1.5e20)
    assert gslider.singleStep() == 1.5e20

    gslider.setPageStep(0.2)
    assert gslider.pageStep() == 0.2

    gslider.setPageStep(1.5e30)
    assert gslider.pageStep() == 1.5e30
Exemplo n.º 14
0
def test_position(gslider: _GenericSlider, qtbot):
    gslider.setSliderPosition(21.2)
    assert gslider.sliderPosition() == 21.2
Exemplo n.º 15
0
def test_wheel(gslider: _GenericSlider, qtbot):
    with qtbot.waitSignal(gslider.valueChanged):
        gslider.wheelEvent(_wheel_event(120))

    gslider.wheelEvent(_wheel_event(0))