Esempio n. 1
0
    def OnPrintPage(self, page):
        dc = self.GetDC()
        width, height = dc.GetSizeTuple()
        mdc = wx.MemoryDC()

        bmp = wx.EmptyBitmap(width, height)
        mdc.SelectObject(bmp)
        mdc.SetBackgroundMode(wx.SOLID)
        mdc.SetBrush(wx.Brush(colour=wx.Colour(255, 255, 255)))
        mdc.SetPen(wx.Pen(colour=wx.Colour(255, 255, 255)))
        mdc.DrawRectangle(0, 0, width, height)
        mdc.SetDeviceOrigin(0, 0)

        # ------------------------------------------
        context = wx.lib.wxcairo.ContextFromDC(mdc)
        code_array = self.grid.code_array

        # Rotate if orientation is reversed
        if self.orientation_reversed:
            context.save()
            context.rotate(math.pi)
            context.translate(-width, -height)

        x_offset = 20.5 * dc.GetPPI()[0] / 96.0
        y_offset = 20.5 * dc.GetPPI()[1] / 96.0

        # Draw cells
        cell_renderer = GridCairoRenderer(context,
                                          code_array,
                                          (self.top_row, self.bottom_row),
                                          (self.left_col, self.right_col),
                                          (page - 1, page),
                                          width,
                                          height,
                                          self.orientation,
                                          x_offset=x_offset,
                                          y_offset=y_offset,
                                          view_frozen=self.grid._view_frozen)

        mdc.BeginDrawing()

        cell_renderer.draw()

        # Rotate back if orientation is reversed
        if self.orientation_reversed:
            context.restore()

        context.show_page()

        mdc.EndDrawing()

        dc.Blit(0, 0, width, height, mdc, 0, 0, wx.COPY)

        return True
Esempio n. 2
0
    def OnPrintPage(self, page):
        dc = self.GetDC()
        width, height = dc.GetSizeTuple()
        mdc = wx.MemoryDC()

        bmp = wx.EmptyBitmap(width, height)
        mdc.SelectObject(bmp)
        mdc.SetBackgroundMode(wx.SOLID)
        mdc.SetBrush(wx.Brush(colour=wx.Colour(255, 255, 255)))
        mdc.SetPen(wx.Pen(colour=wx.Colour(255, 255, 255)))
        mdc.DrawRectangle(0, 0, width, height)
        mdc.SetDeviceOrigin(0, 0)

        # ------------------------------------------
        context = wx.lib.wxcairo.ContextFromDC(mdc)
        code_array = self.grid.code_array

        # Rotate if orientation is reversed
        if self.orientation_reversed:
            context.save()
            context.rotate(math.pi)
            context.translate(-width, -height)

        x_offset = 20.5 * dc.GetPPI()[0] / 96.0
        y_offset = 20.5 * dc.GetPPI()[1] / 96.0

        # Draw cells
        cell_renderer = GridCairoRenderer(context, code_array,
                                          (self.top_row, self.bottom_row),
                                          (self.left_col, self.right_col),
                                          (page - 1, page),
                                          width, height,
                                          self.orientation,
                                          x_offset=x_offset,
                                          y_offset=y_offset,
                                          view_frozen=self.grid._view_frozen)

        mdc.BeginDrawing()

        cell_renderer.draw()

        # Rotate back if orientation is reversed
        if self.orientation_reversed:
            context.restore()

        context.show_page()

        mdc.EndDrawing()

        dc.Blit(0, 0, width, height, mdc, 0, 0, wx.COPY)

        return True
Esempio n. 3
0
    def export_cairo(self, filepath, filetype):
        """Exports grid to the PDF file filepath

        Parameters
        ----------
        filepath: String
        \tPath of file to export
        filetype in ["pdf", "svg"]
        \tType of file to export

        """

        if cairo is None:
            return

        export_info = \
            self.main_window.interfaces.get_cairo_export_info(filetype)

        if export_info is None:
            # Dialog has been canceled
            return

        top_row = max(0, export_info["top_row"])
        bottom_row = min(self.grid.code_array.shape[0] - 1,
                         export_info["bottom_row"])
        left_col = max(0, export_info["left_col"])
        right_col = min(self.grid.code_array.shape[1] - 1,
                        export_info["right_col"])
        first_tab = max(0, export_info["first_tab"])
        last_tab = min(self.grid.code_array.shape[2] - 1,
                       export_info["last_tab"])
        width = export_info["paper_width"]
        height = export_info["paper_height"]
        orientation = export_info["orientation"]

        if orientation == "landscape":
            width, height = height, width

        if filetype == "pdf":
            surface = cairo.PDFSurface(filepath, width, height)
        elif filetype == "svg":
            surface = cairo.SVGSurface(filepath, width, height)
        else:
            msg = "Export filetype {filtype} not supported.".format(
                filetype=filetype)
            raise ValueError(msg)

        context = cairo.Context(surface)

        grid_cairo_renderer = GridCairoRenderer(
            context,
            self.code_array,
            (top_row, bottom_row + 1),
            (left_col, right_col + 1),
            (first_tab, last_tab + 1),
            width,
            height,
            orientation,
            view_frozen=self.grid._view_frozen,
        )

        grid_cairo_renderer.draw()

        # Finish is required for matplotlib figures
        surface.finish()