]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/wxDialog.py
reSWIGged
[wxWidgets.git] / wxPython / demo / wxDialog.py
... / ...
CommitLineData
1# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
5
6import wx
7
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.
11provider = wx.SimpleHelpProvider()
12wx.HelpProvider_Set(provider)
13
14#---------------------------------------------------------------------------
15
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 ):
21
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
25 # method.
26 pre = wx.PreDialog()
27 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
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.
33 self.this = pre.this
34
35 # Now continue with the normal construction of the dialog
36 # contents
37 sizer = wx.BoxSizer(wx.VERTICAL)
38
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)
42
43 box = wx.BoxSizer(wx.HORIZONTAL)
44
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)
48
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)
52
53 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
54
55 box = wx.BoxSizer(wx.HORIZONTAL)
56
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)
60
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)
64
65 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
66
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)
69
70 box = wx.BoxSizer(wx.HORIZONTAL)
71
72 if wx.Platform != "__WXMSW__":
73 btn = wx.ContextHelpButton(self)
74 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
75
76 btn = wx.Button(self, wx.ID_OK, " OK ")
77 btn.SetDefault()
78 btn.SetHelpText("The OK button completes the dialog")
79 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
80
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)
84
85 sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
86
87 self.SetSizer(sizer)
88 self.SetAutoLayout(True)
89 sizer.Fit(self)
90
91#---------------------------------------------------------------------------
92
93def 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
97 )
98 win.CenterOnScreen()
99 val = win.ShowModal()
100
101 if val == wx.ID_OK:
102 log.WriteText("You pressed OK\n")
103 else:
104 log.WriteText("You pressed Cancel\n")
105
106 win.Destroy()
107
108
109
110#---------------------------------------------------------------------------
111
112
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.
117
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.
122
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.
128
129See the documentation for the <code>Dialog</code> class for more details.
130
131"""
132
133if __name__ == '__main__':
134 import sys,os
135 import run
136 run.main(['', os.path.basename(sys.argv[0])])
137