I'm looking at the wxDialog sample in the demo app.
I'm trying to figure out how to intercept the close
event for a wxDialog so I can check and see if the
user clicked the OK button with id = wxID_OK or the
cancel button with id = wxID_CANCEL. If the user
clicked wxID_OK then I'll save their changes to the
database. Otherwise, I'll just let the window close.
Thanks in advance for any help.
Here's the relevant code for the buttons from the
demo.
btn = wxButton(self, wxID_OK, " OK ")
btn.SetDefault()
btn.SetHelpText("The OK button completes the
dialog")
box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5)
I'm looking at the wxDialog sample in the demo app.
I'm trying to figure out how to intercept the close
event for a wxDialog so I can check and see if the
user clicked the OK button with id = wxID_OK or the
cancel button with id = wxID_CANCEL. If the user
clicked wxID_OK then I'll save their changes to the
database. Otherwise, I'll just let the window close.
If you're using a standard modal dialog, the way to do this is outside of the dialog procedure itself. Something along the lines of this:
dialog = wxDialog( ... )
clicked = dialog.ShowModal()
if clicked == wxID_OK:
value = dialog.control.GetValue()
# now save value to database
You should be able to find a more complete example in the demo, under Windows/wxDialog.
Jeff Shannon
Technician/Programmer
Credit International
I'm looking at the wxDialog sample in the demo app.
I'm trying to figure out how to intercept the close
event for a wxDialog so I can check and see if the
user clicked the OK button with id = wxID_OK or the
cancel button with id = wxID_CANCEL. If the user
clicked wxID_OK then I'll save their changes to the
database. Otherwise, I'll just let the window close.
If you're using a standard modal dialog, the way to do this is outside of the dialog procedure itself. Something along the lines of this:
dialog = wxDialog( ... )
clicked = dialog.ShowModal()
if clicked == wxID_OK:
value = dialog.control.GetValue()
# now save value to database
A little more info: wxDialog has a method EndModal that is used to cause the event loop to end and for ShowModal to return. Whatever (integer) value is passed to EndModal is what is returned from the call to ShowModal, so you can use that to decide what to do, like in the above sample. wxDialog has default EVT_BUTTON handlers for IDs wxID_OK and wxID_CANCEL which will call EndModal for you. If you have other buttons or other ways to end the dialog then you just need to provide the necessary event handlers and have them call EndModal(somevalue).
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!