[wxPython-users] please help with drawing

Christopher Barker Chris.Barker at noaa.gov
Tue Mar 6 22:30:21 PST 2007


fatima cabot wrote:

> Any quick suggestion apart from doublebufferDC?

my suggestions worked for me on OS-X (I'm not at that machine now), but 
Robin noticed an error that would keep it from working on Windows. I 
don't know about GTK.

You need a little re-factoring here:

 >     self.terreno.Bind(wx.EVT_PAINT,self.OnPaint)
 >
 >     def OnPaint(self,event):
 >         dc=wx.PaintDC(self)
 >         for i in range(self.numMotes):
 >             self.motes[i][0].DrawMote(dc)
 >
 > for a class child of wx.Frame that has an attribute called initialized
 > with the default constructor of wx.Panel(self.terreno)

this is an odd structure. What you probably want is:

a custom wx.Panel that you do your drawing on. Something like:

class MotePanel(wx.Panel)
     def __init__(self, args, **kwargs)
         wx.Panel.__init__(self, *args, **kwargs)

         #initialize other stuff here	

         self.Bind(wx.EVT_PAINT, self.OnPaint)

	
     def OnPaint(self, event);
         dc = wx.PaintDC
         for i in range(self.numMotes):
             self.motes[i][0].DrawMote(dc)



There are limitations to putting things directly on a frame, so you want 
to make a panel that has the above panel, and the buttons manipulating 
it. That panel then goes on the Main Frame.

> I know my Python programming style stinks. I'm trying to do my best, but 
> I have no time to do it properly 

well, it's faster to not write getters and setters, but it takes time 
for anyone to learn.

However, if you used the DoubleBufferWindow in the wiki, you'd probably 
have it working my now -- borrow code when you can!

good luck!


-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception




More information about the wxpython-users mailing list