BitmapButton shows focus erroneously

Jeffrey Barish jeff_barish at earthlink.net
Wed Aug 23 12:06:38 PDT 2006


Robin Dunn wrote:
> The only thing I can think of is to decouple the code that decides when 
> to set the bg color out of the controls and move it into some sort of 
> highlight manager class.  When a control that is supposed to set its bg 
> color receives the focus then it asks the highlight manager if it can do 
> it.  The highlight manager keeps track of which control currently has 
> the highlight and notifies it if a new control requests it so the 
> current one can reset its bg to the default.  Since the buttons would 
> not request the highlight then the current highlighted control would not 
> lose it.

I implemented something close to this proposal and it works nicely, but
there was still one small problem.  If I covered my application and then
exposed it, the shading would disappear.  I solved the problem, but I am
not confident that my solution is optimal.  First I catch the paint event
directed to the main panel:

    def doMainPanelPaint(self, event):
        wx.PaintDC(self) # online doc says must create PaintDC object
                         # even if not used
        self.backgroundManager.resetFocus()
        event.Skip()

Then the BackgroundManager restores the background:

    def resetFocus(self):
        win = self.restoreFocusWin
        if win.GetBackgroundColour != self.shadedCol:
            win.SetBackgroundColour(self.shadedCol)
            win.Refresh(True)

I am worried about this solution because doMainPanelPaint gets called
frequently for events that have nothing to do with restoring the background
shading.  Is there another event that relates more closely to the problem I
am solving?  Is the overhead for my handler small?  I suppose that
something like the wx.PaintDC call happens regardless, so if the call to
resetFocus is the extent of the overhead then perhaps it is negligible.

I just noticed that when I minimize and restore my application, the shading
is right but the application no longer responds to keyboard commands to
move the focus, so probably I still have something wrong.
-- 
Jeffrey Barish





More information about the wxpython-users mailing list