Python wx 模块,GCDC 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用wx.GCDC

项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def Clear(self):
        """Erase the window."""
        self.last_PointLabel = None  # reset pointLabel
        dc = wx.BufferedDC(wx.ClientDC(self.canvas), self._Buffer)
        bbr = wx.Brush(self.GetBackgroundColour(), wx.SOLID)
        dc.SetBackground(bbr)
        dc.SetBackgroundMode(wx.SOLID)
        dc.Clear()
        if self._antiAliasingEnabled:
            try:
                dc = wx.GCDC(dc)
            except Exception:
                pass
        dc.SetTextForeground(self.GetForegroundColour())
        dc.SetTextBackground(self.GetBackgroundColour())
        self.last_draw = None
项目:Gym_LineFollower    作者:Chachay    | 项目源码 | 文件源码
def OnTimer(self, event):
        if self.World is not None:
            # Graphics Update
            self.bdc = wx.BufferedDC(self.cdc, self.bmp)
            self.gcdc = wx.GCDC(self.bdc)
            self.gcdc.Clear()

            self.gcdc.SetPen(wx.Pen('white'))
            self.gcdc.SetBrush(wx.Brush('white'))
            self.gcdc.DrawRectangle(0,0,640,640)

            for ag in [self.World.A]:
                ag.Draw(self.gcdc)
            self.World.BBox.Draw(self.gcdc)
            self.World.Course.Draw(self.gcdc)
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def OnPaint(self, event):
        # All that is needed here is to draw the buffer to screen
        if self.last_PointLabel != None:
            self._drawPointLabel(self.last_PointLabel)  # erase old
            self.last_PointLabel = None
        dc = wx.BufferedPaintDC(self.canvas, self._Buffer)
        if self._antiAliasingEnabled:
            try:
                dc = wx.GCDC(dc)
            except Exception:
                pass
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def OnPrintPage(self, page):
        dc = self.GetDC()  # allows using floats for certain functions
        # Note PPIScreen does not give the correct number
        # Calulate everything for printer and then scale for preview
        PPIPrinter = self.GetPPIPrinter()        # printer dots/inch (w,h)
        # PPIScreen= self.GetPPIScreen()          # screen dots/inch (w,h)
        dcSize = dc.GetSize()                    # DC size
        if self.graph._antiAliasingEnabled and not isinstance(dc, wx.GCDC):
            try:
                dc = wx.GCDC(dc)
            except Exception:
                pass
            else:
                if self.graph._hiResEnabled:
                    # high precision - each logical unit is 1/20 of a point
                    dc.SetMapMode(wx.MM_TWIPS)
        pageSize = self.GetPageSizePixels()  # page size in terms of pixcels
        clientDcSize = self.graph.GetClientSize()
        # find what the margins are (mm)
        margLeftSize, margTopSize = self.graph.pageSetupData.GetMarginTopLeft()
        margRightSize, margBottomSize = self.graph.pageSetupData.GetMarginBottomRight()
        # calculate offset and scale for dc
        pixLeft = margLeftSize * PPIPrinter[0] / 25.4  # mm*(dots/in)/(mm/in)
        pixRight = margRightSize * PPIPrinter[0] / 25.4
        pixTop = margTopSize * PPIPrinter[1] / 25.4
        pixBottom = margBottomSize * PPIPrinter[1] / 25.4
        plotAreaW = pageSize[0] - (pixLeft + pixRight)
        plotAreaH = pageSize[1] - (pixTop + pixBottom)
        # ratio offset and scale to screen size if preview
        if self.IsPreview():
            ratioW = float(dcSize[0]) / pageSize[0]
            ratioH = float(dcSize[1]) / pageSize[1]
            pixLeft *= ratioW
            pixTop *= ratioH
            plotAreaW *= ratioW
            plotAreaH *= ratioH
        # rescale plot to page or preview plot area
        self.graph._setSize(plotAreaW, plotAreaH)
        # Set offset and scale
        dc.SetDeviceOrigin(pixLeft, pixTop)
        # Thicken up pens and increase marker size for printing
        ratioW = float(plotAreaW) / clientDcSize[0]
        ratioH = float(plotAreaH) / clientDcSize[1]
        aveScale = (ratioW + ratioH) / 2
        if self.graph._antiAliasingEnabled and not self.IsPreview():
            scale = dc.GetUserScale()
            dc.SetUserScale(
                scale[0] / self.graph._pointSize[0], scale[1] / self.graph._pointSize[1])
        self.graph._setPrinterScale(aveScale)  # tickens up pens for printing
        self.graph._printDraw(dc)
        # rescale back to original
        self.graph._setSize()
        self.graph._setPrinterScale(1)
        self.graph.Redraw()  # to get point label scale and shift correct
        return True
#----------------------------------------------------------------------
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnPaint(self, event):
        dc = wx.BufferedPaintDC(self)
        dc.Clear()
        dc.BeginDrawing()

        gc = wx.GCDC(dc)

        width, height = self.GetClientSize()

        gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3))
        gc.SetBrush(wx.GREY_BRUSH)

        gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3))
        gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3))

        gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3))
        gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3))

        thumb_rect = self.GetThumbRect()
        exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
                                 thumb_rect.width, thumb_rect.height)
        if self.Parent.IsMessagePanelTop():
            exclusion_rect.y, exclusion_rect.height = width, exclusion_rect.y + exclusion_rect.height - width
        if self.Parent.IsMessagePanelBottom():
            exclusion_rect.height = height - width - exclusion_rect.y
        if exclusion_rect != thumb_rect:
            colour = wx.NamedColour("LIGHT GREY")
            gc.SetPen(wx.Pen(colour))
            gc.SetBrush(wx.Brush(colour))

            gc.DrawRectangle(exclusion_rect.x, exclusion_rect.y,
                             exclusion_rect.width, exclusion_rect.height)

        gc.SetPen(wx.GREY_PEN)
        gc.SetBrush(wx.GREY_BRUSH)

        gc.DrawPolygon(ArrowPoints(wx.TOP, width, width, 0, 0))

        gc.DrawPolygon(ArrowPoints(wx.BOTTOM, width, width, 0, height))

        gc.DrawRectangle(thumb_rect.x, thumb_rect.y,
                         thumb_rect.width, thumb_rect.height)

        dc.EndDrawing()
        event.Skip()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def draw(self, drawDC=None):
        """
        Render the figure.
        """
        # Render figure using agg
        FigureCanvasAgg.draw(self)

        # Get bitmap of figure rendered
        self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
        if wx.VERSION < (3, 0, 0):
            self.bitmap.UseAlpha()

        # Create DC for rendering graphics in bitmap
        destDC = wx.MemoryDC()
        destDC.SelectObject(self.bitmap)

        # Get Graphics Context for DC, for anti-aliased and transparent
        # rendering
        destGC = wx.GCDC(destDC)

        destGC.BeginDrawing()

        # Get canvas size and figure bounding box in canvas
        width, height = self.GetSize()
        bbox = self.GetAxesBoundingBox()

        # If highlight to display is resize, draw thick grey line at bottom
        # side of canvas
        if self.Highlight == HIGHLIGHT_RESIZE:
            destGC.SetPen(HIGHLIGHT_RESIZE_PEN)
            destGC.SetBrush(HIGHLIGHT_RESIZE_BRUSH)
            destGC.DrawRectangle(0, height - 5, width, 5)

        # If highlight to display is merging graph, draw 50% transparent blue
        # rectangle on left or right part of figure depending on highlight type
        elif self.Highlight in [HIGHLIGHT_LEFT, HIGHLIGHT_RIGHT]:
            destGC.SetPen(HIGHLIGHT_DROP_PEN)
            destGC.SetBrush(HIGHLIGHT_DROP_BRUSH)

            x_offset = (bbox.width / 2
                        if self.Highlight == HIGHLIGHT_RIGHT
                        else 0)
            destGC.DrawRectangle(bbox.x + x_offset, bbox.y,
                                 bbox.width / 2, bbox.height)

        # Draw other Viewer common elements
        self.DrawCommonElements(destGC, self.GetButtons())

        destGC.EndDrawing()

        self._isDrawn = True
        self.gui_repaint(drawDC=drawDC)
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshViewer(self):
        """
        Method that refresh the content displayed by Viewer
        """
        # Create buffered DC for drawing in panel
        width, height = self.GetSize()
        bitmap = wx.EmptyBitmap(width, height)
        dc = wx.BufferedDC(wx.ClientDC(self), bitmap)
        dc.Clear()

        # Get Graphics Context for DC, for anti-aliased and transparent
        # rendering
        gc = wx.GCDC(dc)

        gc.BeginDrawing()

        # Get first item
        item = self.ItemsDict.values()[0]

        # Get item variable path masked according Debug Variable Panel mask
        item_path = item.GetVariable(
                self.ParentWindow.GetVariableNameMask())

        # Draw item variable path at Viewer left side
        w, h = gc.GetTextExtent(item_path)
        gc.DrawText(item_path, 20, (height - h) / 2)

        # Update 'Release' button state and text color according to item forced
        # flag value
        item_forced = item.IsForced()
        self.Buttons[1].Enable(item_forced)
        self.RefreshButtonsPosition()
        if item_forced:
            gc.SetTextForeground(wx.BLUE)

        # Draw item current value at right side of Viewer
        item_value = item.GetValue()
        w, h = gc.GetTextExtent(item_value)
        gc.DrawText(item_value, width - 40 - w, (height - h) / 2)

        # Draw other Viewer common elements
        self.DrawCommonElements(gc)

        gc.EndDrawing()