Dialog lacking focus

I am having a non-repeatable problem.
Once in a while when a modal dialog is called it takes longer than usual to appear (machine busy maybe).
When the dialog appears it doesn’t have focus. As it is a text entry dialog this is a nuisance (and with the current windows 10 default colour scheme it is not immediately apparent).
Any ideas anyone?
Thanks.

Hi, floatingshed

Wx.EVT_SHOW event can be used to give the focus to the text field when it is shown on the screen as follows:

        def on_show(evt):
            self.textctrl.SetFocus()
            evt.Skip()
        self.Bind(wx.EVT_SHOW, on_show)

I hope this helps you.

Thanks, at first I thought it had fixed the problem, but no :slightly_frowning_face:

This issue persists. It happens with any pop-up window if the PC is busy.
The window appears but does not have focus, it isn’t obvious what does have focus.
It is not code specific, any window or dialog has this problem but only on slow or busy pc.
It seems that if the dialog takes more than a certain time to appear it does so without focus.
Users are having to click on the title bar of a dialog before they can use it which is rather clumsy.
Help!

I have the same issue.

I think what’s happening is that MS Windows tries to guess whether the dialog popped up as a response to a user action. If too long time has passed between the launch interaction and the dialog opening, then MS Windows decides that the user would be surprised by having focus yanked away from what they’re doing, and denies the activation.

(Note the terminology: wxWidgets calls this activation, not focus. Focus is something that is held by an individual control within the window.)

To make it worse, for the sake of backwards compatibility Windows lies to the application so that it thinks it’s been activated, even though it’s not actually receiving input events. So you can’t even detect that it’s going on.

I think I may have created a wxWidgets issue for this at some point, but I can’t readily find it, so maybe not.

I don’t think there’s anything you can do, short of raising an issue with Microsoft.

1 Like

try:
in the dialog at wx.EVT_ACTIVATE and if evt.GetActive() then SetFocus() to the text control like @komoto48g suggested (maybe moving the cursor into it etc may be needed as well) :face_with_hand_over_mouth:

It’s been tried and it doesn’t work. SetFocus doesn’t give the dialog keyboard focus. That’s the job of Raise. But once Windows has decided that your dialog will not be allowed to grab keyboard focus, then Raise will not do it either.

well, this is becoming a somewhat ghost discussion, non repeatables, tried stuff etc, and all that on a floating shed (I hope me push bike isn’t in there)
here is some real coding to demonstrate that upgrading the hardware is always good for smoothing out irregularities (but they are not gone, just like the ordinary rubbish)

if you wind up the number of colours the dialog, which pops up every 10 secs, will become unusable (pumping up the window manager)

ok, the fault differs here by what the _core is saying, but on the other hand I haven’t seen anything of the original non repeatable :hot_face:

colour_pump_fake_with_dialog.py (5.8 KB)

well, not only for Microsoft is a dialog with a text entry not modal ! & taking that into account everything looks fine (I think) :sunglasses:

colour_pump_fake_with_dialog_hide.py (6.0 KB)
Log.py (2.2 KB)