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/We can create regions in three ways. <strong>The</strong> easiest way is tocreate a rectangular region. More complex regions can becreated from a list of points of from a bitmap.wx.Region(int x=0, int y=0, int width=0, int height=0)This constructor creates a rectangular region.wx.RegionFromPoints(list points, int fillStyle=wx.WINDING_RULE)This constructor creates a polygonal region. <strong>The</strong> fillStyleparameter can be wx.WINDING_RULE or wx.ODDEVEN_RULE.wx.RegionFromBitmap(wx.Bitmap bmp)<strong>The</strong> most complex regions can be created with the previousmethod.Before we go to the regions, we will create a small examplefirst. We divide the topic into several parts so that it is easierto understand. You may find it a good idea to revise yourschool math. Here we can find a good article.#!/usr/bin/python# lines.pyimport wxfrom math import hypot, sin, cos, piclass Lines(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(450, 400))self.Bind(wx.EVT_PAINT, self.OnPaint)self.Centre()self.Show(True)def OnPaint(self, event):dc = wx.PaintDC(self)size_x, size_y = self.GetClientSizeTuple()dc.SetDeviceOrigin(size_x/2, size_y/2)radius = hypot(size_x/2, size_y/2)25 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!