[wxPython] Focus Problem

Paul,

THANK YOU! THANK YOU! THANK YOU!

Your simple example gave me what I needed to figure this out (although I
don't understand it). I have attached a modified version of your code that
exhibits the problem I was having. I was calling .Destroy() on each dialog
after I was done with it. This works fine until you get to the custom dialog
where it will open without focus.

I found that if I remove the call to .Destroy for the dialog just previous
to wxDialog (the wxSingleChoiceDialog) then the custom wxDialog DOES RECIEVE
FOCUS!!!

Now, the question is...WHY does this happen? Is it by design or is it a bug?
I don't know, but I'm glad I figured it out.

Thanks again for taking the time to help me!

Dan

Here is an example of the 'Focus Problem':

from wxPython import wx
from sys import exit

class MyDialog(wx.wxDialog):

    def __init__(self, parent):
        wx.wxDialog.__init__(self, parent, -1, 'wxDialog')
        clb = wx.wxCheckListBox(
            self, -1, choices=['check', 'list', 'box'])
        ok = wx.wxButton(self, wx.wxID_OK, 'Ok')
        sizer = wx.wxBoxSizer(wx.wxVERTICAL)
        sizer.Add(clb, 1, wx.wxEXPAND|wx.wxALL, 5)
        sizer.Add(ok, 0, wx.wxALIGN_RIGHT|wx.wxALL^wx.wxTOP, 5)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

if __name__ == '__main__':
    
    app = wx.wxPySimpleApp()
    frame = wx.wxFrame(None, -1, 'Focus test')
    frame.Show(1)

    fd = wx.wxFileDialog(frame)
    if fd.ShowModal() == wx.wxID_OK:
        fd.Destroy()
    else:
        exit(1)

    md = wx.wxMessageDialog(frame, 'Continue?')
    if md.ShowModal() == wx.wxID_OK:
        md.Destroy()
    else:
        exit(1)

    scd = wx.wxSingleChoiceDialog(frame, 'msg', 'cap', ['single', 'choice'])
    if scd.ShowModal() == wx.wxID_OK:
        scd.Destroy() # <-- Calling destroy here will prevent myd from
getting focus!!!
    else:
        exit(1)

    myd = MyDialog(frame)
    if myd.ShowModal() == wx.wxID_OK:
        myd.Destroy()
    else:
        exit(1)

    # ... wxProgressDialog, wxMessageDialog

···

-----Original Message-----
From: Paul.Kunysch@DaimlerChrysler.com
[mailto:Paul.Kunysch@DaimlerChrysler.com]
Sent: Monday, January 22, 2001 10:50 AM
To: Dan.Rolander@marriott.com
Subject: RE: [wxPython] Focus Problem

Well, the following code works on my wxPython2.2.2/Python1.5.2/NT4sp6
system.

==========

from wxPython import wx
from sys import exit

class MyDialog(wx.wxDialog):

    def __init__(self, parent):
        wx.wxDialog.__init__(self, parent, -1, 'wxDialog')
        clb = wx.wxCheckListBox(
            self, -1, choices=['check', 'list', 'box'])
        ok = wx.wxButton(self, wx.wxID_OK, 'Ok')
        sizer = wx.wxBoxSizer(wx.wxVERTICAL)
        sizer.Add(clb, 1, wx.wxEXPAND|wx.wxALL, 5)
        sizer.Add(ok, 0, wx.wxALIGN_RIGHT|wx.wxALL^wx.wxTOP, 5)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

if __name__ == '__main__':
    
    app = wx.wxPySimpleApp()
    frame = wx.wxFrame(None, -1, 'Focus test')
    frame.Show(1)

    fd = wx.wxFileDialog(frame)
    if fd.ShowModal() != wx.wxID_OK:
        exit(1)

    md = wx.wxMessageDialog(frame, 'Continue?')
    if md.ShowModal() != wx.wxID_OK:
        exit(1)

    scd = wx.wxSingleChoiceDialog(frame, 'msg', 'cap', ['single', 'choice'])
    if scd.ShowModal() != wx.wxID_OK:
        exit(1)

    myd = MyDialog(frame)
    if myd.ShowModal() != wx.wxID_OK:
        exit(1)

    # ... wxProgressDialog, wxMessageDialog

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

I found that if I remove the call to .Destroy for the dialog just previous
to wxDialog (the wxSingleChoiceDialog) then the custom wxDialog DOES RECIEVE
FOCUS!!!

It works fine here (wx 2.3pre, win2k) so I can't be sure, but it may have something to do with the fact that it is not running within MainLoop. The system does some house cleaning activities during idle time and actually doing the cleanup of Destroy'd windows is one of them.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users