Date: Fri, 12 Apr 2002 00:28:35 +0200
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] modal dialog becomes modeless
Reply-To: wxpython-users@lists.wxwindows.org
But I'm a bit curious about the lost modality. When you do
dialog.ShowModal() your code will normally wait here until
you close your modal dialog. Then it will run the rest of
the code where you typically check what button you pressed etc.
What happens when you "loose modality"?
Let's say you put a print statement directly after ShowModal,
when is that run?When you open the tablepreview?
<When you close the tablepreview?
When you get back to your dialog and close it?
Never?
I have added a minimal example. When the modal dialog opens everything
is fine. You press Preview and the Table Preview opens. You look, maybe
print the table and close the Preview. Voila, the dialog isn't modal any
more (cick on the titlebar of mainframe, not the Dialog button again).
--------------snip---------------
from wxPython.wx import *
from wxPython.lib.printout import PrintTable
B_ID=wxNewId()
B2_ID=wxNewId()
···
From: Magnus =?iso-8859-1?Q?Lyck=E5?= <magnus@thinkware.se>
#---------------------------------------------------------------------------
class MainFrame(wxFrame):
def __init__(self, parent, id):
wxFrame.__init__(self, parent=parent,id= -1, title='title', size =
(500, 500),
style=wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxSYSTEM_MENU
wxCAPTION)
butt=wxButton(self,B_ID,'Dialog')
EVT_BUTTON(self,B_ID,self.Dialog)
#-------------
def Dialog(self,event):
d=modaldialog(self)
if d.ShowModal()==wxID_OK:
pass
#-------------
class modaldialog(wxDialog):
def __init__(self,parent):
self.parent=parent
wxDialog.__init__(self,parent,-1,title='modal
dialog',size=wxDefaultSize,style=wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
self.SetAutoLayout(true)
butt2=wxButton(self,B2_ID,'Preview')
EVT_BUTTON(self,B2_ID,self.Preview)
butt3=wxButton(self,wxID_OK,'OK')
box=wxBoxSizer(wxVERTICAL)
box.Add(butt2,0,wxEXPAND)
box.Add(butt3,0,wxEXPAND)
box.Fit(self)
self.SetSizer(box)
self.Layout()
#-------------
def Preview(self,event):
prt=PrintTable(self.parent)
prt.data=[('a','b','c','d','e')]
prt.data.append(('a','b','c','d','e'))
prt.set_column=[1,1,1,1,1]
prt.label=['a','b','c','d','e']
title='Tabel Title'
prt.SetHeader(title)
prt.Preview()
#-------------
class PTime(wxApp):
def OnInit(self):
frame = MainFrame(NULL, -1)
frame.Show(true)
self.SetTopWindow(frame)
return true
#-------------
app = PTime(0)
app.MainLoop()
--------------snip---------------
Marcus