Пример #1
0
    def draw_matplotlib_figure(self, dc, figure, rect, grid, key):
        """Draws a matplotlib.pyplot.Figure on cell

        The figure is converted into a wx.Bitmap,
        which is then drawn by draw_bitmap.

        """

        crop_rect = wx.Rect(rect.x, rect.y, rect.width - 1, rect.height - 1)

        width, height = crop_rect.width, crop_rect.height
        dpi = float(wx.ScreenDC().GetPPI()[0])

        bmp = fig2bmp(figure, width, height, dpi, self.zoom)

        self.draw_bitmap(dc, bmp, crop_rect, grid, key, scale=False)
Пример #2
0
    def draw_matplotlib_figure(self, dc, figure, rect, grid, key):
        """Draws a matplotlib.pyplot.Figure on cell

        The figure is converted into a wx.Bitmap,
        which is then drawn by draw_bitmap.

        """

        crop_rect = wx.Rect(rect.x, rect.y, rect.width - 1, rect.height - 1)

        width, height = crop_rect.width, crop_rect.height
        dpi = float(wx.ScreenDC().GetPPI()[0])

        bmp = fig2bmp(figure, width, height, dpi, self.zoom)

        self.draw_bitmap(dc, bmp, crop_rect, grid, key, scale=False)
Пример #3
0
    def copy_result(self, selection):
        """Returns result

        If selection consists of one cell only and result is a bitmap then
        the bitmap is returned.
        Otherwise the method returns string representations of the result
        for the given selection in a tab separated string.

        """

        bbox = selection.get_bbox()

        if not bbox:
            # There is no selection
            bb_top, bb_left = self.grid.actions.cursor[:2]
            bb_bottom, bb_right = bb_top, bb_left
        else:
            # Thereis a selection
            (bb_top, bb_left), (bb_bottom, bb_right) = bbox

        if bb_top == bb_bottom and bb_left == bb_right:
            # We have  a single selection

            tab = self.grid.current_table
            result = self.grid.code_array[bb_top, bb_left, tab]

            if isinstance(result, wx._gdi.Bitmap):
                # The result is a wx.Bitmap. Return it.
                return result

            elif Figure is not None and isinstance(result, Figure):
                # The result is a matplotlib figure
                # Therefore, a wx.Bitmap is returned
                key = bb_top, bb_left, tab
                rect = self.grid.CellToRect(bb_top, bb_left)
                merged_rect = self.grid.grid_renderer.get_merged_rect(
                    self.grid, key, rect)
                dpi = float(wx.ScreenDC().GetPPI()[0])
                zoom = self.grid.grid_renderer.zoom

                return fig2bmp(result, merged_rect.width, merged_rect.height,
                               dpi, zoom)

        # So we have result strings to be returned
        getter = self._get_result_string

        return self.copy(selection, getter=getter)