From 201ebeaa961f6aa14dae85463396035feb82ca8e Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 11 Feb 2003 19:24:46 +0000 Subject: [PATCH] Change to a derived dialog class git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19185 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/demo/wxDialog.py | 123 ++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/wxPython/demo/wxDialog.py b/wxPython/demo/wxDialog.py index e1ce4e1516..242e706c05 100644 --- a/wxPython/demo/wxDialog.py +++ b/wxPython/demo/wxDialog.py @@ -3,79 +3,100 @@ from wxPython.wx import * from wxPython.help import * #--------------------------------------------------------------------------- +# Create and set a help provider. Normally you would do this in +# the app's OnInit as it must be done before any SetHelpText calls. +provider = wxSimpleHelpProvider() +wxHelpProvider_Set(provider) -def runTest(frame, nb, log): -## win = wxDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200), -## style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME -## #style = wxDEFAULT_DIALOG_STYLE -## ) - # Create and set a help provider. Normally you would do this in - # the app's OnInit as it must be done before any SetHelpText calls. - provider = wxSimpleHelpProvider() - wxHelpProvider_Set(provider) - win = wxPreDialog() - win.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP) - win.Create(frame, -1, "This is a wxDialog", size=wxSize(350, 200), - #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME - style = wxDEFAULT_DIALOG_STYLE - ) +#--------------------------------------------------------------------------- - sizer = wxBoxSizer(wxVERTICAL) +class TestDialog(wxDialog): + def __init__(self, parent, ID, title, + pos=wxDefaultPosition, size=wxDefaultSize, + style=wxDEFAULT_DIALOG_STYLE): - label = wxStaticText(win, -1, "This is a wxDialog") - label.SetHelpText("This is the help text for the label") - sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) + # Instead of calling wxDialog.__init__ we precreate the dialog + # so we can set an extra style that must be set before + # creation, and then we create the GUI dialog using the Create + # method. + pre = wxPreDialog() + pre.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP) + pre.Create(parent, ID, title, pos, size, style) - box = wxBoxSizer(wxHORIZONTAL) + # This next step is the most important, it turns this Python + # object into the real wrapper of the dialog (instead of pre) + # as far as the wxPython extension is concerned. + self.this = pre.this - label = wxStaticText(win, -1, "Field #1:") - label.SetHelpText("This is the help text for the label") - box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) - text = wxTextCtrl(win, -1, "", size=(80,-1)) - text.SetHelpText("Here's some help text for field #1") - box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) + # Now continue with the normal construction of the dialog + # contents + sizer = wxBoxSizer(wxVERTICAL) - sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) + label = wxStaticText(self, -1, "This is a wxDialog") + label.SetHelpText("This is the help text for the label") + sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) - box = wxBoxSizer(wxHORIZONTAL) + box = wxBoxSizer(wxHORIZONTAL) - label = wxStaticText(win, -1, "Field #2:") - label.SetHelpText("This is the help text for the label") - box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) + label = wxStaticText(self, -1, "Field #1:") + label.SetHelpText("This is the help text for the label") + box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) - text = wxTextCtrl(win, -1, "", size=(80,-1)) - text.SetHelpText("Here's some help text for field #2") - box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) + text = wxTextCtrl(self, -1, "", size=(80,-1)) + text.SetHelpText("Here's some help text for field #1") + box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) - sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) + sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) - line = wxStaticLine(win, -1, size=(20,-1), style=wxLI_HORIZONTAL) - sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5) + box = wxBoxSizer(wxHORIZONTAL) - box = wxBoxSizer(wxHORIZONTAL) + label = wxStaticText(self, -1, "Field #2:") + label.SetHelpText("This is the help text for the label") + box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) - if wxPlatform != "__WXMSW__": - btn = wxContextHelpButton(win) + text = wxTextCtrl(self, -1, "", size=(80,-1)) + text.SetHelpText("Here's some help text for field #2") + box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) + + sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) + + line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL) + sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5) + + box = wxBoxSizer(wxHORIZONTAL) + + if wxPlatform != "__WXMSW__": + btn = wxContextHelpButton(self) + box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) + + btn = wxButton(self, wxID_OK, " OK ") + btn.SetDefault() + btn.SetHelpText("The OK button completes the dialog") box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) - btn = wxButton(win, wxID_OK, " OK ") - btn.SetDefault() - btn.SetHelpText("The OK button completes the dialog") - box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) + btn = wxButton(self, wxID_CANCEL, " Cancel ") + btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)") + box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) - btn = wxButton(win, wxID_CANCEL, " Cancel ") - btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)") - box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) + sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5) - sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5) + self.SetSizer(sizer) + self.SetAutoLayout(true) + sizer.Fit(self) - win.SetSizer(sizer) - win.SetAutoLayout(true) - sizer.Fit(win) + +#--------------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TestDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200), + #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME + style = wxDEFAULT_DIALOG_STYLE + ) + win.CenterOnScreen() val = win.ShowModal() if val == wxID_OK: log.WriteText("You pressed OK\n")