13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>The</strong> Graphics Device Interfacehttp://www.zetcode.com/wxpython/gdi/installed, the system chooses another one. Usually not to ourtaste.self.bitmap = wx.Bitmap('note.png', wx.BITMAP_TYPE_PNG)self.cross = wx.Bitmap('cross.png', wx.BITMAP_TYPE_PNG)I have created two bitmaps. <strong>The</strong> first is a rounded rectangle.With a kind of an orange fill. I have used Inkscape vectorillustrator to create it. <strong>The</strong> second one is a small cross. It isused to close the application. For this I used Gimp imageeditor.w = self.bitmap.GetWidth()h = self.bitmap.GetHeight()self.SetClientSize((w, h))We are going to draw a bitmap on the frame. I order to coverthe whole frame, we figure out the bitmap size. <strong>The</strong>n we setthe site of the frame to the size of the bitmap.if wx.Platform == '__WXGTK__':self.Bind(wx.EVT_WINDOW_CREATE, self.SetNoteShape)else: self.SetNoteShape()This is some platform dependent code. Linux developersshould call the SetNoteShape() method immediately after thewx.WindowCreateEvent event.dc = wx.ClientDC(self)dc.DrawBitmap(self.bitmap, 0, 0, True)<strong>The</strong>se lines are not necessary, because a paint event isgenerated during the creation of the application. But webelieve, it makes the example smoother. I say we, becausethis is what I have learnt from the others.def SetNoteShape(self, *event):region = wx.RegionFromBitmap(self.bitmap)self.SetShape(region)Here we set the shape of the frame to that of the bitmap. <strong>The</strong>pixels outside the image become transparent.42 de 44 27/04/2008 1:08

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!