def test_state_device_widget(qtbot, global_mmcore: CMMCorePlus):
    for label in global_mmcore.getLoadedDevicesOfType(DeviceType.StateDevice):
        wdg: StateDeviceWidget = DeviceWidget.for_device(label)
        qtbot.addWidget(wdg)
        wdg.show()
        assert wdg.deviceLabel() == label
        # assert wdg.deviceName() == "DObjective"
        assert global_mmcore.getStateLabel(label) == wdg._combo.currentText()
        assert global_mmcore.getState(label) == wdg._combo.currentIndex()
        start_state = wdg.state()

        next_state = (wdg.state() + 1) % len(wdg.stateLabels())
        with qtbot.waitSignal(global_mmcore.events.propertyChanged):
            global_mmcore.setState(label, next_state)

        assert wdg.state() != start_state
        assert wdg.state() == global_mmcore.getState(
            label) == wdg._combo.currentIndex()
        assert (wdg.stateLabel() == global_mmcore.getStateLabel(label) ==
                wdg._combo.currentText())

        wdg._disconnect()
        # once disconnected, core changes shouldn't call out to the widget
        global_mmcore.setState(label, start_state)
        assert global_mmcore.getStateLabel(label) != wdg._combo.currentText()
Ejemplo n.º 2
0
def test_objective_widget_changes_objective(global_mmcore: CMMCorePlus, qtbot):
    obj_wdg = MMObjectivesWidget()
    qtbot.addWidget(obj_wdg)

    start_z = 100.0
    global_mmcore.setPosition("Z", start_z)
    stage_mock = Mock()
    obj_wdg._mmc.events.stagePositionChanged.connect(stage_mock)

    assert obj_wdg._combo.currentText() == "Nikon 10X S Fluor"
    with pytest.raises(ValueError):
        obj_wdg._combo.setCurrentText("10asdfdsX")

    assert global_mmcore.getCurrentPixelSizeConfig() == "Res10x"

    new_val = "Nikon 40X Plan Fluor ELWD"
    with qtbot.waitSignal(global_mmcore.events.propertyChanged):
        obj_wdg._combo.setCurrentText(new_val)

    stage_mock.assert_has_calls([call("Z", 0), call("Z", start_z)])
    assert obj_wdg._combo.currentText() == new_val
    assert global_mmcore.getStateLabel(obj_wdg._objective_device) == new_val
    assert global_mmcore.getCurrentPixelSizeConfig() == "Res40x"

    assert global_mmcore.getPosition("Z") == start_z