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