]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | from wxPython.wx import * | |
3 | from wxPython.help import * | |
4 | ||
5 | #--------------------------------------------------------------------------- | |
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) | |
10 | ||
11 | ||
12 | ||
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) | |
47 | ||
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) | |
51 | ||
52 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) | |
53 | ||
54 | box = wxBoxSizer(wxHORIZONTAL) | |
55 | ||
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) | |
59 | ||
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) | |
63 | ||
64 | sizer.AddSizer(box, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5) | |
65 | ||
66 | line = wxStaticLine(self, -1, size=(20,-1), style=wxLI_HORIZONTAL) | |
67 | sizer.Add(line, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5) | |
68 | ||
69 | box = wxBoxSizer(wxHORIZONTAL) | |
70 | ||
71 | if wxPlatform != "__WXMSW__": | |
72 | btn = wxContextHelpButton(self) | |
73 | box.Add(btn, 0, wxALIGN_CENTRE|wxALL, 5) | |
74 | ||
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) | |
79 | ||
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) | |
83 | ||
84 | sizer.AddSizer(box, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5) | |
85 | ||
86 | self.SetSizer(sizer) | |
87 | self.SetAutoLayout(True) | |
88 | sizer.Fit(self) | |
89 | ||
90 | ||
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() | |
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 | ||
114 | overview = """\ | |
115 | """ | |
116 | ||
117 | ||
118 | ||
119 | if __name__ == '__main__': | |
120 | import sys,os | |
121 | import run | |
122 | run.main(['', os.path.basename(sys.argv[0])]) | |
123 |