Python wx 模块,TRANSPARENT_BRUSH 实例源码

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

项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def PaintItem(self, item, dc, level, align):
        CT.CustomTreeCtrl.PaintItem(self, item, dc, level, align)

        rightimages = item.GetRightImages()
        if len(rightimages) > 0:
            images_bbx = self.GetItemRightImagesBBox(item)
            r_image_w, r_image_h = self._imageListRight.GetSize(rightimages[0])

            dc.SetBrush(wx.TRANSPARENT_BRUSH)
            dc.SetPen(wx.TRANSPARENT_PEN)

            bg_width = (r_image_w + 4) * len(rightimages) + 4
            bg_height = r_image_h + 8
            dc.DrawRectangle(images_bbx.x, images_bbx.y,
                             images_bbx.width, images_bbx.height)
            x_pos = images_bbx.x + 4
            for r_image in rightimages:
                self._imageListRight.Draw(
                    r_image, dc, x_pos, images_bbx.y + 4,
                    wx.IMAGELIST_DRAW_TRANSPARENT)
                x_pos += r_image_w + 4
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def DrawHighlightment(self, dc):
        scalex, scaley = dc.GetUserScale()
        dc.SetUserScale(1, 1)
        dc.SetPen(MiterPen(HIGHLIGHTCOLOR, (3 * scalex + 5), wx.SOLID))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.SetLogicalFunction(wx.AND)
        # Draw a two circle arcs for representing the coil
        dc.DrawEllipticArc(round(self.Pos.x * scalex),
                           round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
                           round(self.Size[0] * scalex),
                           round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
                           135, 225)
        dc.DrawEllipticArc(round(self.Pos.x * scalex),
                           round((self.Pos.y - int(self.Size[1] * (sqrt(2) - 1.) / 2.) + 1) * scaley),
                           round(self.Size[0] * scalex),
                           round((int(self.Size[1] * sqrt(2)) - 1) * scaley),
                           -45, 45)
        dc.SetLogicalFunction(wx.COPY)
        dc.SetUserScale(scalex, scaley)

    # Adds an highlight to the connection
项目:nimo    作者:wolfram2012    | 项目源码 | 文件源码
def DisplayImage(self):
        if self.current_image:
            tw = self.static_bitmap.GetSize().GetWidth()
            th = self.static_bitmap.GetSize().GetHeight()
            sw = self.current_image.GetSize().GetWidth()
            sh = self.current_image.GetSize().GetHeight()

            #self.scale = min(tw/float(sw),th/float(sh))


            tw = int(sw*self.scale)
            th = int(sh*self.scale)

            im = self.current_image.Copy()
            im.Rescale(tw,th)
            bm = im.ConvertToBitmap()  
            bmdc = wx.MemoryDC(bm)
            bmdc.SetBrush(wx.TRANSPARENT_BRUSH)
            bmdc.SetPen(wx.RED_PEN)
            bmdc.SetTextForeground(wx.RED)

            i = 1
            for point in self.coords[self.image_name]:
                bmdc.DrawCircle(self.scale*point[0], self.scale*point[1], 5)
                w,h = bmdc.GetTextExtent(str(i))
                bmdc.DrawText(str(i),self.scale*point[0]-w/2, self.scale*point[1]+5)
                i += 1

            del bmdc

            self.static_bitmap.SetBitmap(bm)


    # ------------- Event Handlers ---------------
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def DrawROI(self):
        object = self.object
        bmp = self.image.GetBitmap()
        w =  bmp.GetWidth()
        h =  bmp.GetHeight()
        roi = [0]*6
        for i in range(3):
            roi[2*i] = int(self.roi[2*i].value.GetValue()) - 1
            roi[2*i+1] = int(self.roi[2*i+1].value.GetValue())
        axis = int(self.scrollaxis.value.GetValue())
        if axis == 1:
            x1 = int(float(w*roi[4])/float(object.shape[2]) +0.5)
            x2 = int(float(w*(roi[5]))/float(object.shape[2]) -0.5)
            y1 = int(float(h*roi[2])/float(object.shape[1]) +0.5)
            y2 = int(float(h*(roi[3]))/float(object.shape[1]) -0.5)
        elif axis == 2:
            x1 = int(float(w*roi[4])/float(object.shape[2]) +0.5)
            x2 = int(float(w*(roi[5]))/float(object.shape[2]) -0.5)
            y1 = int(float(h*roi[0])/float(object.shape[0]) +0.5)
            y2 = int(float(h*(roi[1]))/float(object.shape[0]) -0.5)
        elif axis == 3:
            x1 = int(float(w*roi[2])/float(object.shape[1]) +0.5)
            x2 = int(float(w*(roi[3]))/float(object.shape[1]) -0.5)
            y1 = int(float(h*roi[0])/float(object.shape[0]) +0.5)
            y2 = int(float(h*(roi[1]))/float(object.shape[0]) -0.5)
        self.dc = wx.MemoryDC(bmp)
        self.dc.SelectObject(bmp)
        self.dc.SetPen(wx.Pen(wx.RED, 1))
        self.dc.SetBrush(wx.TRANSPARENT_BRUSH)
        self.dc.DrawLine(x1, 1, x1, h)
        self.dc.DrawLine(x2, 1, x2, h)
        self.dc.DrawLine(1, y1, w, y1)
        self.dc.DrawLine(1, y2, w, y2)
        self.dc.SelectObject(wx.NullBitmap)
        self.image.SetBitmap(bmp)
        self.Layout()
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def DrawROI(self):
        object = self.object
        bmp = self.image.GetBitmap()
        w =  bmp.GetWidth()
        h =  bmp.GetHeight()
        roi = [0]*6
        for i in range(3):
            roi[2*i] = int(self.roi[2*i].value.GetValue()) - 1
            roi[2*i+1] = int(self.roi[2*i+1].value.GetValue()) - 1
        axis = int(self.scrollaxis.value.GetValue())
        if axis == 1:
            rx = int(float(w*roi[4])/float(object.shape[2]) +0.5)
            rw = int(float(w*(roi[5] - roi[4] +1.0))/float(object.shape[2]) +0.5)
            ry = int(float(h*roi[2])/float(object.shape[1]) +0.5)
            rh = int(float(h*(roi[3] - roi[2] +1.0))/float(object.shape[1]) +0.5)
        elif axis == 2:
            rx = int(float(w*roi[4])/float(object.shape[2]) +0.5)
            rw = int(float(w*(roi[5] - roi[4] +1.0))/float(object.shape[2]) +0.5)
            ry = int(float(h*roi[0])/float(object.shape[0]) +0.5)
            rh = int(float(h*(roi[1] - roi[0] +1.0))/float(object.shape[0]) +0.5)
        elif axis == 3:
            rx = int(float(w*roi[2])/float(object.shape[1]) +0.5)
            rw = int(float(w*(roi[3] - roi[2] +1.0))/float(object.shape[1]) +0.5)
            ry = int(float(h*roi[0])/float(object.shape[0]) +0.5)
            rh = int(float(h*(roi[1] - roi[0] +1.0))/float(object.shape[0]) +0.5)
        self.dc = wx.MemoryDC(bmp)
        self.dc.SelectObject(bmp)
        self.dc.SetPen(wx.Pen(wx.RED, 1))
        self.dc.SetBrush(wx.TRANSPARENT_BRUSH)
        self.dc.DrawRectangle(rx, ry, rw, rh)
        self.dc.SelectObject(wx.NullBitmap)
        self.image.SetBitmap(bmp)
        self.Layout()
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshScaling(self, refresh=True):
        properties = self.Controler.GetProjectProperties(self.Debug)
        scaling = properties["scaling"][self.CurrentLanguage]
        if scaling[0] != 0 and scaling[1] != 0:
            self.Scaling = scaling
            if self.DrawGrid:
                width = max(2, int(scaling[0] * self.ViewScale[0]))
                height = max(2, int(scaling[1] * self.ViewScale[1]))
                bitmap = wx.EmptyBitmap(width, height)
                dc = wx.MemoryDC(bitmap)
                dc.SetBackground(wx.Brush(self.Editor.GetBackgroundColour()))
                dc.Clear()
                dc.SetPen(MiterPen(wx.Colour(180, 180, 180)))
                dc.DrawPoint(0, 0)
                self.GridBrush = wx.BrushFromBitmap(bitmap)
            else:
                self.GridBrush = wx.TRANSPARENT_BRUSH
        else:
            self.Scaling = None
            self.GridBrush = wx.TRANSPARENT_BRUSH
        page_size = properties["pageSize"]
        if page_size != (0, 0):
            self.PageSize = map(int, page_size)
            self.PagePen = MiterPen(wx.Colour(180, 180, 180))
        else:
            self.PageSize = None
            self.PagePen = wx.TRANSPARENT_PEN
        if refresh:
            self.RefreshVisibleElements()
            self.Editor.Refresh(False)

    # -------------------------------------------------------------------------------
    #                          Refresh functions
    # -------------------------------------------------------------------------------
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def DrawBoundingBoxes(self, bboxes, dc=None):
        """
        Draw a list of bounding box on Viewer in the order given using XOR
        logical function
        @param bboxes: List of bounding boxes to draw on viewer
        @param dc: Device Context of Viewer (default None)
        """
        # Get viewer Device Context if not given
        if dc is None:
            dc = self.Viewer.GetLogicalDC()

        # Save current viewer scale factors before resetting them in order to
        # avoid rubberband pen to be scaled
        scalex, scaley = dc.GetUserScale()
        dc.SetUserScale(1, 1)

        # Set DC drawing style
        dc.SetPen(wx.Pen(wx.WHITE, style=wx.DOT))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.SetLogicalFunction(wx.XOR)

        # Draw the bounding boxes using viewer scale factor
        for bbox in bboxes:
            if bbox is not None:
                dc.DrawRectangle(
                    bbox.x * scalex, bbox.y * scaley,
                    bbox.width * scalex, bbox.height * scaley)

        dc.SetLogicalFunction(wx.COPY)

        # Restore Viewer scale factor
        dc.SetUserScale(scalex, scaley)
项目:Cognitive-Face-Python    作者:Microsoft    | 项目源码 | 文件源码
def draw_bitmap_rectangle(bitmap, faces):
    """Draw rectangle on bitmap."""
    dc = wx.MemoryDC(bitmap.bmp)
    dc.SetPen(wx.BLUE_PEN)
    dc.SetBrush(wx.TRANSPARENT_BRUSH)
    dc.SetTextBackground('black')
    dc.SetTextForeground('white')
    dc.SetBackgroundMode(wx.SOLID)
    dc.SetFont(wx.Font(8,
                       wx.FONTFAMILY_DEFAULT,
                       wx.FONTSTYLE_NORMAL,
                       wx.FONTWEIGHT_BOLD))
    for face in faces:
        dc.DrawRectangle(
            face.rect.left * bitmap.scale,
            face.rect.top * bitmap.scale,
            face.rect.width * bitmap.scale,
            face.rect.height * bitmap.scale,
        )
        if face.name:
            text_width, text_height = dc.GetTextExtent(face.name)
            dc.DrawText(face.name,
                        face.rect.left * bitmap.scale,
                        face.rect.top * bitmap.scale - text_height)
    dc.SelectObject(wx.NullBitmap)
    bitmap.bitmap.SetBitmap(bitmap.bmp)
项目:tindieorderprintout    作者:limpkin    | 项目源码 | 文件源码
def __init__(self, canvas=None, frame=None, zoom=5.0, static=False, **kwargs):
        self.kwargs = kwargs
        self.zoom = zoom
        self.frame = frame
        self.canvas = canvas
        self.static = static

        name = kwargs['name']
        kwargs['type']
        type = kwargs['type']

        x, y, w, h = self.set_coordinates(kwargs['x1'], kwargs['y1'], kwargs['x2'], kwargs['y2'])

        text = kwargs['text']

        shape = self.shape = ogl.RectangleShape(w, h)

        if not static:
            shape.SetDraggable(True, True)        

        shape.SetX(x)
        shape.SetY(y)
        #if pen:    shape.SetPen(pen)
        #if brush:  shape.SetBrush(brush)
        shape.SetBrush(wx.TRANSPARENT_BRUSH)

        if type not in ('L', 'B', 'BC'):
            if not static:
                pen = wx.LIGHT_GREY_PEN
            else:
                pen = wx.RED_PEN
            shape.SetPen(pen)

        self.text = kwargs['text']

        evthandler = MyEvtHandler(self.evt_callback)
        evthandler.SetShape(shape)
        evthandler.SetPreviousHandler(shape.GetEventHandler())
        shape.SetEventHandler(evthandler)
        shape.SetCentreResize(False)
        shape.SetMaintainAspectRatio(False)

        canvas.AddShape( shape )
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def OnPrintPage(self, page):
        dc = self.GetDC()
        dc.SetUserScale(1.0, 1.0)
        dc.SetDeviceOrigin(0, 0)
        dc.printing = not self.Preview

        # Get the size of the DC in pixels
        ppiPrinterX, ppiPrinterY = self.GetPPIPrinter()
        ppiScreenX, ppiScreenY = self.GetPPIScreen()
        pw, ph = self.GetPageSizePixels()
        dw, dh = dc.GetSizeTuple()
        Xscale = (float(dw) * float(ppiPrinterX)) / (float(pw) * 25.4)
        Yscale = (float(dh) * float(ppiPrinterY)) / (float(ph) * 25.4)

        fontsize = self.FontSize * Yscale
        text_margin = self.TextMargin * Yscale

        margin_left = self.Margins[0].x * Xscale
        margin_top = self.Margins[0].y * Yscale
        area_width = dw - self.Margins[1].x * Xscale - margin_left
        area_height = dh - self.Margins[1].y * Yscale - margin_top

        dc.SetPen(MiterPen(wx.BLACK))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.DrawRectangle(margin_left, margin_top, area_width, area_height)

        dc.SetFont(wx.Font(fontsize, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
        dc.SetTextForeground(wx.BLACK)
        block_name = " - ".join(self.Viewer.GetTagName().split("::")[1:])
        text_width, text_height = dc.GetTextExtent(block_name)
        dc.DrawText(block_name, margin_left, margin_top - text_height - self.TextMargin)
        dc.DrawText(_("Page: %d") % page, margin_left, margin_top + area_height + self.TextMargin)

        # Calculate the position on the DC for centering the graphic
        posX = area_width * ((page - 1) % self.PageGrid[0])
        posY = area_height * ((page - 1) / self.PageGrid[0])

        scaleX = float(area_width) / float(self.PageSize[0])
        scaleY = float(area_height) / float(self.PageSize[1])
        scale = min(scaleX, scaleY)

        # Set the scale and origin
        dc.SetDeviceOrigin(-posX + margin_left, -posY + margin_top)
        dc.SetClippingRegion(posX, posY, self.PageSize[0] * scale, self.PageSize[1] * scale)
        dc.SetUserScale(scale, scale)

        self.Viewer.DoDrawing(dc, True)

        return True