13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> Graphics Device Interfacehttp://www.zetcode.com/wxpython/gdi/and these columns are set in pixels. <strong>The</strong> lowest commondenominator for a page is often 800 px etc. This thinking isnatural as we know our monitors have e.g. 1024x768 pxs. Weare not going to do convertions, rather we are accustomed tothink in pixels. If we want to draw a structure in millimeters,we can use the two metric mapping modes. Drawing directlyin millimeters is too thick for a screen, that's why we have thewx.MM_LOMETRIC mapping mode.To set a different mapping mode, we use the SetMapMode()method.First ruler example<strong>The</strong> first ruler example will measure screen objects in pixels.#!/usr/bin/python# ruler1.pyimport wxRW = 701 # ruler widhtRM = 10 # ruler marginRH = 60 # ruler heightclass Ruler1(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(RW + 2*RM, 60),style=wx.FRAME_NO_TASKBAR | wx.NO_BORDER | wx.STAY_ON_TOP)self.font = wx.Font(7, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD, False, 'Courier 10 Pitch')self.Bind(wx.EVT_PAINT, self.OnPaint)self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)self.Bind(wx.EVT_MOTION, self.OnMouseMove)self.Centre()self.Show(True)def OnPaint(self, event):dc = wx.PaintDC(self)brush = wx.BrushFromBitmap(wx.Bitmap('granite.png'))33 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!