2 from wxPython
.wx
import *
3 from wxPython
.help import *
5 #---------------------------------------------------------------------------
6 # Create and set a help provider. Normally you would do this in
7 # the app's OnInit as it must be done before any SetHelpText calls.
8 provider
= wxSimpleHelpProvider()
9 wxHelpProvider_Set(provider
)
13 #---------------------------------------------------------------------------
15 class TestDialog(wxDialog
):
16 def __init__(self
, parent
, ID
, title
,
17 pos
=wxDefaultPosition
, size
=wxDefaultSize
,
18 style
=wxDEFAULT_DIALOG_STYLE
):
20 # Instead of calling wxDialog.__init__ we precreate the dialog
21 # so we can set an extra style that must be set before
22 # creation, and then we create the GUI dialog using the Create
25 pre
.SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
)
26 pre
.Create(parent
, ID
, title
, pos
, size
, style
)
28 # This next step is the most important, it turns this Python
29 # object into the real wrapper of the dialog (instead of pre)
30 # as far as the wxPython extension is concerned.
34 # Now continue with the normal construction of the dialog
36 sizer
= wxBoxSizer(wxVERTICAL
)
38 label
= wxStaticText(self
, -1, "This is a wxDialog")
39 label
.SetHelpText("This is the help text for the label")
40 sizer
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
42 box
= wxBoxSizer(wxHORIZONTAL
)
44 label
= wxStaticText(self
, -1, "Field #1:")
45 label
.SetHelpText("This is the help text for the label")
46 box
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
48 text
= wxTextCtrl(self
, -1, "", size
=(80,-1))
49 text
.SetHelpText("Here's some help text for field #1")
50 box
.Add(text
, 1, wxALIGN_CENTRE|wxALL
, 5)
52 sizer
.AddSizer(box
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL
, 5)
54 box
= wxBoxSizer(wxHORIZONTAL
)
56 label
= wxStaticText(self
, -1, "Field #2:")
57 label
.SetHelpText("This is the help text for the label")
58 box
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
60 text
= wxTextCtrl(self
, -1, "", size
=(80,-1))
61 text
.SetHelpText("Here's some help text for field #2")
62 box
.Add(text
, 1, wxALIGN_CENTRE|wxALL
, 5)
64 sizer
.AddSizer(box
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL
, 5)
66 line
= wxStaticLine(self
, -1, size
=(20,-1), style
=wxLI_HORIZONTAL
)
67 sizer
.Add(line
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP
, 5)
69 box
= wxBoxSizer(wxHORIZONTAL
)
71 if wxPlatform
!= "__WXMSW__":
72 btn
= wxContextHelpButton(self
)
73 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
75 btn
= wxButton(self
, wxID_OK
, " OK ")
77 btn
.SetHelpText("The OK button completes the dialog")
78 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
80 btn
= wxButton(self
, wxID_CANCEL
, " Cancel ")
81 btn
.SetHelpText("The Cancel button cnacels the dialog. (Duh!)")
82 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
84 sizer
.AddSizer(box
, 0, wxALIGN_CENTER_VERTICAL|wxALL
, 5)
87 self
.SetAutoLayout(True)
92 #---------------------------------------------------------------------------
94 def runTest(frame
, nb
, log
):
95 win
= TestDialog(frame
, -1, "This is a wxDialog", size
=wxSize(350, 200),
96 #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
97 style
= wxDEFAULT_DIALOG_STYLE
100 val
= win
.ShowModal()
102 log
.WriteText("You pressed OK\n")
104 log
.WriteText("You pressed Cancel\n")
108 #---------------------------------------------------------------------------
119 if __name__
== '__main__':
122 run
.main(['', os
.path
.basename(sys
.argv
[0])])