]>
Commit | Line | Data |
---|---|---|
cf694132 RD |
1 | |
2 | from wxPython.wx import * | |
1e4a197e | 3 | from wxPython.help import * |
cf694132 RD |
4 | |
5 | #--------------------------------------------------------------------------- | |
1e4a197e RD |
6 | # Create and set a help provider. Normally you would do this in |
7 | # the app's OnInit as it must be done before any SetHelpText calls. | |
8 | provider = wxSimpleHelpProvider() | |
9 | wxHelpProvider_Set(provider) | |
cf694132 | 10 | |
cf694132 | 11 | |
031787de | 12 | |
1e4a197e RD |
13 | #--------------------------------------------------------------------------- |
14 | ||
15 | class TestDialog(wxDialog): | |
16 | def __init__(self, parent, ID, title, | |
17 | pos=wxDefaultPosition, size=wxDefaultSize, | |
18 | style=wxDEFAULT_DIALOG_STYLE): | |
19 | ||
20 | # Instead of calling wxDialog.__init__ we precreate the dialog | |
2f0f3b0f | 21 | # object so we can set an extra style that must be set before |
1e4a197e RD |
22 | # creation, and then we create the GUI dialog using the Create |
23 | # method. | |
24 | pre = wxPreDialog() | |
25 | pre.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP) | |
26 | pre.Create(parent, ID, title, pos, size, style) | |
27 | ||
28 | # This next step is the most important, it turns this Python | |
29 | # object into the real wrapper of the dialog (instead of pre) | |
30 | # as far as the wxPython extension is concerned. | |
31 | self.this = pre.this | |
2f0f3b0f RD |
32 | self.thisown = pre.thisown |
33 | pre.thisown = 0 | |
1e4a197e RD |
34 | |
35 | ||
36 | # Now continue with the normal construction of the dialog | |
37 | # contents | |
38 | sizer = wxBoxSizer(wxVERTICAL) | |
39 | ||
40 | label = wxStaticText(self, -1, "This is a wxDialog") | |
41 | label.SetHelpText("This is the help text for the label") | |
42 | sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
43 | ||
44 | box = wxBoxSizer(wxHORIZONTAL) | |
45 | ||
46 | label = wxStaticText(self, -1, "Field #1:") | |
47 | label.SetHelpText("This is the help text for the label") | |
48 | box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 49 | |
1e4a197e RD |
50 | text = wxTextCtrl(self, -1, "", size=(80,-1)) |
51 | text.SetHelpText("Here's some help text for field #1") | |
52 | box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 53 | |
1e4a197e | 54 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 55 | |
1e4a197e | 56 | box = wxBoxSizer(wxHORIZONTAL) |
031787de | 57 | |
1e4a197e RD |
58 | label = wxStaticText(self, -1, "Field #2:") |
59 | label.SetHelpText("This is the help text for the label") | |
60 | box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 61 | |
1e4a197e RD |
62 | text = wxTextCtrl(self, -1, "", size=(80,-1)) |
63 | text.SetHelpText("Here's some help text for field #2") | |
64 | box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 65 | |
1e4a197e | 66 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 67 | |
1e4a197e RD |
68 | line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL) |
69 | sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5) | |
031787de | 70 | |
1e4a197e | 71 | box = wxBoxSizer(wxHORIZONTAL) |
031787de | 72 | |
1e4a197e RD |
73 | if wxPlatform != "__WXMSW__": |
74 | btn = wxContextHelpButton(self) | |
75 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 76 | |
1e4a197e RD |
77 | btn = wxButton(self, wxID_OK, " OK ") |
78 | btn.SetDefault() | |
79 | btn.SetHelpText("The OK button completes the dialog") | |
80 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 81 | |
1e4a197e RD |
82 | btn = wxButton(self, wxID_CANCEL, " Cancel ") |
83 | btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)") | |
84 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 85 | |
1e4a197e | 86 | sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 87 | |
1e4a197e RD |
88 | self.SetSizer(sizer) |
89 | self.SetAutoLayout(True) | |
90 | sizer.Fit(self) | |
031787de | 91 | |
cf694132 | 92 | |
1e4a197e RD |
93 | |
94 | #--------------------------------------------------------------------------- | |
95 | ||
96 | def runTest(frame, nb, log): | |
97 | win = TestDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200), | |
98 | #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME | |
99 | style = wxDEFAULT_DIALOG_STYLE | |
100 | ) | |
101 | win.CenterOnScreen() | |
cf694132 RD |
102 | val = win.ShowModal() |
103 | if val == wxID_OK: | |
104 | log.WriteText("You pressed OK\n") | |
105 | else: | |
106 | log.WriteText("You pressed Cancel\n") | |
2f0f3b0f | 107 | win.Destroy() |
cf694132 RD |
108 | |
109 | ||
110 | #--------------------------------------------------------------------------- | |
111 | ||
112 | ||
113 | ||
114 | ||
115 | ||
1e4a197e RD |
116 | overview = """\ |
117 | """ | |
cf694132 RD |
118 | |
119 | ||
120 | ||
1e4a197e RD |
121 | if __name__ == '__main__': |
122 | import sys,os | |
123 | import run | |
124 | run.main(['', os.path.basename(sys.argv[0])]) | |
cf694132 | 125 |