]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | # We first have to set an application-wide help provider. Normally you | |
6 | # would do this in your app's OnInit or in other startup code... | |
7 | ||
8 | provider = wx.SimpleHelpProvider() | |
9 | wx.HelpProvider_Set(provider) | |
10 | ||
11 | # This panel is chock full of controls about which we can demonstrate the | |
12 | # help system. | |
13 | class TestPanel(wx.Panel): | |
14 | def __init__(self, parent, log): | |
15 | wx.Panel.__init__(self, parent, -1) | |
16 | self.log = log | |
17 | ||
18 | # This help text, set for the panel itself, will be used if context | |
19 | # sensitive help cannot be found for any particular control. | |
20 | self.SetHelpText("This is a wx.Panel.") | |
21 | ||
22 | sizer = wx.BoxSizer(wx.VERTICAL) | |
23 | ||
24 | # Init the context help button. | |
25 | # And even include help text about the help button :-) | |
26 | cBtn = wx.ContextHelpButton(self) | |
27 | cBtn.SetHelpText("wx.ContextHelpButton") | |
28 | ||
29 | cBtnText = wx.StaticText(self, -1, | |
30 | "This is a wx.ContextHelpButton. Clicking it puts the\n" | |
31 | "app into context sensitive help mode." | |
32 | ) | |
33 | ||
34 | # Yes, even static text can have help text associated with it :-) | |
35 | cBtnText.SetHelpText("Some helpful text...") | |
36 | ||
37 | s = wx.BoxSizer(wx.HORIZONTAL) | |
38 | s.Add(cBtn, 0, wx.ALL, 5) | |
39 | s.Add(cBtnText, 0, wx.ALL, 5) | |
40 | sizer.Add((20,20)) | |
41 | sizer.Add(s) | |
42 | ||
43 | # A text control with help text. | |
44 | text = wx.TextCtrl(self, -1, "Each sub-window can have its own help message", | |
45 | size=(240, 60), style=wx.TE_MULTILINE) | |
46 | text.SetHelpText("This is my very own help message. This is a really long long long long long long long long long long long long long long long long long long long long message!") | |
47 | sizer.Add((20,20)) | |
48 | sizer.Add(text) | |
49 | ||
50 | # Same thing, but this time to demonstrate how the help event can be | |
51 | # intercepted. | |
52 | text = wx.TextCtrl(self, -1, "You can also intercept the help event if you like. Watch the log window when you click here...", | |
53 | size=(240, 60), style = wx.TE_MULTILINE) | |
54 | text.SetHelpText("Yet another context help message.") | |
55 | sizer.Add((20,20)) | |
56 | sizer.Add(text) | |
57 | self.Bind(wx.EVT_HELP, self.OnCtxHelp, text) | |
58 | ||
59 | text = wx.TextCtrl(self, -1, "This one displays the tip itself...", | |
60 | size=(240, 60), style = wx.TE_MULTILINE) | |
61 | sizer.Add((20,20)) | |
62 | sizer.Add(text) | |
63 | self.Bind(wx.EVT_HELP, self.OnCtxHelp2, text) | |
64 | ||
65 | ||
66 | border = wx.BoxSizer(wx.VERTICAL) | |
67 | border.Add(sizer, 0, wx.ALL, 25) | |
68 | ||
69 | self.SetAutoLayout(True) | |
70 | self.SetSizer(border) | |
71 | self.Layout() | |
72 | ||
73 | ||
74 | # On the second text control above, we intercept the help event. This is where | |
75 | # we process it. Anything could happen here. In this case we're just printing | |
76 | # some stuff about it, then passing it on, at which point we see the help tip. | |
77 | def OnCtxHelp(self, evt): | |
78 | self.log.write("OnCtxHelp: %s" % evt) | |
79 | evt.Skip() | |
80 | ||
81 | # On the third text control above, we intercept the help event. | |
82 | # Here, we print a note about it, generate our own tip window, and, | |
83 | # unlike last time, we don't pass it on to the underlying provider. | |
84 | def OnCtxHelp2(self, evt): | |
85 | self.log.write("OnCtxHelp: %s\n" % evt) | |
86 | tip = wx.TipWindow(self, "This is a wx.TipWindow") | |
87 | ||
88 | ||
89 | #---------------------------------------------------------------------- | |
90 | ||
91 | def runTest(frame, nb, log): | |
92 | win = TestPanel(nb, log) | |
93 | return win | |
94 | ||
95 | ||
96 | #---------------------------------------------------------------------- | |
97 | ||
98 | ||
99 | overview = """ | |
100 | This demo shows how to incorporate Context Sensitive | |
101 | help into your application using the wx.SimpleHelpProvider class. | |
102 | ||
103 | """ | |
104 | ||
105 | #---------------------------------------------------------------------- | |
106 | ||
107 | if __name__ == '__main__': | |
108 | import sys,os | |
109 | import run | |
110 | run.main(['', os.path.basename(sys.argv[0])]) | |
111 |