New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling SetFocus on a child window in SettingsDialog.postInit has the side effect of also showing the dialog #5951
Comments
I could be mistaken, but I'm pretty sure wx didn't always set focus to
the first control in a dialog, which I believe is why postInit does
this. I vaguely recall it used to set it to the last control created,
but that could be totally incorrect. However, it certainly seems to now
(more than it should in fact; in some cases, it resets the focus when
you alt+tab back in, which is broken). If I'm right and this did change,
it was probably when we moved from wx 2 to wx 3.
It's worth noting that wx doesn't document that SetFocus will show the
dialog. The fact that it does makes things difficult because any change
here risks a backwards compatibility break. I'm tempted to say we should
just call postInit on a show event, but we'd then need to make sure it
only happens for the first show and that could cause weirdness (e.g.
focus jumping or visual flickering) depending on what the caller does in
postInit.
|
@LeonarddeR, now that the above issues have settled down, is it worth bringing the attention of this issue up again? |
@jscholes, @LeonarddeR do you still see this issue? |
@jscholes are you still available? |
I'm also pretty sure that wx doesn't set focus correctly if we don't do this explicitly. |
As far as I know, this is still an issue in wxPython. But since I filed this issue the Settings dialog has been completely revamped. Originally, I filed it because of the way a particular add-on (https://github.com/ABuffEr/rapidSettings) worked, but the new unified Settings dialog makes that add-on obsolete. Feel free to close it. |
Closing as requested. If there are specific issues related to this topic, please comment on this and we can reopen it. or create a new issue if needed. Thanks. |
In All of the built-in settings dialogs, the SettingsDialog.postInit method is overridden to set focus to the first focusable child control in that dialog. For example, in SettingsDialogs.GeneralSettingsDialog.postInit, focus is set to the list of languages. This behaviour is encouraged in the SettingsDialog.postInit docstring.
However, perhaps due to a wx bug or maybe this is intended behaviour, this has the side effect of also showing the dialog, regardless of whether the dialog's Show method is subsequently called. This makes the dialogs unsuitable for instantiation in code which doesn't necessarily want to show them on screen straight away (or at all).
If explicitly setting focus to the first child control is really necessary, which it shouldn't be as it usually happens automatically in wx dialogs, this should only take place in a method designated as a handler for a wx.EVT_SHOW event. I'm happy to submit a pull request at some point if this is an appropriate change, although you may have thoughts on how to implement this with minimal API changes.
The text was updated successfully, but these errors were encountered: