Hi,
(I have posted this to news:comp.lang.python too)
I am trying to learn how to use wxPython and currently I am especially
working with 'device contexts'.
By looking at (copy-pasting from) the examples and the pysketch sample
I am able to draw something, but I don't really get the understanding
of what is going on.
I have boiled my app down to simplest possible I think. It looks like:
···
================================================================
from wxPython.wx import *
class MyCanvas(wxScrolledWindow):
def __init__(self, parent, id = -1, size = wxDefaultSize):
wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size, wxSUNKEN_BORDER)
self.buffer=wxEmptyBitmap(100,100)
dc=wxBufferedDC(None, self.buffer)
dc.SetBackground(wxBrush(self.GetBackgroundColour()))
dc.Clear()
dc.BeginDrawing()
dc.DrawRectangle(10,10,100,100)
dc.EndDrawing()
EVT_PAINT(self,self.OnPaint)
def OnPaint(self,event):
dc = wxBufferedPaintDC(self,self.buffer)
app=wxPySimpleApp()
frame=wxFrame(None,-1,"Test")
win = MyCanvas(frame)
frame.Show(true)
app.MainLoop()
and draws a rectangle on the window. I could go on living happily, but
I would like to know why do I need a DC in both __init__ and OnPaint.
Why do I need to have the EVT_PAINT when the docs say:
"To draw on a window from outside OnPaint, construct a wxClientDC
object."?
Removing the event and changing the dc line in __init__ to use a
wxClientDC does not draw anything.
What are the arguments I feed to the DC's. Buffered DC is not
mentioned anywhere in the doc AFAICS.
Another question is what is the difference between the different
wxDC's (Paint, Client, Buffered, BufferedPaint,...)?
Could I do it without the class MyCanvas and completely procedural? I
believe not as I can't figure out what arguments to give to the
EVT_PAINT and the OnPaint if not self from a class. Does the script
itself have a 'self'?
Now when I have got it running I would like to be able to click on
items on the window, open an entry and write the input on this on the
DC.
I make a left down event reacting with:
def OnLeftDown(self,event):
dlg = wxTextEntryDialog(frame,"Write here","Entry","")
dlg.ShowModal()
I then would like to draw the output from dlg.GetValue() on the DC,
but a new wxBufferedDC written exactly as in __init__ doesn't draw. Why?
A lot of questions which I hope someone will give me some information
on.
tia,
--
Brian Elmegaard (be@mek.dtu.dk)
Dept. of Mechanical Engineering, Energy Engineering,
Technical University of Denmark, Phone +45 4525 4169 Fax +45 4593 5215
http://www.et.dtu.dk/staff/be