2001-07-29 03:06:02 +00:00
2003-12-09 01:23:28 +00:00
import wx
2001-07-29 03:06:02 +00:00
#----------------------------------------------------------------------
2001-11-30 21:16:36 +00:00
# We first have to set an application-wide help provider. Normally you
2001-07-29 03:06:02 +00:00
# would do this in your app's OnInit or in other startup code...
2003-12-09 01:23:28 +00:00
provider = wx . SimpleHelpProvider ( )
wx . HelpProvider_Set ( provider )
2001-07-29 03:06:02 +00:00
2003-12-09 01:23:28 +00:00
# This panel is chock full of controls about which we can demonstrate the
# help system.
class TestPanel ( wx . Panel ) :
2001-07-29 03:06:02 +00:00
def __init__ ( self , parent , log ) :
2003-12-09 01:23:28 +00:00
wx . Panel . __init__ ( self , parent , - 1 )
2001-07-29 03:06:02 +00:00
self . log = log
2003-12-09 01:23:28 +00:00
# This help text, set for the panel itself, will be used if context
# sensitive help cannot be found for any particular control.
self . SetHelpText ( " This is a wx.Panel. " )
sizer = wx . BoxSizer ( wx . VERTICAL )
# Init the context help button.
# And even include help text about the help button :-)
cBtn = wx . ContextHelpButton ( self )
cBtn . SetHelpText ( " wx.ContextHelpButton " )
cBtnText = wx . StaticText ( self , - 1 ,
" This is a wx.ContextHelpButton. Clicking it puts the \n "
" app into context sensitive help mode. "
)
2001-07-29 03:06:02 +00:00
2003-12-09 01:23:28 +00:00
# Yes, even static text can have help text associated with it :-)
2001-07-29 03:06:02 +00:00
cBtnText . SetHelpText ( " Some helpful text... " )
2003-12-09 01:23:28 +00:00
s = wx . BoxSizer ( wx . HORIZONTAL )
2003-12-11 19:55:48 +00:00
s . Add ( cBtn , 0 , wx . ALL , 5 )
s . Add ( cBtnText , 0 , wx . ALL , 5 )
2003-11-22 22:57:49 +00:00
sizer . Add ( ( 20 , 20 ) )
2001-07-29 03:06:02 +00:00
sizer . Add ( s )
2003-12-09 01:23:28 +00:00
# A text control with help text.
text = wx . TextCtrl ( self , - 1 , " Each sub-window can have its own help message " ,
size = ( 240 , 60 ) , style = wx . TE_MULTILINE )
2001-07-29 03:06:02 +00:00
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! " )
2003-11-22 22:57:49 +00:00
sizer . Add ( ( 20 , 20 ) )
2001-07-29 03:06:02 +00:00
sizer . Add ( text )
2003-12-09 01:23:28 +00:00
# Same thing, but this time to demonstrate how the help event can be
# intercepted.
text = wx . TextCtrl ( self , - 1 , " You can also intercept the help event if you like. Watch the log window when you click here... " ,
size = ( 240 , 60 ) , style = wx . TE_MULTILINE )
2001-07-29 03:06:02 +00:00
text . SetHelpText ( " Yet another context help message. " )
2003-11-22 22:57:49 +00:00
sizer . Add ( ( 20 , 20 ) )
2001-07-29 03:06:02 +00:00
sizer . Add ( text )
2003-12-09 01:23:28 +00:00
self . Bind ( wx . EVT_HELP , self . OnCtxHelp , text )
2001-07-29 03:06:02 +00:00
2003-12-09 01:23:28 +00:00
text = wx . TextCtrl ( self , - 1 , " This one displays the tip itself... " ,
size = ( 240 , 60 ) , style = wx . TE_MULTILINE )
2003-11-22 22:57:49 +00:00
sizer . Add ( ( 20 , 20 ) )
2001-07-29 03:06:02 +00:00
sizer . Add ( text )
2003-12-09 01:23:28 +00:00
self . Bind ( wx . EVT_HELP , self . OnCtxHelp2 , text )
2001-07-29 03:06:02 +00:00
2003-12-09 01:23:28 +00:00
border = wx . BoxSizer ( wx . VERTICAL )
border . Add ( sizer , 0 , wx . ALL , 25 )
2001-07-29 03:06:02 +00:00
2003-03-25 06:35:27 +00:00
self . SetAutoLayout ( True )
2001-07-29 03:06:02 +00:00
self . SetSizer ( border )
self . Layout ( )
2003-12-09 01:23:28 +00:00
# On the second text control above, we intercept the help event. This is where
# we process it. Anything could happen here. In this case we're just printing
# some stuff about it, then passing it on, at which point we see the help tip.
2001-07-29 03:06:02 +00:00
def OnCtxHelp ( self , evt ) :
self . log . write ( " OnCtxHelp: %s " % evt )
evt . Skip ( )
2003-12-09 01:23:28 +00:00
# On the third text control above, we intercept the help event.
# Here, we print a note about it, generate our own tip window, and,
# unlike last time, we don't pass it on to the underlying provider.
2001-07-29 03:06:02 +00:00
def OnCtxHelp2 ( self , evt ) :
2001-11-30 23:15:05 +00:00
self . log . write ( " OnCtxHelp: %s \n " % evt )
2003-12-09 01:23:28 +00:00
tip = wx . TipWindow ( self , " This is a wx.TipWindow " )
2001-07-29 03:06:02 +00:00
#----------------------------------------------------------------------
def runTest ( frame , nb , log ) :
2004-02-26 20:49:22 +00:00
win = TestPanel ( nb , log )
return win
2001-07-29 03:06:02 +00:00
#----------------------------------------------------------------------
overview = """
2003-10-02 00:58:06 +00:00
This demo shows how to incorporate Context Sensitive
2003-12-09 01:23:28 +00:00
help into your application using the wx . SimpleHelpProvider class .
2001-07-29 03:06:02 +00:00
"""
#----------------------------------------------------------------------
2003-07-02 23:13:10 +00:00
if __name__ == ' __main__ ' :
import sys , os
import run
2004-03-05 00:06:33 +00:00
run . main ( [ ' ' , os . path . basename ( sys . argv [ 0 ] ) ] + sys . argv [ 1 : ] )
2003-07-02 23:13:10 +00:00