Frame focus

I have an application that has two frames. One frame is opened at
initial program launch and the second frame can be launched by
clicking a button on the first frame. The two frames are not modal as
I want to be able to have both of them open and responsive to user
input at the same time. This works except that when I call up and
subsequently close a dialog box from the second frame, the focus goes
back to the first frame. I want the focus to stay on the second frame.
I am not sure what I am doing wrong and I can not seem to find any
examples.

Thanks.

The sample code you sent works fine. It is a little different from
what I am doing though. I am opening frame 1 in wx.App. Frame 1 is
always open. I am opening frame 2 from frame 1. So frame 2 may not
always be open but when it is it should not block frame 1. I suspect I
do not have the parent/child relationship set up correctly.

···

2009/3/29 Peter Damoc <pdamoc@gmail.com>:

Hi Glenn,

This is strange. The focus should go to the parent of the dialog.

here is a small app that does the same thing. Is the behavior present in it
too? (look for the focus ring around the buttons)
What version of wxpython do you have? What OS?

import wx

class MyFrame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title)
button = wx.Button(self, label="push me")
button.Bind(wx.EVT_BUTTON, self.OnButton)

def OnButton\(self, evt\):
    dlg = wx\.MessageDialog\(self, &#39;Hello from Python and wxPython\!&#39;,
                           &#39;A Message Box&#39;,
                           wx\.OK | wx\.ICON\_INFORMATION
                           \#wx\.YES\_NO | wx\.NO\_DEFAULT | wx\.CANCEL |

wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()

app =wx.App(0)
frame1 = MyFrame("Frame1")
frame2 = MyFrame("Frame2")
frame1.Show()
frame2.Show()
app.MainLoop()

On Sun, Mar 29, 2009 at 8:59 AM, Glenn Johnson <glennpj@gmail.com> wrote:

I have an application that has two frames. One frame is opened at
initial program launch and the second frame can be launched by
clicking a button on the first frame. The two frames are not modal as
I want to be able to have both of them open and responsive to user
input at the same time. This works except that when I call up and
subsequently close a dialog box from the second frame, the focus goes
back to the first frame. I want the focus to stay on the second frame.
I am not sure what I am doing wrong and I can not seem to find any
examples.

Thanks.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Attached is a snippet that demonstates the problem. I basically
extracted this from my program and changed the titles etc. to
(hopefully) make sense in the context of the problem behavior.

Thanks.

two_frames.py (1.63 KB)

···

On Sun, Mar 29, 2009 at 2:51 PM, Glenn Johnson <glennpj@gmail.com> wrote:

The sample code you sent works fine. It is a little different from
what I am doing though. I am opening frame 1 in wx.App. Frame 1 is
always open. I am opening frame 2 from frame 1. So frame 2 may not
always be open but when it is it should not block frame 1. I suspect I
do not have the parent/child relationship set up correctly.

2009/3/29 Peter Damoc <pdamoc@gmail.com>:

Hi Glenn,

This is strange. The focus should go to the parent of the dialog.

here is a small app that does the same thing. Is the behavior present in it
too? (look for the focus ring around the buttons)
What version of wxpython do you have? What OS?

import wx

class MyFrame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title)
button = wx.Button(self, label="push me")
button.Bind(wx.EVT_BUTTON, self.OnButton)

def OnButton\(self, evt\):
    dlg = wx\.MessageDialog\(self, &#39;Hello from Python and wxPython\!&#39;,
                           &#39;A Message Box&#39;,
                           wx\.OK | wx\.ICON\_INFORMATION
                           \#wx\.YES\_NO | wx\.NO\_DEFAULT | wx\.CANCEL |

wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()

app =wx.App(0)
frame1 = MyFrame("Frame1")
frame2 = MyFrame("Frame2")
frame1.Show()
frame2.Show()
app.MainLoop()

On Sun, Mar 29, 2009 at 8:59 AM, Glenn Johnson <glennpj@gmail.com> wrote:

I have an application that has two frames. One frame is opened at
initial program launch and the second frame can be launched by
clicking a button on the first frame. The two frames are not modal as
I want to be able to have both of them open and responsive to user
input at the same time. This works except that when I call up and
subsequently close a dialog box from the second frame, the focus goes
back to the first frame. I want the focus to stay on the second frame.
I am not sure what I am doing wrong and I can not seem to find any
examples.

Thanks.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I got it working but I am not sure why I had to change:

class EditDialog(wx.Dialog):
    def __init__(self, title):
        wx.Dialog.__init__(self, None, -1, title)

to:

class EditDialog(wx.Dialog):
    def __init__(self, parent, ID, title):
        wx.Dialog.__init__(self, parent, ID, title)

Then in the second frame class:

        edit_d = EditDialog('Dialog')

to:
        edit_d = EditDialog(self, -1, 'Dialog')

This is not necessary for dialogs called from Frame1 (the initial frame).

···

On Sun, Mar 29, 2009 at 3:55 PM, Glenn Johnson <glennpj@gmail.com> wrote:

Attached is a snippet that demonstates the problem. I basically
extracted this from my program and changed the titles etc. to
(hopefully) make sense in the context of the problem behavior.

Thanks.

On Sun, Mar 29, 2009 at 2:51 PM, Glenn Johnson <glennpj@gmail.com> wrote:

The sample code you sent works fine. It is a little different from
what I am doing though. I am opening frame 1 in wx.App. Frame 1 is
always open. I am opening frame 2 from frame 1. So frame 2 may not
always be open but when it is it should not block frame 1. I suspect I
do not have the parent/child relationship set up correctly.

2009/3/29 Peter Damoc <pdamoc@gmail.com>:

Hi Glenn,

This is strange. The focus should go to the parent of the dialog.

here is a small app that does the same thing. Is the behavior present in it
too? (look for the focus ring around the buttons)
What version of wxpython do you have? What OS?

import wx

class MyFrame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title)
button = wx.Button(self, label="push me")
button.Bind(wx.EVT_BUTTON, self.OnButton)

def OnButton\(self, evt\):
    dlg = wx\.MessageDialog\(self, &#39;Hello from Python and wxPython\!&#39;,
                           &#39;A Message Box&#39;,
                           wx\.OK | wx\.ICON\_INFORMATION
                           \#wx\.YES\_NO | wx\.NO\_DEFAULT | wx\.CANCEL |

wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()

app =wx.App(0)
frame1 = MyFrame("Frame1")
frame2 = MyFrame("Frame2")
frame1.Show()
frame2.Show()
app.MainLoop()

On Sun, Mar 29, 2009 at 8:59 AM, Glenn Johnson <glennpj@gmail.com> wrote:

I have an application that has two frames. One frame is opened at
initial program launch and the second frame can be launched by
clicking a button on the first frame. The two frames are not modal as
I want to be able to have both of them open and responsive to user
input at the same time. This works except that when I call up and
subsequently close a dialog box from the second frame, the focus goes
back to the first frame. I want the focus to stay on the second frame.
I am not sure what I am doing wrong and I can not seem to find any
examples.

Thanks.
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
There is NO FATE, we are the creators.
blog: http://damoc.ro/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Peter Damoc wrote:

Dialogs have orphan depression disorder.
Frames can handle better being without a parent... Dialogs are a little bit more immature... they panic from time to time... :slight_smile:

Silly as it sounds this is totally true. If you don't give a dialog an explicit parent then wx will try to give it one, and it uses wx.GetApp().GetTopWindow() to do so.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Silly as it sounds this is totally true. If you don't give a dialog an explicit parent then wx will try to give it one, and it uses wx.GetApp().GetTopWindow() to do so.

Really? This didn't appear to be the case for my code. I was creating dialogs without parents, but then when I shut down all the frames of the app, the app didn't shut down, which led me to believe that those parent-less dialogs were still alive, keeping the app alive. That wouldn't' happen if they were parented, would it?

When I made sure to parent all the dialogs, the issue went away.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov