[wxPython-users] About wx.Window default OnPaint function

Robin Dunn robin at alldunn.com
Mon Jan 7 11:03:17 PST 2008


甜瓜 wrote:
> Howdy,
>      I notice that there is a OnPaint method exported from wx.Window,
> but it is not documented in the wxpython online doc. I wonder what it
> is used for?

It should be considered an undocumented implementation detail, so if you 
can avoid it then don't use it.  Also, it only exists on Windows.


>     Will OnPaint do all default paintings according to the type of
> window? If so, it will be really useful in the case of custom
> controls. For example, I want to do some owner draw:
> 
> class MyBitmapButton(wx.BitmapButton):
>       def __init__(...):
>              self.Bind(wx.EVT_PAINT, self.OnPaint)
>              ...
>       def OnPaint(self, evt):
>             # Here, I want to draw something AFTER the wx.BitmapButton
> default drawings.
>             # so:
>             wx.BitmapButton.OnPaint(self, evt)
>             ... # do my drawings.
> 
>     Above code is not tested yet. I wonder whether it works and
> whether it is a generally correct for all wx controls.

I think stuff like that is the intent of making it public, but I've 
never tried it myself.


>     Again, wxWidget::ScrolledWindow exports OnDraw method to simplify
> DoPrepareDC, but why  is there no corresponding method in
> wx.ScrolledWindow?

http://wiki.wxpython.org/OverridingMethods

Since all OnDraw does is save you from having to call PrepareDC yourself
I felt that it wasn't worth the overhead of making that C++ method 
overridable in Python classes.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!




More information about the wxpython-users mailing list