]>
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 | |
21 | # so we can set an extra style that must be set before | |
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 | |
32 | ||
33 | ||
34 | # Now continue with the normal construction of the dialog | |
35 | # contents | |
36 | sizer = wxBoxSizer(wxVERTICAL) | |
37 | ||
38 | label = wxStaticText(self, -1, "This is a wxDialog") | |
39 | label.SetHelpText("This is the help text for the label") | |
40 | sizer.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
41 | ||
42 | box = wxBoxSizer(wxHORIZONTAL) | |
43 | ||
44 | label = wxStaticText(self, -1, "Field #1:") | |
45 | label.SetHelpText("This is the help text for the label") | |
46 | box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 47 | |
1e4a197e RD |
48 | text = wxTextCtrl(self, -1, "", size=(80,-1)) |
49 | text.SetHelpText("Here's some help text for field #1") | |
50 | box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 51 | |
1e4a197e | 52 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 53 | |
1e4a197e | 54 | box = wxBoxSizer(wxHORIZONTAL) |
031787de | 55 | |
1e4a197e RD |
56 | label = wxStaticText(self, -1, "Field #2:") |
57 | label.SetHelpText("This is the help text for the label") | |
58 | box.Add(label, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 59 | |
1e4a197e RD |
60 | text = wxTextCtrl(self, -1, "", size=(80,-1)) |
61 | text.SetHelpText("Here's some help text for field #2") | |
62 | box.Add(text, 1, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 63 | |
1e4a197e | 64 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 65 | |
1e4a197e RD |
66 | line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL) |
67 | sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5) | |
031787de | 68 | |
1e4a197e | 69 | box = wxBoxSizer(wxHORIZONTAL) |
031787de | 70 | |
1e4a197e RD |
71 | if wxPlatform != "__WXMSW__": |
72 | btn = wxContextHelpButton(self) | |
73 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 74 | |
1e4a197e RD |
75 | btn = wxButton(self, wxID_OK, " OK ") |
76 | btn.SetDefault() | |
77 | btn.SetHelpText("The OK button completes the dialog") | |
78 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 79 | |
1e4a197e RD |
80 | btn = wxButton(self, wxID_CANCEL, " Cancel ") |
81 | btn.SetHelpText("The Cancel button cnacels the dialog. (Duh!)") | |
82 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
031787de | 83 | |
1e4a197e | 84 | sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5) |
031787de | 85 | |
1e4a197e RD |
86 | self.SetSizer(sizer) |
87 | self.SetAutoLayout(True) | |
88 | sizer.Fit(self) | |
031787de | 89 | |
cf694132 | 90 | |
1e4a197e RD |
91 | |
92 | #--------------------------------------------------------------------------- | |
93 | ||
94 | def runTest(frame, nb, log): | |
95 | win = TestDialog(frame, -1, "This is a wxDialog", size=wxSize(350, 200), | |
96 | #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME | |
97 | style = wxDEFAULT_DIALOG_STYLE | |
98 | ) | |
99 | win.CenterOnScreen() | |
cf694132 RD |
100 | val = win.ShowModal() |
101 | if val == wxID_OK: | |
102 | log.WriteText("You pressed OK\n") | |
103 | else: | |
104 | log.WriteText("You pressed Cancel\n") | |
105 | ||
106 | ||
107 | ||
108 | #--------------------------------------------------------------------------- | |
109 | ||
110 | ||
111 | ||
112 | ||
113 | ||
1e4a197e RD |
114 | overview = """\ |
115 | """ | |
cf694132 RD |
116 | |
117 | ||
118 | ||
1e4a197e RD |
119 | if __name__ == '__main__': |
120 | import sys,os | |
121 | import run | |
122 | run.main(['', os.path.basename(sys.argv[0])]) | |
cf694132 | 123 |