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...
8 provider
= wx
.SimpleHelpProvider()
9 wx
.HelpProvider_Set(provider
)
11 # This panel is chock full of controls about which we can demonstrate the
13 class TestPanel(wx
.Panel
):
14 def __init__(self
, parent
, log
):
15 wx
.Panel
.__init
__(self
, parent
, -1)
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.")
22 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
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")
29 cBtnText
= wx
.StaticText(self
, -1,
30 "This is a wx.ContextHelpButton. Clicking it puts the\n"
31 "app into context sensitive help mode."
34 # Yes, even static text can have help text associated with it :-)
35 cBtnText
.SetHelpText("Some helpful text...")
37 s
= wx
.BoxSizer(wx
.HORIZONTAL
)
38 s
.Add(cBtn
, 0, wx
.ALL
, 5)
39 s
.Add(cBtnText
, 0, wx
.ALL
, 5)
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!")
50 # Same thing, but this time to demonstrate how the help event can be
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.")
57 text
.Bind(wx
.EVT_HELP
, self
.OnCtxHelp
, text
)
59 text
= wx
.TextCtrl(self
, -1, "This one displays the tip itself...",
60 size
=(240, 60), style
= wx
.TE_MULTILINE
)
63 text
.Bind(wx
.EVT_HELP
, self
.OnCtxHelp2
, text
)
66 border
= wx
.BoxSizer(wx
.VERTICAL
)
67 border
.Add(sizer
, 0, wx
.ALL
, 25)
69 self
.SetAutoLayout(True)
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
)
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("OnCtxHelp2: %s\n" % evt
)
86 tip
= wx
.TipWindow(self
, "This is a wx.TipWindow")
89 #----------------------------------------------------------------------
91 def runTest(frame
, nb
, log
):
92 win
= TestPanel(nb
, log
)
96 #----------------------------------------------------------------------
100 This demo shows how to incorporate Context Sensitive
101 help into your application using the wx.SimpleHelpProvider class.
105 #----------------------------------------------------------------------
107 if __name__
== '__main__':
110 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])