Python wx 模块,NullBitmap() 实例源码

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

项目:cebl    作者:idfah    | 项目源码 | 文件源码
def refresh(self):
        dc = wx.MemoryDC(self.drawingBuffer)
        dc.SelectObject(self.drawingBuffer)

        dc.SetBackground(wx.Brush(self.background, style=wx.SOLID))
        dc.Clear()

        gc = wx.GraphicsContext.Create(dc)

        # do not draw if window is very small, right solution? XXX - idfah
        if self.winRadius < 1.0e-3:
            return

        self.draw(gc)

        dc.SelectObject(wx.NullBitmap)
        self.triggerRepaint()
项目:AppAutoViewer    作者:RealLau    | 项目源码 | 文件源码
def DrawFromSelectedNode(self, msg):
        t = msg.replace("][", ",").replace("[", "").replace("]", "").split(",")
        osx = int(t[0])
        osy = int(t[1])
        oex = int(t[2])
        oey = int(t[3])
        i = wx.Bitmap(os.path.join(self.screenShotDir, "screenshot.png"))
        dc = wx.MemoryDC(i)
        dc.SetPen(wx.Pen(wx.RED, 1))
        #???(wxpython????drawline?drawlines, ??drawrect??????)
        dc.DrawLine(osx, osy, osx, oey)
        dc.DrawLine(osx, osy, oex, osy)
        dc.DrawLine(oex, osy, oex, oey)
        dc.DrawLine(osx, oey, oex, oey)
        dc.SelectObject(wx.NullBitmap)
        self.screenShot.SetBitmap(i) 
        self.Refresh(eraseBackground=True, rect=None)
项目:stopgo    作者:notklaatu    | 项目源码 | 文件源码
def OnLeftRelease(self,e):

        self.player.stop()
        self.brec.SetBitmapLabel(self.brecxicon)
        self.bplay.SetBitmapLabel(self.bplayicon)

        if self.hasSelected:
            #the frame selected was clicked
            img = self.MakeThumbnail(os.path.join(self.imgdir, self.selected.GetName() ), self.thumbsize)
            self.selected.SetBitmap(wx.BitmapFromImage(img) )
            self.hasSelected = True
            self.previous = 0
            self.player.play()
            self.viewport.Refresh()
            self.brec.SetBitmapLabel(self.brecicon)

        if not self.hasSelected:
            # we clicked something new
            # get new selection
            self.selected = e.GetEventObject()
            # highlight new selection
            img = self.MakeThumbnail(os.path.join(self.imgdir, self.selected.GetName() ), self.thumbsize + 3)
            imgb = wx.BitmapFromImage(img)
            dc = wx.MemoryDC(imgb)
            staricon = wx.Image(os.path.join(os.path.dirname(__file__),'..','..','stopgo','images','select.png') )
            star = wx.BitmapFromImage(staricon)
            dc.DrawBitmap(star,133,0)
            dc.SelectObject(wx.NullBitmap)
            del dc
            control = wx.StaticBitmap(self, -1, imgb)
            self.selected.SetBitmap(imgb)
            self.hasSelected = True
            self.previous = self.selected.GetId()

            #paint canvas
            img = self.MakeThumbnail(os.path.join( self.imgdir, self.selected.GetName() ), self.screenHeight*.9)
            self.GetStatusBar().SetStatusText(self.selected.GetName(), 0)
            self.PaintCanvas(img)

            self.viewport.Refresh()
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def CreateBitmap(self, artid, client, size):
        if not artid.startswith('priv'):
            return wx.NullBitmap

        artid = artid.split('/')[1:]  # Split path and remove 'priv'
        artid = '/'.join(artid)  # rejoin remaining parts

        fpath = appconstants.getdatapath(artid)
        return wx.Bitmap(fpath, wx.BITMAP_TYPE_ANY)
项目:cebl    作者:idfah    | 项目源码 | 文件源码
def refresh(self):
        """Refresh the drawing area after a change has been made.
        This method sets up a drawing context, calls self.draw
        to update the drawing and then calls self.triggerRepaint
        in order to update the drawing area on the screen.

        This method should be called each time a change is
        made that requires the drawing area to be updated.
        """
        dc = wx.MemoryDC(self.drawingBuffer)
        dc.SelectObject(self.drawingBuffer)

        dc.SetBackground(wx.Brush(self.background, style=wx.SOLID))
        dc.Clear()

        # do not draw if window is very small, right solution? XXX - idfah
        if self.winRadius < 1.0e-3:
            return

        #dc.BeginDrawing()
        self.draw(dc)
        #dc.EndDrawing()

        #del dc
        dc.SelectObject(wx.NullBitmap)
        self.triggerRepaint()
项目: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()
项目:bonsu    作者:bonsudev    | 项目源码 | 文件源码
def __init__(self, parent, id=wx.ID_ANY, bitmap=wx.NullBitmap, style=wx.ALIGN_LEFT, size=(-1,-1)):
        wx.BitmapButton.__init__(self, parent, id, bitmap=bitmap, style=style, size=size)
项目:laplacian-meshes    作者:bmershon    | 项目源码 | 文件源码
def saveImage(canvas, filename):
    s = wx.ScreenDC()
    w, h = canvas.size.Get()
    b = wx.EmptyBitmap(w, h)
    m = wx.MemoryDCFromDC(s)
    m.SelectObject(b)
    m.Blit(0, 0, w, h, s, 70, 0)
    m.SelectObject(wx.NullBitmap)
    b.SaveFile(filename, wx.BITMAP_TYPE_PNG)
项目:pyjam    作者:10se1ucgo    | 项目源码 | 文件源码
def draw_box(self):
        x1, x2 = self.plot._point2ClientCoord(*self.selected)[::2]
        dc = wx.ClientDC(self.plot.canvas)
        dc.SetLogicalFunction(wx.INVERT)
        dc.DrawRectangle(x1, 0, x2, dc.GetSize()[1])
        dc.SetLogicalFunction(wx.COPY)

    # def clear(self):
    #     # An experimental way to clear the canvas without redrawing the plot every time
    #     # dc.Blit() usage from SOF.
    #     if self.selection_drawn:
    #         self.draw_box()  # clear old
    #         self.selection_drawn = False
    #     dc = wx.ClientDC(self.plot.canvas)
    #     size = dc.GetSize()
    #     bmp = wx.Bitmap(size.width, size.height)
    #     prev_dc = wx.MemoryDC()
    #     prev_dc.SelectObject(bmp)
    #     prev_dc.Blit(
    #         0,  # Copy to this X coordinate
    #         0,  # Copy to this Y coordinate
    #         size.width,  # Copy this width
    #         size.height,  # Copy this height
    #         dc,  # From where do we copy?
    #         0,  # What's the X offset in the original DC?
    #         0  # What's the Y offset in the original DC?
    #     )
    #     prev_dc.SelectObject(wx.NullBitmap)
    #     dc.Clear()
    #     dc.DrawBitmap(bmp, 0, 0)
    #     # if self.plot.last_draw is not None:
    #     #     self.plot.Draw(self.plot.last_draw[0])
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def RefreshEditorToolBar(self):
        selected = self.TabsOpened.GetSelection()
        menu = None
        if selected != -1:
            window = self.TabsOpened.GetPage(selected)
            if isinstance(window, (Viewer, TextViewer)):
                if not window.IsDebugging():
                    menu = self.Controler.GetEditedElementBodyType(window.GetTagName())
                else:
                    menu = "debug"
        if menu is not None and menu != self.CurrentMenu:
            self.ResetEditorToolBar()
            self.CurrentMenu = menu
            self.CurrentEditorToolBar = []
            EditorToolBar = self.Panes["EditorToolBar"]
            if EditorToolBar:
                for radio, modes, id, method, picture, help in EditorToolBarItems[menu]:
                    if modes & self.DrawingMode:
                        if radio or self.DrawingMode == FREEDRAWING_MODE:
                            EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help)
                        else:
                            EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help)
                        self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
                        self.CurrentEditorToolBar.append(id)
                EditorToolBar.Realize()
                self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
                self.AUIManager.GetPane("EditorToolBar").Show()
                self.AUIManager.Update()
        elif menu is None:
            self.ResetEditorToolBar()
            self.CurrentMenu = menu
        self.ResetCurrentMode()

    # -------------------------------------------------------------------------------
    #                           EditorToolBar Items Functions
    # -------------------------------------------------------------------------------
项目:imagepy    作者:Image-Py    | 项目源码 | 文件源码
def save_bitmap(self, path):
        context = wx.ClientDC( self )
        memory = wx.MemoryDC( )
        x, y = self.ClientSize
        bitmap = wx.Bitmap( x, y, -1 )
        memory.SelectObject( bitmap )
        memory.Blit( 0, 0, x, y, context, 0, 0)
        memory.SelectObject( wx.NullBitmap)
        bitmap.SaveFile( path, wx.BITMAP_TYPE_PNG )
项目:procrustes    作者:bmershon    | 项目源码 | 文件源码
def saveImage(canvas, filename):
    s = wx.ScreenDC()
    w, h = canvas.size.Get()
    b = wx.EmptyBitmap(w, h)
    m = wx.MemoryDCFromDC(s)
    m.SelectObject(b)
    m.Blit(0, 0, w, h, s, 70, 0)
    m.SelectObject(wx.NullBitmap)
    b.SaveFile(filename, wx.BITMAP_TYPE_PNG)
项目:baroness    作者:ulrichknecht    | 项目源码 | 文件源码
def __init__(self, parent):
        wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))

        self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./gui/thanks.png", wx.BITMAP_TYPE_ANY), pos=(0, 0))
        self.bitmap_2 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, pos=(10, 10))

        self.label_1 = wx.StaticText(self, wx.ID_ANY, 'bla blub', pos=(120, 50), size=(340, 100))
        self.label_1.SetFont(wx.Font(25, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))
        self.label_1.SetForegroundColour("white")
项目:LalkaChat    作者:DeForce    | 项目源码 | 文件源码
def create_tool(self, name, binding=None, style=wx.ITEM_NORMAL, s_help="", l_help=""):
        l_id = id_renew(name)
        IDS[l_id] = name
        label_text = translate_key(IDS[l_id])
        button = self.AddLabelTool(l_id, label_text, wx.NullBitmap, wx.NullBitmap,
                                   style, s_help, l_help)
        if binding:
            self.main_class.Bind(wx.EVT_TOOL, binding, id=l_id)
        return button
项目:Cognitive-Face-Python    作者:Microsoft    | 项目源码 | 文件源码
def __init__(self, parent, bitmap=wx.NullBitmap, size=util.MAX_IMAGE_SIZE):
        super(MyStaticBitmap, self).__init__(parent)
        self.bmp = bitmap
        self.scale = 1.0
        self.bitmap = wx.StaticBitmap(self, bitmap=bitmap)
        self.size = size
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.AddStretchSpacer()
        self.sizer.Add(self.bitmap, 0, wx.EXPAND)
        self.sizer.AddStretchSpacer()
        self.SetMinSize((size, size))
        self.SetSizer(self.sizer)
        self.sizer.Layout()
项目: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)
项目:SpatialTool    作者:JRcard    | 项目源码 | 文件源码
def create_background(self):
        w,h = self.GetSize()
        self.background_bitmap = wx.EmptyBitmap(w, h)
        dc = wx.MemoryDC(self.background_bitmap)
        gc = wx.GraphicsContext_Create(dc)
        dc.SetBrush(wx.Brush("#FFFFFF"))
        dc.Clear()
        dc.DrawRectangle(0,0,w,h)

        off = h // self.chnls // 2
        gc.SetPen(wx.Pen('#000000', width=1, style=wx.SOLID))
        gc.SetBrush(wx.Brush("#FFFFFF", style=wx.TRANSPARENT))
        dc.SetTextForeground("#444444")
        if sys.platform in "darwin":
            font, ptsize = dc.GetFont(), dc.GetFont().GetPointSize()
            font.SetPointSize(ptsize - 3)
            dc.SetFont(font)
        else:
            font = dc.GetFont()
            font.SetPointSize(8)
            dc.SetFont(font)
        tickstep = w // 10
        if tickstep < 40:
            timelabel = "%.1f"
        elif tickstep < 80:
            timelabel = "%.2f"
        elif tickstep < 120:
            timelabel = "%.3f"
        else:
            timelabel = "%.4f"
        timestep = (self.end - self.begin) * 0.1
        for i, samples in enumerate(self.img):
            y = h // self.chnls * i
            if len(samples):
                gc.DrawLines(samples)
            dc.SetPen(wx.Pen('#888888', width=1, style=wx.DOT))
            dc.DrawLine(0, y+off, w, y+off)
#            for j in range(10):
#                dc.SetPen(wx.Pen('#888888', width=1, style=wx.DOT))
#                dc.DrawLine(j*tickstep, 0, j*tickstep, h)
#                dc.DrawText(timelabel % (self.begin+j*timestep), j*tickstep+2, h-y-12)
            dc.SetPen(wx.Pen('#000000', width=1))
            dc.DrawLine(0, h-y, w, h-y)

        dc.SelectObject(wx.NullBitmap)
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def onTakeScreenShot(self, event):
        """
        Takes a screenshot of the screen at give pos & size (rect).

        Method based on a script by Andrea Gavana
        """
        print('Taking screenshot...')
        rect = self.GetRect()

        # adjust widths for Linux (figured out by John Torres
        # http://article.gmane.org/gmane.comp.python.wxpython/67327)
        if sys.platform == 'linux2':
            client_x, client_y = self.ClientToScreen((0, 0))
            border_width = client_x - rect.x
            title_bar_height = client_y - rect.y
            rect.width += (border_width * 2)
            rect.height += title_bar_height + border_width

        # Create a DC for the whole screen area
        dcScreen = wx.ScreenDC()

        # Create a Bitmap that will hold the screenshot image later on
        # Note that the Bitmap must have a size big enough to hold the screenshot
        # -1 means using the current default colour depth
        bmp = wx.EmptyBitmap(rect.width, rect.height)

        #Create a memory DC that will be used for actually taking the screenshot
        memDC = wx.MemoryDC()

        # Tell the memory DC to use our Bitmap
        # all drawing action on the memory DC will go to the Bitmap now
        memDC.SelectObject(bmp)

        # Blit (in this case copy) the actual screen on the memory DC
        # and thus the Bitmap
        memDC.Blit( 0, # Copy to this X coordinate
                    0, # Copy to this Y coordinate
                    rect.width, # Copy this width
                    rect.height, # Copy this height
                    dcScreen, # Where to copy from
                    rect.x, # What's the X offset in the original DC?
                    rect.y  # What's the Y offset in the original DC?
                    )

        # Select the Bitmap out of the memory DC by selecting a new
        # uninitialized Bitmap
        memDC.SelectObject(wx.NullBitmap)

        img = bmp.ConvertToImage()
        fileName = "myImage.png"
        img.SaveFile(fileName, wx.BITMAP_TYPE_PNG)
        print('...saving as png!')
项目:GRIPy    作者:giruenf    | 项目源码 | 文件源码
def PostInit(self):
        logging.debug('{}.AfterInit started'.format(self.name))
        UIM = UIManager()
        root_ctrl = UIM.get_root_controller()

        if not isinstance(root_ctrl, MainWindowController):
            raise Exception()

        # DetachPane if granpa object has a AuiManager...    
        parent_uid = UIM._getparentuid(self.uid)
        grampa_uid = UIM._getparentuid(parent_uid)
        parent = UIM.get(parent_uid)
        grampa =  UIM.get(grampa_uid)
        if isinstance(grampa, MainWindowController):  
            mgr = wx.aui.AuiManager.GetManager(root_ctrl.view)
            if mgr is not None:
                mgr.DetachPane(parent.view)

        if self.model.pos == -1:
            # Appending - Not needed to declare pos
            self.model.pos =  parent.view.GetToolsCount()
        if self.model.pos >  parent.view.GetToolsCount():
            # If pos was setted out of range for inserting in parent Menu
            msg = 'Invalid tool position for ToolBarTool with text={}. Position will be setting to {}'.format(self.model.label, parent.view.GetToolsCount())
            logging.warning(msg)
            self.model.pos = parent.view.GetToolsCount() 

        if self.model.bitmap is None:
            bitmap = wx.Bitmap()
        else:
            bitmap = wx.Bitmap(self.model.bitmap)

        # TODO: Rever isso
        try:
            tool = parent.view.InsertTool(self.model.pos, self.model.id,
                                            self.model.label, bitmap, 
                                            wx.NullBitmap, self.model.kind,
                                            self.model.help, 
                                            self.model.long_help, None
            )
        except Exception:
            msg = 'Error in creating ToolBarTool.'
            logging.exception(msg)
            raise
        if self.model.callback and tool:
            root_ctrl.view.Bind(wx.EVT_TOOL, self.model.callback, tool)
            parent.view.Realize()

        # AtachPane again if granpa object had it detached...    
        if isinstance(grampa, MainWindowController):        
            mgr.AddPane(parent.view, parent.view.paneinfo)
            mgr.Update()

        logging.debug('{}.AfterInit ended'.format(self.name))