[wxPython-users] Re: Re: BitmapButton shows focus erroneously

Robin Dunn robin at alldunn.com
Tue Jun 6 09:13:11 PDT 2006


Jeffrey Barish wrote:
> Jeffrey Barish wrote:
> 
>> Robin Dunn wrote:
>>
>>> Jeffrey Barish wrote:
>>>> You are right: This change solves the problem with focus.  But now I
>>>> can't get the button to do anything because it no longer produces
>>>> EVT_BUTTON. Wait, I wasn't getting EVT_BUTTON in the original version of
>>>> the test
>>>> (without the CallAfter) either.  I'm confused because the buttons still
>>>> work in the actual program even though they go into the metafocus mode.
>>> This is strange.  Perhaps the native control is checking focus before
>>> sending of the button event, or something like that.  (As further
>>> evidence of this being a native behavior, it works fine in wxGTK.)  In
>>> any case you can just move your SetFocus call to a EVT_BUTTON handler.
>>>
>> I had the same idea after sending my message.  That solution works -- in
>> the test program, at least.
> 
> There are two complications that prevent the solution from working well in
> the actual program.  The first may seem minor, but it points to the second,
> which is not.  As long as the button is down, it actually has the focus
> (because the focus does not get fixed until after the button event), so the
> graphic shows the dashed line that appears when a window has focus. 
> Because the visual corruption is transient, it is a minor aesthetic
> concern.  The second complication is more significant: Because the button
> actually gets the focus while it is depressed, other windows lose the
> focus.  In my application, some controls have their background shaded when
> they have the focus, so pushing a button causes the shading to disappear
> and then reappear an instant later when the button is released.  This
> flashing looks very bad.  I suppose that it would be possible to detect in
> the focus kill handler whether the focus is going to one of the buttons
> (and not change the background in that case), but then the handler would
> have to know something about the layout of the application, which is bad
> programming practice.  I already have to detect whether a button triggered
> a set focus event so that I know whether to defer the SetFocus call until
> after the button event, so maybe this additional pollution isn't so
> noisome, but I'm not happy with any pollution.  On the other hand,
> detecting the source of the focus event may be the only solution to this
> problem.

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.

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





More information about the wxpython-users mailing list