]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Wizard.py
doc tweaks, typo fixed, etc.
[wxWidgets.git] / wxPython / demo / Wizard.py
1 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2 #
3 # o Updated for wx namespace
4 #
5 # 11/3-/2003 - Jeff Grimmett (grimmtooth@softhome.net)
6 #
7 # o WizardPage* doesn't support GetId()
8 #
9
10 import wx
11 import wx.wizard as wiz
12 import images
13
14 #----------------------------------------------------------------------
15
16 def makePageTitle(wizPg, title):
17 sizer = wx.BoxSizer(wx.VERTICAL)
18 wizPg.SetSizer(sizer)
19 title = wx.StaticText(wizPg, -1, title)
20 title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
21 sizer.AddWindow(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
22 sizer.AddWindow(wx.StaticLine(wizPg, -1), 0, wx.EXPAND|wx.ALL, 5)
23 return sizer
24
25 #----------------------------------------------------------------------
26
27 class TitledPage(wiz.WizardPageSimple):
28 def __init__(self, parent, title):
29 wiz.WizardPageSimple.__init__(self, parent)
30 self.sizer = makePageTitle(self, title)
31
32
33 #----------------------------------------------------------------------
34
35 class SkipNextPage(wiz.PyWizardPage):
36 def __init__(self, parent, title):
37 wiz.PyWizardPage.__init__(self, parent)
38 self.next = self.prev = None
39 self.sizer = makePageTitle(self, title)
40
41 self.cb = wx.CheckBox(self, -1, "Skip next page")
42 self.sizer.Add(self.cb, 0, wx.ALL, 5)
43
44 def SetNext(self, next):
45 self.next = next
46
47 def SetPrev(self, prev):
48 self.prev = prev
49
50
51 # Classes derived from wxPyWizardPanel must override
52 # GetNext and GetPrev, and may also override GetBitmap
53 # as well as all those methods overridable by
54 # wx.PyWindow.
55
56 def GetNext(self):
57 """If the checkbox is set then return the next page's next page"""
58 next = self.next
59 if self.cb.GetValue():
60 next = next.GetNext()
61 return next
62
63 def GetPrev(self):
64 return self.prev
65
66 #----------------------------------------------------------------------
67
68 class UseAltBitmapPage(wiz.PyWizardPage):
69 def __init__(self, parent, title):
70 wiz.PyWizardPage.__init__(self, parent)
71 self.next = self.prev = None
72 self.sizer = makePageTitle(self, title)
73
74 self.sizer.Add(wx.StaticText(self, -1, "This page uses a different bitmap"),
75 0, wx.ALL, 5)
76
77 def SetNext(self, next):
78 self.next = next
79
80 def SetPrev(self, prev):
81 self.prev = prev
82
83 def GetNext(self):
84 return self.next
85
86 def GetPrev(self):
87 return self.prev
88
89 def GetBitmap(self):
90 # You usually wouldn't need to override this method
91 # since you can set a non-default bitmap in the
92 # wxWizardPageSimple constructor, but if you need to
93 # dynamically change the bitmap based on the
94 # contents of the wizard, or need to also change the
95 # next/prev order then it can be done by overriding
96 # GetBitmap.
97 return images.getWizTest2Bitmap()
98
99 #----------------------------------------------------------------------
100
101 class TestPanel(wx.Panel):
102 ID_wiz = wx.NewId()
103
104 def __init__(self, parent, log):
105 self.log = log
106 wx.Panel.__init__(self, parent, -1)
107
108 b = wx.Button(self, -1, "Run Simple Wizard", pos=(50, 50))
109 self.Bind(wx.EVT_BUTTON, self.OnRunSimpleWizard, b)
110
111 b = wx.Button(self, -1, "Run Dynamic Wizard", pos=(50, 100))
112 self.Bind(wx.EVT_BUTTON, self.OnRunDynamicWizard, b)
113
114 wiz.EVT_WIZARD_PAGE_CHANGED(self, self.ID_wiz, self.OnWizPageChanged)
115 wiz.EVT_WIZARD_PAGE_CHANGING(self, self.ID_wiz, self.OnWizPageChanging)
116 wiz.EVT_WIZARD_CANCEL(self, self.ID_wiz, self.OnWizCancel)
117
118
119 def OnWizPageChanged(self, evt):
120 if evt.GetDirection():
121 dir = "forward"
122 else:
123 dir = "backward"
124
125 page = evt.GetPage()
126 self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__))
127
128
129 def OnWizPageChanging(self, evt):
130 if evt.GetDirection():
131 dir = "forward"
132 else:
133 dir = "backward"
134
135 page = evt.GetPage()
136 self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__))
137
138
139 def OnWizCancel(self, evt):
140 page = evt.GetPage()
141 self.log.write("OnWizCancel: %s\n" % page.__class__)
142
143 # Show how to prevent cancelling of the wizard. The
144 # other events can be Veto'd too.
145 if page is self.page1:
146 wx.MessageBox("Cancelling on the first page has been prevented.", "Sorry")
147 evt.Veto()
148
149 def OnWizFinished(self, evt):
150 self.log.write("OnWizFinished\n")
151
152
153 def OnRunSimpleWizard(self, evt):
154 # Create the wizard and the pages
155 wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
156 images.getWizTest1Bitmap())
157 page1 = TitledPage(wizard, "Page 1")
158 page2 = TitledPage(wizard, "Page 2")
159 page3 = TitledPage(wizard, "Page 3")
160 page4 = TitledPage(wizard, "Page 4")
161 self.page1 = page1
162
163 page1.sizer.Add(wx.StaticText(page1, -1, """
164 This wizard is totally useless, but is meant to show how to
165 chain simple wizard pages together in a non-dynamic manner.
166 IOW, the order of the pages never changes, and so the
167 wxWizardPageSimple class can easily be used for the pages."""))
168 wizard.FitToPage(page1)
169 page4.sizer.Add(wx.StaticText(page4, -1, "\nThis is the last page."))
170
171 # Use the convenience Chain function to connect the pages
172 wiz.WizardPageSimple_Chain(page1, page2)
173 wiz.WizardPageSimple_Chain(page2, page3)
174 wiz.WizardPageSimple_Chain(page3, page4)
175
176 if wizard.RunWizard(page1):
177 wx.MessageBox("Wizard completed successfully", "That's all folks!")
178 else:
179 wx.MessageBox("Wizard was cancelled", "That's all folks!")
180
181
182
183 def OnRunDynamicWizard(self, evt):
184 # Create the wizard and the pages
185 #wizard = wx.PreWizard()
186 #wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON)
187 #wizard.Create(self, self.ID_wiz, "Simple Wizard",
188 # images.getWizTest1Bitmap())
189 wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
190 images.getWizTest1Bitmap())
191
192 page1 = TitledPage(wizard, "Page 1")
193 page2 = SkipNextPage(wizard, "Page 2")
194 page3 = TitledPage(wizard, "Page 3")
195 page4 = UseAltBitmapPage(wizard, "Page 4")
196 page5 = TitledPage(wizard, "Page 5")
197 self.page1 = page1
198
199 page1.sizer.Add(wx.StaticText(page1, -1, """
200 This wizard shows the ability to choose at runtime the order
201 of the pages and also which bitmap is shown.
202 """))
203 wizard.FitToPage(page1)
204 page5.sizer.Add(wx.StaticText(page5, -1, "\nThis is the last page."))
205
206 # Set the initial order of the pages
207 page1.SetNext(page2)
208 page2.SetPrev(page1)
209 page2.SetNext(page3)
210 page3.SetPrev(page2)
211 page3.SetNext(page4)
212 page4.SetPrev(page3)
213 page4.SetNext(page5)
214 page5.SetPrev(page4)
215
216
217 if wizard.RunWizard(page1):
218 wx.MessageBox("Wizard completed successfully", "That's all folks!")
219 else:
220 wx.MessageBox("Wizard was cancelled", "That's all folks!")
221
222 #----------------------------------------------------------------------
223
224 def runTest(frame, nb, log):
225 win = TestPanel(nb, log)
226 return win
227
228 #----------------------------------------------------------------------
229
230
231
232 overview = """<html><body>
233 <h2><center>wxWizard</center></h2>
234
235 wxWizard is the central class for implementing 'wizard-like'
236 dialogs. These dialogs are mostly familiar to Windows users and are
237 nothing else but a sequence of 'pages' each of them displayed inside a
238 dialog which has the buttons to pass to the next (and previous) pages.
239 <p>
240 The wizards are typically used to decompose a complex dialog into
241 several simple steps and are mainly useful to the novice users, hence
242 it is important to keep them as simple as possible.
243
244 </body></html>
245 """
246
247
248
249 if __name__ == '__main__':
250 import sys,os
251 import run
252 run.main(['', os.path.basename(sys.argv[0])])
253