Additional drawing in OnPaint while base class draws the rest
Hello all,
I’m working on a layout design application similar to wxDesigner. The user can create and arrange controls on a panel. I’m trying to get selected controls to draw a box around themselves. I’m trying to do this by handling EVT_PAINT thusly:
def OnPaint(self, event):
if self.selected:
dc = wxPaintDC(self)
(width, height) = self.GetClientSizeTuple()
dc.SetPen(self.selectedPen)
dc.DrawRectangle(0, 0, width, height)
event.Skip()
The problem is, for some control types, like wxBitmapButton, the creation of the wxPaintDC object appears to stop the base class from drawing itself. I end up with a white rectangle instead of a button with a box drawn inside it. I’d like for the base class to handle most of the drawing… I just want to add to it. Any ideas?
For reference, here is some more source code:
class UserCtrl(Ctrl):
def __init__(self, wxType, *_args, **_kwargs):
argList = [self]
argList.extend(_args)
apply(wxType.__init__, argList, _kwargs)
self.selected = 1
self.selectedPen = wxPen(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNHIGHLIGHT), 1, wxDOT)
EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
if self.selected:
dc = wxPaintDC(self)
(width, height) = self.GetClientSizeTuple()
dc.SetPen(self.selectedPen)
dc.DrawRectangle(0, 0, width, height)
event.Skip()
class UserBitmapButton(wxBitmapButton, UserCtrl):
def __init__(self, *_args, **_kwargs):
UserCtrl.__init__(self, wxBitmapButton, *_args, **_kwargs)
···
Motion Engineering, Inc.
**Helping you build a better machine, faster.
**
+1-805-681-3300
Fax +1-805-681-3291
matthew.thornley@motioneng.com
[www.motioneng.com](http://www.motioneng.com)