def test_exposure_widget(qtbot: QtBot): CORE.setExposure(15) wdg = DefaultCameraExposureWidget(core=CORE) qtbot.addWidget(wdg) # check that it get's whatever core is set to. assert wdg.spinBox.value() == 15 with qtbot.waitSignal(CORE.events.exposureChanged): CORE.setExposure(30) assert wdg.spinBox.value() == 30 with qtbot.wait_signal(CORE.events.exposureChanged): wdg.spinBox.setValue(45) assert CORE.getExposure() == 45 # test updating cameraDevice CORE.setProperty("Core", "Camera", "") assert not wdg.isEnabled() with pytest.raises(RuntimeError): wdg.setCamera("blarg") # set to an invalid camera name # should now be disabled. wdg.setCamera("blarg", force=True) assert not wdg.isEnabled() # reset the camera to a working one CORE.setProperty("Core", "Camera", "Camera") with qtbot.wait_signal(CORE.events.exposureChanged): wdg.spinBox.setValue(12) assert CORE.getExposure() == 12
def test_selection_dialog(qtbot: QtBot): x = np.random.random((10, 10)) graphics = LaserGraphicsView(GraphicsOptions()) graphics.drawImage(x, QtCore.QRectF(0, 0, 10, 10), "x") dialog = dialogs.SelectionDialog(graphics) qtbot.addWidget(dialog) dialog.open() # Test enabling of options assert dialog.lineedit_manual.isEnabled() assert not dialog.spinbox_method.isEnabled() assert not dialog.spinbox_comparison.isEnabled() dialog.combo_method.setCurrentText("K-means") dialog.refresh() assert not dialog.lineedit_manual.isEnabled() assert dialog.spinbox_method.isEnabled() assert dialog.spinbox_comparison.isEnabled() assert dialog.spinbox_method.value() == 3 assert dialog.spinbox_comparison.value() == 1 dialog.combo_method.setCurrentText("Mean") dialog.check_limit_selection.setChecked(True) dialog.refresh() assert not dialog.spinbox_method.isEnabled() assert not dialog.spinbox_comparison.isEnabled() # Test correct states and masks emmited with qtbot.wait_signal(dialog.maskSelected) as emitted: dialog.apply() assert np.all(emitted.args[0] == (x > x.mean())) assert emitted.args[1] == ["intersect"] dialog.check_limit_selection.setChecked(False) dialog.combo_method.setCurrentText("Manual") dialog.lineedit_manual.setText("0.9") dialog.refresh() with qtbot.wait_signal(dialog.maskSelected) as emitted: dialog.apply() assert np.all(emitted.args[0] == (x > 0.9)) assert emitted.args[1] == [""] dialog.graphics.selection = emitted.args[0] # Test limit threshold dialog.combo_method.setCurrentText("Mean") dialog.check_limit_threshold.setChecked(True) graphics.mask = x > 0.9 dialog.refresh() with qtbot.wait_signal(dialog.maskSelected) as emitted: dialog.apply() assert np.all(emitted.args[0] == (x > np.mean(x[x > 0.9]))) assert emitted.args[1] == [""]
def wait_signal( self, signal=None, timeout=1000, raising=None, check_params_cb=None, ): self._should_raise = lambda x: x # qtbot hack return QtBot.wait_signal( self, signal=signal, timeout=timeout, raising=raising, check_params_cb=check_params_cb, )
def test_tool_widget(qtbot: QtBot): viewspace = LaserViewSpace() qtbot.addWidget(viewspace) viewspace.show() view = viewspace.activeView() widget = view.addLaser(Laser(rand_data("A1"), info={"Name": "Widget"})) tool = ToolWidget(widget, apply_all=True) index = widget.index widget.view.removeTab(index) widget.view.insertTab(index, "Tool", tool) qtbot.waitExposed(tool) tool.requestClose() view.tabs.tabText(index) == "Widget" with qtbot.wait_signal(tool.applyPressed): button = tool.button_box.button(QtWidgets.QDialogButtonBox.Apply) button.click() with qtbot.wait_signal(tool.applyPressed): button = tool.button_box.button(QtWidgets.QDialogButtonBox.Ok) button.click()
def test_overlay_tool(qtbot: QtBot): data = np.zeros((10, 10), dtype=[("r", float), ("g", float), ("b", float)]) data["r"][:, :] = 1.0 data["g"][:10, :] = 1.0 data["b"][:, :10] = 1.0 viewspace = LaserViewSpace() qtbot.addWidget(viewspace) viewspace.show() view = viewspace.activeView() view.addLaser( Laser(data, info={ "Name": "real", "File Path": "/home/pewpew/real.npz" })) tool = OverlayTool(view.activeWidget()) view.addTab("Tool", tool) qtbot.waitExposed(tool) # Test rgb mode assert tool.rows.color_model == "rgb" tool.comboAdd(1) # r assert np.all(tool.graphics.data[0, 0] == (255 << 24) + (255 << 16)) tool.comboAdd(2) # g assert np.all(tool.graphics.data[:10] == (255 << 24) + (255 << 16) + (255 << 8)) assert np.all(tool.graphics.data[10:] == (255 << 24) + (255 << 16)) tool.comboAdd(3) # g assert np.all(tool.graphics.data[:10, :10] == (255 << 24) + (255 << 16) + (255 << 8) + 255) assert np.all(tool.graphics.data[10:, :10] == (255 << 24) + (255 << 16)) assert np.all(tool.graphics.data[10:, 10:] == (255 << 24) + (255 << 16) + (255 << 8)) assert np.all(tool.graphics.data[10:, 10:] == (255 << 24) + (255 << 16)) # Test cmyk mode tool.radio_cmyk.toggle() assert tool.rows.color_model == "cmyk" assert np.all(tool.graphics.data[:10, :10] == (255 << 24)) assert np.all(tool.graphics.data[10:, :10] == (255 << 24) + (255 << 8)) assert np.all(tool.graphics.data[10:, 10:] == (255 << 25) + 255) assert np.all(tool.graphics.data[10:, 10:] == (255 << 24) + (255 << 8) + 255) # Check that the rows are limited to 3 assert tool.rows.max_rows == 3 assert not tool.combo_add.isEnabled() assert tool.rows.rowCount() == 3 with qtbot.assert_not_emitted(tool.rows.rowsChanged): tool.addRow("r") assert tool.rows.rowCount() == 3 # Check color buttons are not enabled for row in tool.rows.rows: assert not row.button_color.isEnabled() # Test any mode tool.radio_custom.toggle() assert tool.rows.color_model == "any" assert tool.combo_add.isEnabled() assert tool.check_normalise.isEnabled() for row in tool.rows.rows: assert row.button_color.isEnabled() tool.addRow("g") tool.rows[3].setColor(QtGui.QColor.fromRgbF(0.0, 1.0, 1.0)) assert tool.rows.rowCount() == 4 # Test normalise assert np.amin(tool.graphics.data) > (255 << 24) tool.check_normalise.setChecked(True) tool.refresh() assert tool.graphics.data.min() == (255 << 24) + (255 << 8) + 255 # No red tool.check_normalise.setChecked(False) # Test export dlg = tool.openExportDialog() dlg2 = dlg.selectDirectory() dlg2.close() with tempfile.NamedTemporaryFile() as tf: dlg.export(Path(tf.name)) assert Path(tf.name).exists() with tempfile.TemporaryDirectory() as td: dlg.lineedit_directory.setText(td) dlg.lineedit_filename.setText("test.png") dlg.check_individual.setChecked(True) dlg.accept() qtbot.wait(300) assert Path(td).joinpath("test_1.png").exists() assert Path(td).joinpath("test_2.png").exists() assert Path(td).joinpath("test_3.png").exists() # Test close with qtbot.wait_signal(tool.rows.rowsChanged): tool.rows.rows[-1].close() assert tool.rows.rowCount() == 3 # Test hide tool.radio_rgb.toggle() with qtbot.wait_signal(tool.rows.rows[0].itemChanged): tool.rows.rows[0].button_hide.click() assert np.all(tool.graphics.data <= ((255 << 24) + (255 << 8) + 255)) dlg = tool.rows[0].selectColor() dlg.close()