示例#1
0
def draw_representation(cls,
                        peak_origin,
                        shape_info,
                        painter,
                        fg_color,
                        bg_color,
                        slice_transform=None,
                        shape_name="ellipsoid"):
    """
    Calls draw on a given representation type
    :param cls: The representation type expected to have a classmethod called draw
    :param peak_origin: 3-element sequence specifying the origin
    :param shape_info: dict containing a relevant shape description
    :param painter: Reference to the painter object
    :param fg_color: str containing the foreground color
    :param bg_color: str containing the background color
    :param slice_transform: Optional function to assign as slice transformation. Defaults to identity
    """
    def identity(x):
        return x

    peak_shape = MagicMock()
    peak_shape.shapeName.return_value = shape_name
    peak_shape.toJSON.return_value = json.dumps(shape_info)
    if slice_transform is None:
        slice_transform = identity
    slice_info = create_slice_info(slice_transform,
                                   slice_value=3.,
                                   slice_width=10.)

    return cls.draw(peak_origin, peak_shape, slice_info, painter, fg_color,
                    bg_color)
    def test_slice_point_changed_clears_old_peaks_and_overlays_visible(
            self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        # draw some peaks first so we can test clearing them
        painter, axes = MagicMock(), MagicMock()
        axes.get_xlim.return_value = (-1, 1)
        painter.axes = axes

        test_model.draw_peaks(slice_info, painter, SpecialCoordinateSystem.QSample)
        # clear draw calls
        painter.cross.reset_mock()
        self.mock_view.painter = painter
        self.mock_view.sliceinfo = create_slice_info(centers, slice_value=3, slice_width=5)
        presenter = PeaksViewerPresenter(test_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.SlicePointChanged)

        self.assertEqual(2, self.mock_view.painter.remove.call_count)
        self.assertEqual(2, self.mock_view.painter.cross.call_count)
示例#3
0
    def test_slice_point_changed_clears_old_peaks_and_overlays_visible(
            self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        # draw some peaks first so we can test clearing them
        painter = MagicMock()
        test_model.draw_peaks(slice_info, painter)
        # clear draw calls
        painter.cross.reset_mock()
        mock_view = MagicMock()
        mock_view.painter = painter
        mock_view.sliceinfo = create_slice_info(centers,
                                                slice_value=3,
                                                slice_width=5)
        presenter = PeaksViewerPresenter(test_model, mock_view)

        presenter.notify(PeaksViewerPresenter.Event.SlicePointChanged)

        self.assertEqual(2, mock_view.painter.remove.call_count)
        self.assertEqual(2, mock_view.painter.cross.call_count)
示例#4
0
    def test_clear_removes_painted_peaks(self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        painter = MagicMock()
        test_model.draw_peaks(slice_info, painter)
        mock_view = MagicMock()
        mock_view.painter = painter
        presenter = PeaksViewerPresenter(test_model, mock_view)

        presenter.notify(PeaksViewerPresenter.Event.ClearPeaks)

        self.assertEqual(2, mock_view.painter.remove.call_count)
    def test_clear_removes_painted_peaks(self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        painter, axes = MagicMock(), MagicMock()
        axes.get_xlim.return_value = (-1, 1)
        painter.axes = axes
        test_model.draw_peaks(slice_info, painter, SpecialCoordinateSystem.QSample)
        self.mock_view.painter = painter
        presenter = PeaksViewerPresenter(test_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.ClearPeaks)

        self.assertEqual(2, self.mock_view.painter.remove.call_count)
    def test_draw_creates_nothing_when_alpha_lt_zero(self, compute_alpha_mock):
        peak_origin, fg_color = (1, 3, 5), "r"
        peak_shape, painter = MagicMock(), MagicMock()
        alpha = -0.1
        compute_alpha_mock.return_value = alpha
        slice_info = create_slice_info(lambda x: x,
                                       slice_value=3.,
                                       slice_width=10.)

        painted = NonIntegratedPeakRepresentation.draw(peak_origin, peak_shape,
                                                       slice_info, painter,
                                                       fg_color, "unused")

        painter.cross.assert_not_called()
        self.assertTrue(painted is None)
    def test_draw_creates_cross_with_expected_properties_when_alpha_gt_zero(
            self, compute_alpha_mock):
        peak_origin, fg_color = (1, 3, 5), "r"
        peak_shape, painter = MagicMock(), MagicMock()
        painter.axes.get_xlim.return_value = (-10, 10)
        alpha = 0.5
        compute_alpha_mock.return_value = alpha
        slice_info = create_slice_info(lambda x: x,
                                       slice_value=3.,
                                       slice_width=10.)

        painted = NonIntegratedPeakRepresentation.draw(peak_origin, peak_shape,
                                                       slice_info, painter,
                                                       fg_color, "unused")

        width = 0.15
        painter.cross.assert_called_with(peak_origin[0],
                                         peak_origin[1],
                                         FuzzyMatch(width, atol=1e-2),
                                         alpha=alpha,
                                         color=fg_color)
        self.assertTrue(painted is not None)