Panel keeps passing focus on to children after SetFocusIgnoringChildren

In a medium sized app, I’m having problems with panels and can’t rely on SetFocusIgnoringChildren(). Attached is example code.

Output after pressing the button is always:

before:  wx._controls.Button; proxy of ...
after:   wx._controls.TextCtrl; proxy of ...

Am I missing something here? How can I focus a Panel ignoring its children? (And I really do need it to be a panel.)

test.py (1.14 KB)

Not here:

before: <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x26adc58> >
after: <__main__.MyPanel; proxy of <Swig Object of type 'wxPanel *' at 0x365d420> >

Win7/64, Python 2.7.5, 3.0.0.0 Classic

Michael

···

On Thu, 29 Jan 2015 22:41:17 +0100, Leockard <diegote142@gmail.com> wrote:

In a medium sized app, I'm having problems with panels and can't rely on
SetFocusIgnoringChildren(). Attached is example code.

Output after pressing the button is always:

before: wx._controls.Button; proxy of ...
after: wx._controls.TextCtrl; proxy of ...

Like Michael Ross, after the button click, the panel has the focus here both with

OS X 10.10 Python 2.7.6 wx 2.9.4.0 Classic

and

Windows 8.1/64 Python 2.7.6 wx 3.0.2.0 Classic

Regards,
David Hughes

···

On Thursday, January 29, 2015 at 9:41:17 PM UTC, Leockard wrote:

In a medium sized app, I’m having problems with panels and can’t rely on SetFocusIgnoringChildren().

Thank you for your attention.
What is the course of action here then? I am running Ubuntu 14.10, and it looks like this should be a platform issue.

Leockard wrote:

Thank you for your attention.
What is the course of action here then? I am running Ubuntu 14.10, and it looks like this should be a platform issue.

What does it mean for a "panel" to have the focus? A panel doesn't
accept any input.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Well, what I want to do is kill focus on any control that can take input from the user. For example, if the user presses ESC, any text controls should hide the caret and selection and no button should have its label surrounded by a selection rect. I thought that focusing the underlying panel would be the way to do that.

···

On Fri, Jan 30, 2015 at 12:59 PM, Tim Roberts timr@probo.com wrote:

Leockard wrote:

Thank you for your attention.

What is the course of action here then? I am running Ubuntu 14.10, and it looks like this should be a platform issue.

What does it mean for a “panel” to have the focus? A panel doesn’t

accept any input.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/xW6ug9RSMBk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

why not SetFocus on the Frame, or on the object returned by [GetTopLevelParent](http://www.wxpython.org/docs/api/wx.Window-class.html#GetTopLevelParent)()

?

···

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

Well, what I want to do is kill focus on any control that can take input from the user. For example, if the user presses ESC, any text controls should hide the caret and selection and no button should have its label surrounded by a selection rect. I thought that focusing the underlying panel would be the way to do that.

This almost works. The only thing that bothers me is that if the focus is inside a TextCtrl, there’s an active selection and I then use myWin.GetTopLevelParent.SetFocus(), the selection background AND foreground become white. ???

···

On Fri, Feb 6, 2015 at 4:49 PM, Nathan McCorkle nmz787@gmail.com wrote:

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

Well, what I want to do is kill focus on any control that can take input from the user. For example, if the user presses ESC, any text controls should hide the caret and selection and no button should have its label surrounded by a selection rect. I thought that focusing the underlying panel would be the way to do that.

why not SetFocus on the Frame, or on the object returned by [GetTopLevelParent](http://www.wxpython.org/docs/api/wx.Window-class.html#GetTopLevelParent)()

?

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/xW6ug9RSMBk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nathan McCorkle wrote:

    Well, what I want to do is kill focus on any control that can take
    input from the user. For example, if the user presses ESC, any text
    controls should hide the caret and selection and no button should
    have its label surrounded by a selection rect. I thought that
    focusing the underlying panel would be the way to do that.

why not SetFocus on the Frame, or on the object returned by
>GetTopLevelParent
<wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
?

The typical way it is done is to disable the widgets you don't want to allow to have focus. Even though that changes their appearance in most themes, having a visual change that notifies the user that they can't interact with the widgets is actually a good thing, otherwise you'll have users that think it is broken. If you want to enable/disable all widgets in a panel then you should be able to just call the panel's Enable/Disable methods.

···

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

--
Robin Dunn
Software Craftsman

Thanks for the answer, Robin. Disabling all the controls will not do for my application. No matter, I have solved it in a (very hacky) way.
Is there any known reason why calling Panel.SetFocusIgnoringChildren() wasn’t working in my system?

python: 2.7.8

wxpython: 3.0.0.0 gtk2 (classic)

linux: 3.13.0-24-generic Ubuntu 14.10 Utopic x86_64

···

On Wed, Feb 11, 2015 at 12:14 AM, Robin Dunn robin@alldunn.com wrote:

Nathan McCorkle wrote:

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

Well, what I want to do is kill focus on any control that can take

input from the user. For example, if the user presses ESC, any text

controls should hide the caret and selection and no button should

have its label surrounded by a selection rect. I thought that

focusing the underlying panel would be the way to do that.

why not SetFocus on the Frame, or on the object returned by

|GetTopLevelParent

<http://www.wxpython.org/docs/api/wx.Window-class.html#GetTopLevelParent>()|

?

The typical way it is done is to disable the widgets you don’t want to allow to have focus. Even though that changes their appearance in most themes, having a visual change that notifies the user that they can’t interact with the widgets is actually a good thing, otherwise you’ll have users that think it is broken. If you want to enable/disable all widgets in a panel then you should be able to just call the panel’s Enable/Disable methods.

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/xW6ug9RSMBk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Earlier you mentioned trying to SetFocus() on a Panel, which seems like it will have no effect in general.

···

On Wednesday, February 11, 2015 at 10:53:15 AM UTC-8, Leonardo Torres wrote:

Thanks for the answer, Robin. Disabling all the controls will not do for my application. No matter, I have solved it in a (very hacky) way.
Is there any known reason why calling Panel.SetFocusIgnoringChildren() wasn’t working in my system?

python: 2.7.8

wxpython: 3.0.0.0 gtk2 (classic)

linux: 3.13.0-24-generic Ubuntu 14.10 Utopic x86_64

I meant SetFocusIgnoringChildren(), not just SetFocus()

···

On Wednesday, February 11, 2015 at 1:43:02 PM UTC-8, Nathan McCorkle wrote:

On Wednesday, February 11, 2015 at 10:53:15 AM UTC-8, Leonardo Torres wrote:

Thanks for the answer, Robin. Disabling all the controls will not do for my application. No matter, I have solved it in a (very hacky) way.
Is there any known reason why calling Panel.SetFocusIgnoringChildren() wasn’t working in my system?

python: 2.7.8

wxpython: 3.0.0.0 gtk2 (classic)

linux: 3.13.0-24-generic Ubuntu 14.10 Utopic x86_64

Earlier you mentioned trying to SetFocus() on a Panel, which seems like it will have no effect in general.

Then why have it?

···

On Wed, Feb 11, 2015 at 4:43 PM, Nathan McCorkle nmz787@gmail.com wrote:

On Wednesday, February 11, 2015 at 1:43:02 PM UTC-8, Nathan McCorkle wrote:

On Wednesday, February 11, 2015 at 10:53:15 AM UTC-8, Leonardo Torres wrote:

Thanks for the answer, Robin. Disabling all the controls will not do for my application. No matter, I have solved it in a (very hacky) way.
Is there any known reason why calling Panel.SetFocusIgnoringChildren() wasn’t working in my system?

python: 2.7.8

wxpython: 3.0.0.0 gtk2 (classic)

linux: 3.13.0-24-generic Ubuntu 14.10 Utopic x86_64

Earlier you mentioned trying to SetFocus() on a Panel, which seems like it will have no effect in general.

I meant SetFocusIgnoringChildren(), not just SetFocus()

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/xW6ug9RSMBk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

I’m on Windows and wx.version() says 3.0.0.0 msw

Your example seems to work, when the button is clicked the focus is pulled from the text box:

before: <wx._controls.Button; proxy of <Swig Object of type ‘wxButton *’ at 0x22af468> >

after: <main.MyPanel; proxy of <Swig Object of type ‘wxPanel *’ at 0x31441e8> >

···

On Thursday, January 29, 2015 at 1:41:17 PM UTC-8, Leockard wrote:

In a medium sized app, I’m having problems with panels and can’t rely on SetFocusIgnoringChildren(). Attached is example code.

Output after pressing the button is always:

before:  wx._controls.Button; proxy of ...
after:   wx._controls.TextCtrl; proxy of ...

Am I missing something here? How can I focus a Panel ignoring its children? (And I really do need it to be a panel.)

I just tried GetTopLevelParent().SetFocus() in the button handler in your example and that also seems to work for me here:

before: <wx._controls.Button; proxy of <Swig Object of type ‘wxButton *’ at 0x222ee88> >

after: <main.Test; proxy of <Swig Object of type ‘wxFrame *’ at 0x1f6b760> >

I don’t recommend doing this though, as if you ever import this Frame from another file, the top-level parent won’t be the same as when you use this GUI standalone.

I’ve attached a modified version of your code, which also works for me (I wanted to try it with everything on a Panel, rather than some widgets being directly on the Frame). Supposedly having widget (drawn things) on panels is better for cross-platform, idk if that could be your issue.

test_focus.py (1.2 KB)

···

On Friday, February 6, 2015 at 1:49:37 PM UTC-8, Nathan McCorkle wrote:

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

Well, what I want to do is kill focus on any control that can take input from the user. For example, if the user presses ESC, any text controls should hide the caret and selection and no button should have its label surrounded by a selection rect. I thought that focusing the underlying panel would be the way to do that.

why not SetFocus on the Frame, or on the object returned by [GetTopLevelParent](http://www.wxpython.org/docs/api/wx.Window-class.html#GetTopLevelParent)()

Nathan, thank you for the response.
As I said in a previous post, I have since solved my problem with a hacky work-around.

My only question is: is there a known reason that Panel.SetFocusIgnoringChildren() won’t work in my system? And, if so many users are expecting it not to do anything, then why have it at all?

···

On Wednesday, February 11, 2015 at 4:54:24 PM UTC-5, Nathan McCorkle wrote:

On Friday, February 6, 2015 at 1:49:37 PM UTC-8, Nathan McCorkle wrote:

On Sunday, February 1, 2015 at 6:29:57 AM UTC-8, Leonardo Torres wrote:

Well, what I want to do is kill focus on any control that can take input from the user. For example, if the user presses ESC, any text controls should hide the caret and selection and no button should have its label surrounded by a selection rect. I thought that focusing the underlying panel would be the way to do that.

why not SetFocus on the Frame, or on the object returned by [GetTopLevelParent](http://www.wxpython.org/docs/api/wx.Window-class.html#GetTopLevelParent)()

I just tried GetTopLevelParent().SetFocus() in the button handler in your example and that also seems to work for me here:

before: <wx._controls.Button; proxy of <Swig Object of type ‘wxButton *’ at 0x222ee88> >

after: <main.Test; proxy of <Swig Object of type ‘wxFrame *’ at 0x1f6b760> >

I don’t recommend doing this though, as if you ever import this Frame from another file, the top-level parent won’t be the same as when you use this GUI standalone.

I’ve attached a modified version of your code, which also works for me (I wanted to try it with everything on a Panel, rather than some widgets being directly on the Frame). Supposedly having widget (drawn things) on panels is better for cross-platform, idk if that could be your issue.

Leockard wrote:

Nathan, thank you for the response.
As I said in a previous post, I have since solved my problem with a
hacky work-around.
My only question is: is there a known reason that
Panel.SetFocusIgnoringChildren() won't work in my system? And, if so
many users are expecting it not to do anything, then why have it at all?

I haven't heard of any issues with it, and I would expect it to work, but I suppose it's possible that some style settings or some other component in the application is interfering with it. It basically just bypasses the code in wxPanel that looks for a child that will accept focus and falls back to calling the SetFocus in the parent class.

···

--
Robin Dunn
Software Craftsman

I did think that it could be one of the more obscure features of my application. Until I tested the code I posted in one of my earlier posts, that is.

···

On Fri, Mar 6, 2015 at 8:28 PM, Robin Dunn robin@alldunn.com wrote:

Leockard wrote:

Nathan, thank you for the response.

As I said in a previous post, I have since solved my problem with a

hacky work-around.

My only question is: is there a known reason that

Panel.SetFocusIgnoringChildren() won’t work in my system? And, if so

many users are expecting it not to do anything, then why have it at all?

I haven’t heard of any issues with it, and I would expect it to work, but I suppose it’s possible that some style settings or some other component in the application is interfering with it. It basically just bypasses the code in wxPanel that looks for a child that will accept focus and falls back to calling the SetFocus in the parent class.

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/xW6ug9RSMBk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.