]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Dialog.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / demo / Dialog.py
CommitLineData
8fa876ca
RD
1# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
cf694132 5
8fa876ca 6import wx
cf694132
RD
7
8#---------------------------------------------------------------------------
1e4a197e
RD
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.
8fa876ca
RD
11provider = wx.SimpleHelpProvider()
12wx.HelpProvider_Set(provider)
031787de 13
1e4a197e
RD
14#---------------------------------------------------------------------------
15
8fa876ca
RD
16class TestDialog(wx.Dialog):
17 def __init__(
18 self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
19 style=wx.DEFAULT_DIALOG_STYLE
20 ):
1e4a197e
RD
21
22 # Instead of calling wxDialog.__init__ we precreate the dialog
8fa876ca 23 # so we can set an extra style that must be set before
1e4a197e
RD
24 # creation, and then we create the GUI dialog using the Create
25 # method.
8fa876ca
RD
26 pre = wx.PreDialog()
27 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1e4a197e
RD
28 pre.Create(parent, ID, title, pos, size, style)
29
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.
8fa876ca 33 self.this = pre.this
1e4a197e
RD
34
35 # Now continue with the normal construction of the dialog
36 # contents
8fa876ca 37 sizer = wx.BoxSizer(wx.VERTICAL)
1e4a197e 38
8fa876ca 39 label = wx.StaticText(self, -1, "This is a wxDialog")
1e4a197e 40 label.SetHelpText("This is the help text for the label")
8fa876ca 41 sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
1e4a197e 42
8fa876ca 43 box = wx.BoxSizer(wx.HORIZONTAL)
1e4a197e 44
8fa876ca 45 label = wx.StaticText(self, -1, "Field #1:")
1e4a197e 46 label.SetHelpText("This is the help text for the label")
8fa876ca 47 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 48
8fa876ca 49 text = wx.TextCtrl(self, -1, "", size=(80,-1))
1e4a197e 50 text.SetHelpText("Here's some help text for field #1")
8fa876ca 51 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 52
8fa876ca 53 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 54
8fa876ca 55 box = wx.BoxSizer(wx.HORIZONTAL)
031787de 56
8fa876ca 57 label = wx.StaticText(self, -1, "Field #2:")
1e4a197e 58 label.SetHelpText("This is the help text for the label")
8fa876ca 59 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 60
8fa876ca 61 text = wx.TextCtrl(self, -1, "", size=(80,-1))
1e4a197e 62 text.SetHelpText("Here's some help text for field #2")
8fa876ca 63 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 64
8fa876ca 65 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 66
8fa876ca
RD
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)
031787de 69
8fa876ca 70 box = wx.BoxSizer(wx.HORIZONTAL)
031787de 71
8fa876ca
RD
72 if wx.Platform != "__WXMSW__":
73 btn = wx.ContextHelpButton(self)
74 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 75
8fa876ca 76 btn = wx.Button(self, wx.ID_OK, " OK ")
1e4a197e
RD
77 btn.SetDefault()
78 btn.SetHelpText("The OK button completes the dialog")
8fa876ca 79 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
031787de 80
8fa876ca
RD
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)
031787de 84
8fa876ca 85 sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
031787de 86
1e4a197e
RD
87 self.SetSizer(sizer)
88 self.SetAutoLayout(True)
89 sizer.Fit(self)
031787de 90
1e4a197e
RD
91#---------------------------------------------------------------------------
92
93def runTest(frame, nb, log):
8fa876ca 94 win = TestDialog(frame, -1, "This is a Dialog", size=(350, 200),
1e4a197e 95 #style = wxCAPTION | wxSYSTEM_MENU | wxTHICK_FRAME
8fa876ca 96 style = wx.DEFAULT_DIALOG_STYLE
1e4a197e
RD
97 )
98 win.CenterOnScreen()
cf694132 99 val = win.ShowModal()
8fa876ca
RD
100
101 if val == wx.ID_OK:
cf694132
RD
102 log.WriteText("You pressed OK\n")
103 else:
104 log.WriteText("You pressed Cancel\n")
8fa876ca 105
2f0f3b0f 106 win.Destroy()
cf694132
RD
107
108
cf694132 109
8fa876ca 110#---------------------------------------------------------------------------
cf694132
RD
111
112
8fa876ca
RD
113overview = """\
114wxPython offers quite a few general purpose dialogs for useful data input from
115the user; they are all based on the wx.Dialog class, which you can also subclass
116to create custom dialogs to suit your needs.
cf694132 117
8fa876ca
RD
118The Dialog class, in addition to dialog-like behaviors, also supports the full
119wxWindows layout featureset, which means that you can incorporate sizers or
120layout constraints as needed to achieve the look and feel desired. It even supports
121context-sensitive help, which is illustrated in this example.
cf694132 122
8fa876ca
RD
123The example is very simple; in real world situations, a dialog that had input
124fields such as this would no doubt be required to deliver those values back to
125the 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>
127The example shown here is <i>modal</i>; non-modal dialogs are possible as well.
cf694132 128
8fa876ca 129See the documentation for the <code>Dialog</code> class for more details.
cf694132 130
8fa876ca 131"""
cf694132 132
1e4a197e
RD
133if __name__ == '__main__':
134 import sys,os
135 import run
136 run.main(['', os.path.basename(sys.argv[0])])
cf694132 137