[wxPython] Focus Problem

Rolander, Dan Dan.Rolander at marriott.com
Mon Jan 22 12:15:46 EST 2001


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 at DaimlerChrysler.com
[mailto:Paul.Kunysch at DaimlerChrysler.com]
Sent: Monday, January 22, 2001 10:50 AM
To: Dan.Rolander at 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






More information about the Python-list mailing list