예제 #1
0
    def test_save(self, qtbot):
        settings = ViewSettings()
        widget = PColormapCreator(settings)
        qtbot.addWidget(widget)
        color1 = QColor(10, 40, 12)
        color2 = QColor(100, 4, 220)
        widget.color_picker.setCurrentColor(color1)
        widget.add_color(0.1)
        widget.color_picker.setCurrentColor(color2)
        widget.add_color(0.8)

        def check_res(colormap):
            return (len(colormap) == 2
                    and colormap[0].color == color_from_qcolor(color1)
                    and colormap[1].color == color_from_qcolor(color2)
                    and colormap[0].color_position == 0.1
                    and colormap[1].color_position == 0.8)

        with qtbot.wait_signal(widget.colormap_selected,
                               check_params_cb=check_res):
            widget.save_btn.click()

        cmap_dict = settings.get_from_profile("custom_colormap")
        assert len(cmap_dict) == 1
        assert check_res(list(cmap_dict.values())[0])
예제 #2
0
    def __init__(self, settings: ViewSettings):
        super().__init__()
        self.settings = settings

        self.layout_list = QComboBox()
        self.layout_list.addItems(self.settings.theme_list())
        self.layout_list.setCurrentText(self.settings.theme_name)

        self.layout_list.currentIndexChanged.connect(self.change_theme)
        self.labels_render_cmb = QComboBox()
        self.labels_render_cmb.addItems(RENDERING_LIST)
        self._update_render_mode()
        self.labels_render_cmb.currentTextChanged.connect(
            self.change_render_mode)
        settings.connect_to_profile(RENDERING_MODE_NAME,
                                    self._update_render_mode)

        layout = QGridLayout()
        layout.addWidget(QLabel("Theme:"), 0, 0)
        layout.addWidget(self.layout_list, 0, 1)
        layout.addWidget(QLabel("ROI render mode:"), 1, 0)
        layout.addWidget(self.labels_render_cmb, 1, 1)
        layout.setColumnStretch(2, 1)
        layout.setRowStretch(2, 1)
        self.setLayout(layout)
예제 #3
0
    def test_save(self, qtbot):
        settings = ViewSettings()
        widget = PColormapCreator(settings)
        qtbot.addWidget(widget)
        color1 = QColor(10, 40, 12)
        color2 = QColor(100, 4, 220)
        widget.color_picker.setCurrentColor(color1)
        widget.add_color(0.1)
        widget.color_picker.setCurrentColor(color2)
        widget.add_color(0.8)

        def check_res(colormap):
            return (
                len(colormap.colors) == 4
                and np.allclose(colormap.colors[0], color_from_qcolor(color1))
                and np.allclose(colormap.colors[1], color_from_qcolor(color1))
                and np.allclose(colormap.colors[2], color_from_qcolor(color2))
                and np.allclose(colormap.colors[3], color_from_qcolor(color2))
                and colormap.controls[0] == 0 and colormap.controls[1] == 0.1
                and colormap.controls[2] == 0.8 and colormap.controls[3] == 1)

        with qtbot.wait_signal(widget.colormap_selected,
                               check_params_cb=check_res):
            widget.save_btn.click()

        cmap_dict = settings.get_from_profile("custom_colormap")
        assert len(cmap_dict) == 1
        assert check_res(list(cmap_dict.values())[0])
예제 #4
0
 def test_change_channels_num(self, qtbot, image2):
     settings = ViewSettings()
     box = ColorComboBoxGroup(settings, "test", height=30)
     qtbot.add_widget(box)
     box.set_channels(1)
     box.set_channels(4)
     box.set_channels(10)
     box.set_channels(4)
     box.set_channels(10)
     settings.image = image2
     box.update_channels()
     assert box.layout().count() == image2.channels
예제 #5
0
 def test_custom_colors_save(self, qtbot):
     settings = ViewSettings()
     widget = PColormapCreator(settings)
     qtbot.addWidget(widget)
     color1 = QColor(10, 40, 12)
     color2 = QColor(100, 4, 220)
     widget.color_picker.setCustomColor(2, color1)
     widget.color_picker.setCustomColor(7, color2)
     widget._save_custom_colors()
     custom_color_list = settings.get_from_profile("custom_colors")
     assert custom_color_list[2] == color_from_qcolor(color1)
     assert custom_color_list[7] == color_from_qcolor(color2)
     widget2 = PColormapCreator(settings)
     assert widget2.color_picker.customColor(2) == color1
     assert widget2.color_picker.customColor(7) == color2
예제 #6
0
 def test_color(self, qtbot):
     settings = ViewSettings()
     widget = LabelEditor(settings)
     qtbot.addWidget(widget)
     widget.color_picker.setCurrentColor(QColor(100, 200, 0))
     widget.add_color()
     assert widget.get_colors() == [[100, 200, 0]]
예제 #7
0
 def __init__(self, settings: ViewSettings):
     super().__init__()
     self.settings = settings
     for i, el in enumerate(settings.get_from_profile("custom_colors", [])):
         self.color_picker.setCustomColor(i, qcolor_from_color(el))
     self.prohibited_names = set(self.settings.colormap_dict.keys()
                                 )  # Prohibited name is added to reduce
예제 #8
0
    def test_color_combo_box_group_and_color_preview(self, qtbot):
        settings = ViewSettings()
        ch_property = ChannelProperty(settings, "test")
        box = ColorComboBoxGroup(settings, "test", ch_property, height=30)
        qtbot.add_widget(box)
        qtbot.add_widget(ch_property)
        box.set_channels(3)
        box.set_active(1)
        with qtbot.assert_not_emitted(box.coloring_update), qtbot.assert_not_emitted(box.change_channel):
            ch_property.minimum_value.setValue(10)
            ch_property.minimum_value.setValue(100)

        def check_parameters(name, index):
            return name == "test" and index == 1

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.fixed.setChecked(True)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.minimum_value.setValue(10)

        ch_property.maximum_value.setValue(10000)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.maximum_value.setValue(11000)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.fixed.setChecked(False)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.use_filter.set_value(NoiseFilterType.Gauss)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.use_filter.set_value(NoiseFilterType.Median)

        ch_property.filter_radius.setValue(0.5)
        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.filter_radius.setValue(2)

        with qtbot.waitSignal(box.coloring_update), qtbot.waitSignal(
            box.change_channel, check_params_cb=check_parameters
        ):
            ch_property.use_filter.set_value(NoiseFilterType.No)

        with qtbot.assert_not_emitted(box.coloring_update), qtbot.assert_not_emitted(box.change_channel):
            ch_property.filter_radius.setValue(0.5)
예제 #9
0
 def test_add(self, qtbot):
     settings = ViewSettings()
     widget = LabelEditor(settings)
     qtbot.addWidget(widget)
     base_count = len(settings.label_color_dict)
     widget.save()
     assert len(settings.label_color_dict) == base_count
     widget.add_color()
     widget.save()
     assert len(settings.label_color_dict) == base_count + 1
예제 #10
0
 def test_change_channels_num(self, qtbot):
     settings = ViewSettings()
     box = ColorComboBoxGroup(settings, "test", height=30)
     qtbot.add_widget(box)
     box.set_channels(1)
     box.set_channels(4)
     box.set_channels(10)
     box.set_channels(4)
     box.set_channels(10)
     box.set_channels(2)
예제 #11
0
 def test_settings_integration(self, qtbot):
     settings = ViewSettings()
     color_list = PColormapList(settings, [])
     color_list.refresh()
     qtbot.addWidget(color_list)
     selected = settings.chosen_colormap[:]
     color_list.set_state("BlackRed", False)
     selected2 = settings.chosen_colormap[:]
     assert len(selected2) + 1 == len(selected)
     assert "BlackRed" not in selected2
     assert "BlackRed" in selected
예제 #12
0
 def test_color_combo_box_group(self, qtbot):
     settings = ViewSettings()
     box = ColorComboBoxGroup(settings, "test", height=30)
     qtbot.add_widget(box)
     box.set_channels(3)
     assert len(box.current_colors) == 3
     assert all(map(lambda x: isinstance(x, str), box.current_colors))
     with qtbot.waitSignal(box.coloring_update):
         box.layout().itemAt(0).widget().check_box.setChecked(False)
     with qtbot.waitSignal(box.coloring_update):
         box.layout().itemAt(0).widget().setCurrentIndex(2)
     assert box.current_colors[0] is None
     assert all(map(lambda x: isinstance(x, str), box.current_colors[1:]))
예제 #13
0
 def test_init(self, qtbot):
     settings = ViewSettings()
     widget = LabelEditor(settings)
     qtbot.addWidget(widget)
     assert len(widget.get_colors()) == 0