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/dc.SetBrush(brush)dc.DrawRectangle(0, 0, RW+2*RM, RH)dc.SetFont(self.font)dc.SetPen(wx.Pen('#F8FF25'))dc.SetTextForeground('#F8FF25')for i in range(RW):if not (i % 100):dc.DrawLine(i+RM, 0, i+RM, 10)w, h = dc.GetTextExtent(str(i))dc.DrawText(str(i), i+RM-w/2, 11)elif not (i % 20):dc.DrawLine(i+RM, 0, i+RM, 8)elif not (i % 2): dc.DrawLine(i+RM, 0, i+RM, 4)def OnLeftDown(self, event):pos = event.GetPosition()x, y = self.ClientToScreen(event.GetPosition())ox, oy = self.GetPosition()dx = x - oxdy = y - oyself.delta = ((dx, dy))def OnMouseMove(self, event):if event.Dragging() and event.LeftIsDown():x, y = self.ClientToScreen(event.GetPosition())fp = (x - self.delta[0], y - self.delta[1])self.Move(fp)def OnRightDown(self, event):self.Close()app = wx.App()Ruler1(None, -1, '')app.MainLoop()In this example we create a ruler. This ruler will measurescreen objects in pixels. We left the default mapping mode,which is wx.MM_TEXT. As we have already mentioned, thismode has the same logical and device units. In our case,pixels.wx.Frame.__init__(self, parent, id, title, size=(RW + 2*RM, 60), style=wx.FRAMEwx.NO_BORDER | wx.STAY_ON_TOP)We have created a borderless window. <strong>The</strong> ruler is 721 pxwide. <strong>The</strong> ruler is RW + 2*RM = 701 + 20 = 721. <strong>The</strong> rulershows 700 numbers. 0 ... 700 is 701 pixels. A ruler has a34 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!