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