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/margin on both sides, 2*10 is 20 pixels. Together it makes721 pixels.brush = wx.BrushFromBitmap(wx.Bitmap('granite.png'))dc.SetBrush(brush)dc.DrawRectangle(0, 0, RW+2*RM, RH)Here we draw a custom pattern onto the window. I have useda predefined pattern available in the GIMP. It is called granite.w, h = dc.GetTextExtent(str(i))dc.DrawText(str(i), i+RM-w/2, 11)<strong>The</strong>se lines ensure, that we align the text correctly. <strong>The</strong>GetTextExtent() method returns the width and the height ofthe text.We do not have a border around our window. So we musthandle moving manually by additional code. <strong>The</strong> OnLeftDown()and the OnMouseMove() methods enable us to move the ruler.(TODO:link to dragging.)Figure: First ruler exampleP R A C T I C A L E X A M P L E SYou might ask yourself, why do we need all those lines, pens,gradients? What is it good for? <strong>The</strong> following scripts will bringsome practical examples. We will utilize, what we have learntin practice.ChartsCreating charts is an excelent example of utilizing gdi drawingfunctions. Charts are not GUI widgets. No gui toolkit provides35 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!