I have a panel to which I have bounded a wx.EVT_KEY_DOWN.
Part of the interface is hidden to the user, and only intervention by
an external person can unlock it, via a key combination unknown to the
user. This might seem strange, but the App is used in an experimental
setting, and the experiment can go on only after intervention by the
experimenter.
In linux (wxGTK), this works as a charm; but in windows, an
inadvertent pressing of the TAB key on the part of the user - or the
experiment - steals the focus away from the panel to the widgets
present in the interface (there is a disabled button, and a disabled
TextCtrl, plus StaticTexts), so that the panel does not capture any
more Key events - it has no focus. The focus never returns to the
panel, and hence the interface is frozen in place.
I need the focus to stay with the panel, so that even if subjects
inadvertently hit the TAB key, the experiment can go on.
I have tried to capture the Tab key pressing and make this event set
the focus back to the panel (panel.SetFocus()) but this does not
work.
One solution would be to disable Tab-key support for this frame - but
I do not know how to do this.
Moreover, why does the focus get stolen away in Windows and not in
Linux?
There are probably a couple issues at work here. First, on Windows the navigation keys are usually stolen before we can get key events for them. Second, wx.Panels will try to not keep the focus when they get it, usually passing it on to child widgets if one of them will accept the focus, and there may be some other situations when it might pass it on to sibling panels as well.
Here are a couple ideas you can try:
* Turn off the tab traversal functionality on the panel by creating it with style=0.
* Disable other widgets in the frame while your panel is active.
* Put a password field on the panel (wx.TextCtrl with style wx.TE_PASSWORD) and keep the focus there instead of on the panel.
···
On 5/7/11 8:33 AM, Paolo Crosetto wrote:
Dear All,
I have a panel to which I have bounded a wx.EVT_KEY_DOWN.
Part of the interface is hidden to the user, and only intervention by
an external person can unlock it, via a key combination unknown to the
user. This might seem strange, but the App is used in an experimental
setting, and the experiment can go on only after intervention by the
experimenter.
In linux (wxGTK), this works as a charm; but in windows, an
inadvertent pressing of the TAB key on the part of the user - or the
experiment - steals the focus away from the panel to the widgets
present in the interface (there is a disabled button, and a disabled
TextCtrl, plus StaticTexts), so that the panel does not capture any
more Key events - it has no focus. The focus never returns to the
panel, and hence the interface is frozen in place.
I need the focus to stay with the panel, so that even if subjects
inadvertently hit the TAB key, the experiment can go on.
I have tried to capture the Tab key pressing and make this event set
the focus back to the panel (panel.SetFocus()) but this does not
work.
One solution would be to disable Tab-key support for this frame - but
I do not know how to do this.
Moreover, why does the focus get stolen away in Windows and not in
Linux?
as always, thank you very much for your insights. A report for future
uses:
* setting style=0 in the panel works - Tab keys do not steal the focus
any more.
* Disabling other widgets did not work before - indeed, the focus got
stolen away from the panel to a disabled textctrl and button.
* I did not try the last suggestion.
Best,
Paolo
···
On 7 Mag, 22:25, Robin Dunn <ro...@alldunn.com> wrote:
On 5/7/11 8:33 AM, Paolo Crosetto wrote:
> Dear All,
> I have a panel to which I have bounded a wx.EVT_KEY_DOWN.
> Part of the interface is hidden to the user, and only intervention by
> an external person can unlock it, via a key combination unknown to the
> user. This might seem strange, but the App is used in an experimental
> setting, and the experiment can go on only after intervention by the
> experimenter.
> In linux (wxGTK), this works as a charm; but in windows, an
> inadvertent pressing of the TAB key on the part of the user - or the
> experiment - steals the focus away from the panel to the widgets
> present in the interface (there is a disabled button, and a disabled
> TextCtrl, plus StaticTexts), so that the panel does not capture any
> more Key events - it has no focus. The focus never returns to the
> panel, and hence the interface is frozen in place.
> I need the focus to stay with the panel, so that even if subjects
> inadvertently hit the TAB key, the experiment can go on.
> I have tried to capture the Tab key pressing and make this event set
> the focus back to the panel (panel.SetFocus()) but this does not
> work.
> One solution would be to disable Tab-key support for this frame - but
> I do not know how to do this.
> Moreover, why does the focus get stolen away in Windows and not in
> Linux?
There are probably a couple issues at work here. First, on Windows the
navigation keys are usually stolen before we can get key events for
them. Second, wx.Panels will try to not keep the focus when they get
it, usually passing it on to child widgets if one of them will accept
the focus, and there may be some other situations when it might pass it
on to sibling panels as well.
Here are a couple ideas you can try:
* Turn off the tab traversal functionality on the panel by creating it
with style=0.
* Disable other widgets in the frame while your panel is active.
* Put a password field on the panel (wx.TextCtrl with style
wx.TE_PASSWORD) and keep the focus there instead of on the panel.
--
Robin Dunn
Software Craftsmanhttp://wxPython.org