]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Dialog.py
4 #---------------------------------------------------------------------------
5 # Create and set a help provider. Normally you would do this in
6 # the app's OnInit as it must be done before any SetHelpText calls.
7 provider
= wx
.SimpleHelpProvider()
8 wx
.HelpProvider_Set(provider
)
10 #---------------------------------------------------------------------------
12 class TestDialog(wx
.Dialog
):
14 self
, parent
, ID
, title
, size
=wx
.DefaultSize
, pos
=wx
.DefaultPosition
,
15 style
=wx
.DEFAULT_DIALOG_STYLE
18 # Instead of calling wx.Dialog.__init__ we precreate the dialog
19 # so we can set an extra style that must be set before
20 # creation, and then we create the GUI dialog using the Create
23 pre
.SetExtraStyle(wx
.DIALOG_EX_CONTEXTHELP
)
24 pre
.Create(parent
, ID
, title
, pos
, size
, style
)
26 # This next step is the most important, it turns this Python
27 # object into the real wrapper of the dialog (instead of pre)
28 # as far as the wxPython extension is concerned.
31 # Now continue with the normal construction of the dialog
33 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
35 label
= wx
.StaticText(self
, -1, "This is a wx.Dialog")
36 label
.SetHelpText("This is the help text for the label")
37 sizer
.Add(label
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
39 box
= wx
.BoxSizer(wx
.HORIZONTAL
)
41 label
= wx
.StaticText(self
, -1, "Field #1:")
42 label
.SetHelpText("This is the help text for the label")
43 box
.Add(label
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
45 text
= wx
.TextCtrl(self
, -1, "", size
=(80,-1))
46 text
.SetHelpText("Here's some help text for field #1")
47 box
.Add(text
, 1, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
49 sizer
.AddSizer(box
, 0, wx
.GROW|wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, 5)
51 box
= wx
.BoxSizer(wx
.HORIZONTAL
)
53 label
= wx
.StaticText(self
, -1, "Field #2:")
54 label
.SetHelpText("This is the help text for the label")
55 box
.Add(label
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
57 text
= wx
.TextCtrl(self
, -1, "", size
=(80,-1))
58 text
.SetHelpText("Here's some help text for field #2")
59 box
.Add(text
, 1, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
61 sizer
.AddSizer(box
, 0, wx
.GROW|wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, 5)
63 line
= wx
.StaticLine(self
, -1, size
=(20,-1), style
=wx
.LI_HORIZONTAL
)
64 sizer
.Add(line
, 0, wx
.GROW|wx
.ALIGN_CENTER_VERTICAL|wx
.RIGHT|wx
.TOP
, 5)
66 box
= wx
.BoxSizer(wx
.HORIZONTAL
)
68 if wx
.Platform
!= "__WXMSW__":
69 btn
= wx
.ContextHelpButton(self
)
70 box
.Add(btn
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
72 btn
= wx
.Button(self
, wx
.ID_OK
, " OK ")
74 btn
.SetHelpText("The OK button completes the dialog")
75 box
.Add(btn
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
77 btn
= wx
.Button(self
, wx
.ID_CANCEL
, " Cancel ")
78 btn
.SetHelpText("The Cancel button cnacels the dialog. (Cool, huh?)")
79 box
.Add(btn
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
81 sizer
.Add(box
, 0, wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, 5)
84 self
.SetAutoLayout(True)
87 #---------------------------------------------------------------------------
89 def runTest(frame
, nb
, log
):
90 win
= TestDialog(frame
, -1, "This is a Dialog", size
=(350, 200),
91 #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
92 style
= wx
.DEFAULT_DIALOG_STYLE
98 log
.WriteText("You pressed OK\n")
100 log
.WriteText("You pressed Cancel\n")
106 #---------------------------------------------------------------------------
110 wxPython offers quite a few general purpose dialogs for useful data input from
111 the user; they are all based on the wx.Dialog class, which you can also subclass
112 to create custom dialogs to suit your needs.
114 The Dialog class, in addition to dialog-like behaviors, also supports the full
115 wxWindows layout featureset, which means that you can incorporate sizers or
116 layout constraints as needed to achieve the look and feel desired. It even supports
117 context-sensitive help, which is illustrated in this example.
119 The example is very simple; in real world situations, a dialog that had input
120 fields such as this would no doubt be required to deliver those values back to
121 the calling function. The Dialog class supports data retrieval in this manner.
122 <b>However, the data must be retrieved prior to the dialog being destroyed.</b>
123 The example shown here is <i>modal</i>; non-modal dialogs are possible as well.
125 See the documentation for the <code>Dialog</code> class for more details.
129 if __name__
== '__main__':
132 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])