]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ContextHelp.py
The great wxVScrolledWindow refactoring: allow using it both horizontal and
[wxWidgets.git] / wxPython / demo / ContextHelp.py
CommitLineData
4f3449b4 1
8fa876ca 2import wx
4f3449b4
RD
3
4#----------------------------------------------------------------------
611dc22c 5# We first have to set an application-wide help provider. Normally you
4f3449b4
RD
6# would do this in your app's OnInit or in other startup code...
7
8fa876ca
RD
8provider = wx.SimpleHelpProvider()
9wx.HelpProvider_Set(provider)
4f3449b4 10
8fa876ca
RD
11# This panel is chock full of controls about which we can demonstrate the
12# help system.
13class TestPanel(wx.Panel):
4f3449b4 14 def __init__(self, parent, log):
8fa876ca 15 wx.Panel.__init__(self, parent, -1)
4f3449b4
RD
16 self.log = log
17
8fa876ca
RD
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 )
4f3449b4 33
8fa876ca 34 # Yes, even static text can have help text associated with it :-)
4f3449b4
RD
35 cBtnText.SetHelpText("Some helpful text...")
36
8fa876ca 37 s = wx.BoxSizer(wx.HORIZONTAL)
372bde9b
RD
38 s.Add(cBtn, 0, wx.ALL, 5)
39 s.Add(cBtnText, 0, wx.ALL, 5)
fd3f2efe 40 sizer.Add((20,20))
4f3449b4
RD
41 sizer.Add(s)
42
8fa876ca
RD
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)
4f3449b4 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!")
fd3f2efe 47 sizer.Add((20,20))
4f3449b4
RD
48 sizer.Add(text)
49
8fa876ca
RD
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)
4f3449b4 54 text.SetHelpText("Yet another context help message.")
fd3f2efe 55 sizer.Add((20,20))
4f3449b4 56 sizer.Add(text)
bed72852 57 text.Bind(wx.EVT_HELP, self.OnCtxHelp, text)
4f3449b4 58
8fa876ca
RD
59 text = wx.TextCtrl(self, -1, "This one displays the tip itself...",
60 size=(240, 60), style = wx.TE_MULTILINE)
fd3f2efe 61 sizer.Add((20,20))
4f3449b4 62 sizer.Add(text)
bed72852
RD
63 text.Bind(wx.EVT_HELP, self.OnCtxHelp2, text)
64
4f3449b4 65
8fa876ca
RD
66 border = wx.BoxSizer(wx.VERTICAL)
67 border.Add(sizer, 0, wx.ALL, 25)
4f3449b4 68
1e4a197e 69 self.SetAutoLayout(True)
4f3449b4
RD
70 self.SetSizer(border)
71 self.Layout()
72
73
8fa876ca
RD
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.
4f3449b4
RD
77 def OnCtxHelp(self, evt):
78 self.log.write("OnCtxHelp: %s" % evt)
79 evt.Skip()
80
8fa876ca
RD
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.
4f3449b4 84 def OnCtxHelp2(self, evt):
bed72852 85 self.log.write("OnCtxHelp2: %s\n" % evt)
8fa876ca 86 tip = wx.TipWindow(self, "This is a wx.TipWindow")
4f3449b4
RD
87
88
89#----------------------------------------------------------------------
90
91def runTest(frame, nb, log):
56ca5a41
RD
92 win = TestPanel(nb, log)
93 return win
4f3449b4
RD
94
95
96#----------------------------------------------------------------------
97
98
4f3449b4 99overview = """
8b9a4190 100This demo shows how to incorporate Context Sensitive
8fa876ca 101help into your application using the wx.SimpleHelpProvider class.
4f3449b4
RD
102
103"""
104
4f3449b4
RD
105#----------------------------------------------------------------------
106
1fded56b
RD
107if __name__ == '__main__':
108 import sys,os
109 import run
8eca4fef 110 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 111