BitmapButton shows focus erroneously

Jeffrey Barish jeff_barish at earthlink.net
Mon Jun 5 10:09:41 PDT 2006


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.
-- 
Jeffrey Barish





More information about the wxpython-users mailing list