]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ContextHelp.py
Applied patch [ 827011 ] Event-based processing of item tooltips in wxTreeCtrl
[wxWidgets.git] / wxPython / demo / ContextHelp.py
CommitLineData
8fa876ca
RD
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#
4f3449b4 9
8fa876ca 10import wx
4f3449b4
RD
11
12#----------------------------------------------------------------------
611dc22c 13# We first have to set an application-wide help provider. Normally you
4f3449b4
RD
14# would do this in your app's OnInit or in other startup code...
15
8fa876ca
RD
16provider = wx.SimpleHelpProvider()
17wx.HelpProvider_Set(provider)
4f3449b4 18
8fa876ca
RD
19# This panel is chock full of controls about which we can demonstrate the
20# help system.
21class TestPanel(wx.Panel):
4f3449b4 22 def __init__(self, parent, log):
8fa876ca 23 wx.Panel.__init__(self, parent, -1)
4f3449b4
RD
24 self.log = log
25
8fa876ca
RD
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 )
4f3449b4 41
8fa876ca 42 # Yes, even static text can have help text associated with it :-)
4f3449b4
RD
43 cBtnText.SetHelpText("Some helpful text...")
44
8fa876ca 45 s = wx.BoxSizer(wx.HORIZONTAL)
4f3449b4
RD
46 s.Add(cBtn, 0, wxALL, 5)
47 s.Add(cBtnText, 0, wxALL, 5)
fd3f2efe 48 sizer.Add((20,20))
4f3449b4
RD
49 sizer.Add(s)
50
8fa876ca
RD
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)
4f3449b4 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!")
fd3f2efe 55 sizer.Add((20,20))
4f3449b4
RD
56 sizer.Add(text)
57
8fa876ca
RD
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)
4f3449b4 62 text.SetHelpText("Yet another context help message.")
fd3f2efe 63 sizer.Add((20,20))
4f3449b4 64 sizer.Add(text)
8fa876ca 65 self.Bind(wx.EVT_HELP, self.OnCtxHelp, text)
4f3449b4 66
8fa876ca
RD
67 text = wx.TextCtrl(self, -1, "This one displays the tip itself...",
68 size=(240, 60), style = wx.TE_MULTILINE)
fd3f2efe 69 sizer.Add((20,20))
4f3449b4 70 sizer.Add(text)
8fa876ca 71 self.Bind(wx.EVT_HELP, self.OnCtxHelp2, text)
4f3449b4
RD
72
73
8fa876ca
RD
74 border = wx.BoxSizer(wx.VERTICAL)
75 border.Add(sizer, 0, wx.ALL, 25)
4f3449b4 76
1e4a197e 77 self.SetAutoLayout(True)
4f3449b4
RD
78 self.SetSizer(border)
79 self.Layout()
80
81
8fa876ca
RD
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.
4f3449b4
RD
85 def OnCtxHelp(self, evt):
86 self.log.write("OnCtxHelp: %s" % evt)
87 evt.Skip()
88
8fa876ca
RD
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.
4f3449b4 92 def OnCtxHelp2(self, evt):
4416b508 93 self.log.write("OnCtxHelp: %s\n" % evt)
8fa876ca 94 tip = wx.TipWindow(self, "This is a wx.TipWindow")
4f3449b4
RD
95
96
97#----------------------------------------------------------------------
98
99def runTest(frame, nb, log):
100 win = TestPanel(nb, log)
101 return win
102
103
104#----------------------------------------------------------------------
105
106
4f3449b4 107overview = """
8b9a4190 108This demo shows how to incorporate Context Sensitive
8fa876ca 109help into your application using the wx.SimpleHelpProvider class.
4f3449b4
RD
110
111"""
112
4f3449b4
RD
113#----------------------------------------------------------------------
114
1fded56b
RD
115if __name__ == '__main__':
116 import sys,os
117 import run
118 run.main(['', os.path.basename(sys.argv[0])])
119