Buttons don't close dialog in wxPython
Volker Bartheld
dr_versaeg at freenet.de
Thu Jan 25 09:23:58 PST 2007
Hi!
On Thu, 25 Jan 2007 17:00:04 +0000, Tom Wright <tew24 at spam.ac.uk> wrote
>I'm trying to make a custom dialog box in wxPython, which has four
>buttons.
>I want each of these buttons to close the dialog and generate a different
>code when I do a .ShowModal()
What speaks against a dialog sceleton like this:
enum wxIDS { ID_BUTTON1=wxID_HIGHEST+1, ID_BUTTON2, ID_BUTTON3 };
class TestDialog : public wxDialog
{
public:
TestDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = wxT("dialogBox"))
: wxDialog(parent, id, title, pos, size, style, name)
{
wxBoxSizer *pSizerMain = new wxBoxSizer(wxVERTICAL);
SetSizer(pSizerMain);
pSizerMain->Add(new wxButton(this, ID_BUTTON1, wxT("1")));
pSizerMain->Add(new wxButton(this, ID_BUTTON2, wxT("2")));
pSizerMain->Add(new wxButton(this, ID_BUTTON3, wxT("3")));
}
void OnClose(wxCloseEvent &event) { if(IsModal()) EndModal(event.GetId); else Destroy(); }
void OnButton(wxCommandEvent &event) { OnClose(wxCloseEvent(0, event.GetId())); }
DECLARE_EVENT_TABLE()
}; // class TestDialog : public wxDialog
BEGIN_EVENT_TABLE(TestDialog, wxDialog)
EVT_COMMAND_RANGE(ID_BUTTON1, ID_BUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, TestDialog::OnButton)
EVT_CLOSE(TestDialog::OnClose)
END_EVENT_TABLE()
I'm more the C++ guy but the above should somehow also work with
wxPython.
Good luck,
Volker
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list