[wxPython-users] please help with drawing

Christopher Barker Chris.Barker at noaa.gov
Tue Mar 6 09:47:03 PST 2007


a few comments:

1) In your OnPaint, you need to use a wx.PaintDC, not a wx.ClientDC. It 
should be:

     def OnPaint(self,event):
         dc=wx.PaintDC(self.panel)
         self.DrawMote(dc)

2) It looks like you haven't bound the Paint event to the panel:

         self.panel=parent
...
         self.Bind(wx.EVT_PAINT,self.OnPaint)

You've just bound OnPaint to self, not to self.panel. It should be:

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

Those two fix your problem, but ---

making self.panel the parent is an odd choice. I"d tend to make a "Mote" 
  panel, that does all the drawing, then put that Panel in the MiPanel, 
along with the buttons.

3) your file had a mixture of dos and unix line endings, which confused 
my editor -- not a big deal.

4) This is just a style issue, but I wouldn't bother with all those 
getters and setters, just access the attributed directly. If you find 
you need to do more in the future, use properties.

http://dirtsimple.org/2004/12/python-is-not-java.html

5) For the leds, you could use DrawRectangle, instead of DrawPolygon.

6) You really want to learn how to use Sizers to place your controls, 
rather than coordinates, particularly if you want to support multiple 
platforms, multiple languages, and have easy-to-maintain code.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

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

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list