Ejemplo n.º 1
0
def RenderText(text, font, bgcolor, fgcolor):
    """Renders text with given font to bitmap."""
    dc = wx.MemoryDC(EmptyBitmap(20, 20))
    dc.SetFont(font)
    w, h = dc.GetTextExtent(text)
    bmp = EmptyBitmap(w + 2, h + 2)
    dc.SelectObject(bmp)
    dc.SetBackgroundMode(wx.SOLID)
    dc.SetTextBackground(wx.Colour(*bgcolor))
    dc.SetTextForeground(wx.Colour(*fgcolor))
    dc.Clear()
    dc.DrawText(text, 1, 1)
    dc.SelectObject(wx.NullBitmap)

    return bmp
Ejemplo n.º 2
0
def createNoDataBitmap(imageWidth, imageHeight, text="No data"):
    """Creates 'no data' bitmap.

    Used when requested bitmap is not available (loading data was not successful) or
    we want to show 'no data' bitmap.

    :param imageWidth: image width
    :param imageHeight: image height
    """
    Debug.msg(
        4,
        "createNoDataBitmap: w={w}, h={h}, text={t}".format(w=imageWidth,
                                                            h=imageHeight,
                                                            t=text),
    )
    bitmap = EmptyBitmap(imageWidth, imageHeight)
    dc = wx.MemoryDC()
    dc.SelectObject(bitmap)
    dc.Clear()
    text = _(text)
    dc.SetFont(
        wx.Font(
            pointSize=40,
            family=wx.FONTFAMILY_SCRIPT,
            style=wx.FONTSTYLE_NORMAL,
            weight=wx.FONTWEIGHT_BOLD,
        ))
    tw, th = dc.GetTextExtent(text)
    dc.DrawText(text, (imageWidth - tw) // 2, (imageHeight - th) // 2)
    dc.SelectObject(wx.NullBitmap)
    return bitmap
Ejemplo n.º 3
0
 def _finishSaveToFile(self):
     img = self.GetImage()
     self.Draw(self.pdc, img, drawid=99)
     FileName, FileType, width, height = self._finishRenderingInfo
     ibuffer = EmptyBitmap(max(1, width), max(1, height))
     dc = wx.BufferedDC(None, ibuffer)
     dc.Clear()
     self.pdc.DrawToDC(dc)
     ibuffer.SaveFile(FileName, FileType)
     self.Map.GetRenderMgr().updateMap.disconnect(self._finishSaveToFile)
     self._finishRenderingInfo = None
Ejemplo n.º 4
0
    def OnSize(self, event):
        Debug.msg(5, "BufferedWindow.OnSize()")
        # The Buffer init is done here, to make sure the buffer is always
        # the same size as the Window
        #Size  = self.GetClientSizeTuple()
        size = self.GetClientSize()

        # Make new offscreen bitmap: this bitmap will always have the
        # current drawing in it, so it can be used to save the image to
        # a file, or whatever.
        self._Buffer = EmptyBitmap(*size)
        self.UpdateDrawing()
Ejemplo n.º 5
0
    def __init__(
        self,
        parent,
        id=wx.ID_ANY,
        style=wx.NO_FULL_REPAINT_ON_RESIZE,
        Map=None,
        **kwargs,
    ):

        wx.Window.__init__(self, parent, id=id, style=style, **kwargs)

        self.parent = parent
        self.Map = Map
        self.mapname = self.parent.mapname

        #
        # Flags
        #
        self.render = True  # re-render the map from GRASS or just redraw image
        self.resize = False  # indicates whether or not a resize event has taken place
        self.dragimg = None  # initialize variable for map panning
        self.pen = None  # pen for drawing zoom boxes, etc.
        self._oldfont = self._oldencoding = None

        #
        # Event bindings
        #
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_IDLE, self.OnIdle)

        #
        # Render output objects
        #
        self.mapfile = None  # image file to be rendered
        self.img = None  # wx.Image object (self.mapfile)

        self.imagedict = {
        }  # images and their PseudoDC ID's for painting and dragging

        self.pdc = PseudoDC()
        # will store an off screen empty bitmap for saving to file
        self._buffer = EmptyBitmap(max(1, self.Map.width),
                                   max(1, self.Map.height))

        # make sure that extents are updated at init
        self.Map.region = self.Map.GetRegion()
        self.Map.SetRegion()

        self._finishRenderingInfo = None

        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
Ejemplo n.º 6
0
    def __init__(self, parent, id=wx.ID_ANY,
                 style=wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE |
                 wx.BORDER_RAISED):
        Debug.msg(2, "AnimationWindow.__init__()")

        self.bitmap = EmptyBitmap(1, 1)
        self.parent = parent
        self._pdc = PseudoDC()
        self._overlay = None
        self._tmpMousePos = None
        self.x = self.y = 0
        self.bitmap_overlay = None

        BufferedWindow.__init__(self, parent=parent, id=id, style=style)
        self.SetBackgroundColour(wx.BLACK)
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvents)
Ejemplo n.º 7
0
    def SaveToFile(self, FileName, FileType, width, height):
        """This will save the contents of the buffer to the specified
        file. See the wx.Windows docs for wx.Bitmap::SaveFile for the
        details
        """
        busy = wx.BusyInfo(_("Please wait, exporting image..."), parent=self)
        wx.GetApp().Yield()

        self.Map.ChangeMapSize((width, height))
        ibuffer = EmptyBitmap(max(1, width), max(1, height))
        self.Map.Render(force=True, windres=True)
        img = self.GetImage()
        self.Draw(self.pdc, img, drawid=99)
        dc = wx.BufferedDC(None, ibuffer)
        dc.Clear()
        # probably does nothing, removed from wxPython 2.9
        # self.PrepareDC(dc)
        self.pdc.DrawToDC(dc)
        ibuffer.SaveFile(FileName, FileType)

        del busy
Ejemplo n.º 8
0
    def OnSize(self, event):
        """Init image size to match window size
        """
        # set size of the input image
        self.Map.width, self.Map.height = self.GetClientSize()

        # Make new off screen bitmap: this bitmap will always have the
        # current drawing in it, so it can be used to save the image to
        # a file, or whatever.
        self._buffer = EmptyBitmap(self.Map.width, self.Map.height)

        # get the image to be rendered
        self.img = self.GetImage()

        # update map display
        if self.img and self.Map.width + self.Map.height > 0:  # scale image during resize
            self.img = self.img.Scale(self.Map.width, self.Map.height)
            self.render = False
            self.UpdateHist()

        # re-render image on idle
        self.resize = True