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 # object 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.
32 self
.thisown
= pre
.thisown
36 # Now continue with the normal construction of the dialog
38 sizer
= wxBoxSizer(wxVERTICAL
)
40 label
= wxStaticText(self
, -1, "This is a wxDialog")
41 label
.SetHelpText("This is the help text for the label")
42 sizer
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
44 box
= wxBoxSizer(wxHORIZONTAL
)
46 label
= wxStaticText(self
, -1, "Field #1:")
47 label
.SetHelpText("This is the help text for the label")
48 box
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
50 text
= wxTextCtrl(self
, -1, "", size
=(80,-1))
51 text
.SetHelpText("Here's some help text for field #1")
52 box
.Add(text
, 1, wxALIGN_CENTRE|wxALL
, 5)
54 sizer
.AddSizer(box
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL
, 5)
56 box
= wxBoxSizer(wxHORIZONTAL
)
58 label
= wxStaticText(self
, -1, "Field #2:")
59 label
.SetHelpText("This is the help text for the label")
60 box
.Add(label
, 0, wxALIGN_CENTRE|wxALL
, 5)
62 text
= wxTextCtrl(self
, -1, "", size
=(80,-1))
63 text
.SetHelpText("Here's some help text for field #2")
64 box
.Add(text
, 1, wxALIGN_CENTRE|wxALL
, 5)
66 sizer
.AddSizer(box
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL
, 5)
68 line
= wxStaticLine(self
, -1, size
=(20,-1), style
=wxLI_HORIZONTAL
)
69 sizer
.Add(line
, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP
, 5)
71 box
= wxBoxSizer(wxHORIZONTAL
)
73 if wxPlatform
!= "__WXMSW__":
74 btn
= wxContextHelpButton(self
)
75 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
77 btn
= wxButton(self
, wxID_OK
, " OK ")
79 btn
.SetHelpText("The OK button completes the dialog")
80 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
82 btn
= wxButton(self
, wxID_CANCEL
, " Cancel ")
83 btn
.SetHelpText("The Cancel button cnacels the dialog. (Duh!)")
84 box
.Add(btn
, 0, wxALIGN_CENTRE|wxALL
, 5)
86 sizer
.AddSizer(box
, 0, wxALIGN_CENTER_VERTICAL|wxALL
, 5)
89 self
.SetAutoLayout(True)
94 #---------------------------------------------------------------------------
96 def runTest(frame
, nb
, log
):
97 win
= TestDialog(frame
, -1, "This is a wxDialog", size
=wxSize(350, 200),
98 #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
99 style
= wxDEFAULT_DIALOG_STYLE
102 val
= win
.ShowModal()
104 log
.WriteText("You pressed OK\n")
106 log
.WriteText("You pressed Cancel\n")
110 #---------------------------------------------------------------------------
121 if __name__
== '__main__':
124 run
.main(['', os
.path
.basename(sys
.argv
[0])])