]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxWizard.py
Added PyPlot
[wxWidgets.git] / wxPython / demo / wxWizard.py
CommitLineData
8fa876ca
RD
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
10import wx
11import wx.wizard as wiz
12import images
af83019e
RD
13
14#----------------------------------------------------------------------
15
85260f24 16def makePageTitle(wizPg, title):
8fa876ca 17 sizer = wx.BoxSizer(wx.VERTICAL)
85260f24 18 wizPg.SetSizer(sizer)
8fa876ca
RD
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)
85260f24
RD
23 return sizer
24
25#----------------------------------------------------------------------
26
8fa876ca 27class TitledPage(wiz.WizardPageSimple):
af83019e 28 def __init__(self, parent, title):
8fa876ca 29 wiz.WizardPageSimple.__init__(self, parent)
85260f24
RD
30 self.sizer = makePageTitle(self, title)
31
32
33#----------------------------------------------------------------------
34
8fa876ca 35class SkipNextPage(wiz.PyWizardPage):
85260f24 36 def __init__(self, parent, title):
8fa876ca 37 wiz.PyWizardPage.__init__(self, parent)
85260f24
RD
38 self.next = self.prev = None
39 self.sizer = makePageTitle(self, title)
40
8fa876ca
RD
41 self.cb = wx.CheckBox(self, -1, "Skip next page")
42 self.sizer.Add(self.cb, 0, wx.ALL, 5)
af83019e 43
85260f24
RD
44 def SetNext(self, next):
45 self.next = next
af83019e 46
85260f24
RD
47 def SetPrev(self, prev):
48 self.prev = prev
af83019e
RD
49
50
85260f24
RD
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
8fa876ca 54 # wx.PyWindow.
85260f24
RD
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
6a6ff564
RD
66#----------------------------------------------------------------------
67
8fa876ca 68class UseAltBitmapPage(wiz.PyWizardPage):
85260f24 69 def __init__(self, parent, title):
8fa876ca 70 wiz.PyWizardPage.__init__(self, parent)
85260f24
RD
71 self.next = self.prev = None
72 self.sizer = makePageTitle(self, title)
73
8fa876ca
RD
74 self.sizer.Add(wx.StaticText(self, -1, "This page uses a different bitmap"),
75 0, wx.ALL, 5)
85260f24
RD
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()
6a6ff564 98
af83019e
RD
99#----------------------------------------------------------------------
100
8fa876ca
RD
101class TestPanel(wx.Panel):
102 ID_wiz = wx.NewId()
af83019e
RD
103
104 def __init__(self, parent, log):
105 self.log = log
8fa876ca 106 wx.Panel.__init__(self, parent, -1)
af83019e 107
8fa876ca
RD
108 b = wx.Button(self, -1, "Run Simple Wizard", pos=(50, 50))
109 self.Bind(wx.EVT_BUTTON, self.OnRunSimpleWizard, b)
af83019e 110
8fa876ca
RD
111 b = wx.Button(self, -1, "Run Dynamic Wizard", pos=(50, 100))
112 self.Bind(wx.EVT_BUTTON, self.OnRunDynamicWizard, b)
6a6ff564 113
8fa876ca
RD
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)
af83019e
RD
117
118
119 def OnWizPageChanged(self, evt):
120 if evt.GetDirection():
121 dir = "forward"
122 else:
123 dir = "backward"
8fa876ca 124
6a6ff564
RD
125 page = evt.GetPage()
126 self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__))
127
af83019e
RD
128
129 def OnWizPageChanging(self, evt):
130 if evt.GetDirection():
131 dir = "forward"
132 else:
133 dir = "backward"
8fa876ca 134
6a6ff564
RD
135 page = evt.GetPage()
136 self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__))
137
af83019e
RD
138
139 def OnWizCancel(self, evt):
85260f24
RD
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:
8fa876ca 146 wx.MessageBox("Cancelling on the first page has been prevented.", "Sorry")
85260f24 147 evt.Veto()
af83019e 148
118f4724
RD
149 def OnWizFinished(self, evt):
150 self.log.write("OnWizFinished\n")
151
af83019e
RD
152
153 def OnRunSimpleWizard(self, evt):
154 # Create the wizard and the pages
8fa876ca 155 wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
af83019e
RD
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")
85260f24 161 self.page1 = page1
af83019e 162
8fa876ca 163 page1.sizer.Add(wx.StaticText(page1, -1, """
af83019e
RD
164This wizard is totally useless, but is meant to show how to
165chain simple wizard pages together in a non-dynamic manner.
166IOW, the order of the pages never changes, and so the
6a6ff564 167wxWizardPageSimple class can easily be used for the pages."""))
af83019e 168 wizard.FitToPage(page1)
8fa876ca 169 page4.sizer.Add(wx.StaticText(page4, -1, "\nThis is the last page."))
af83019e
RD
170
171 # Use the convenience Chain function to connect the pages
8fa876ca
RD
172 wiz.WizardPageSimple_Chain(page1, page2)
173 wiz.WizardPageSimple_Chain(page2, page3)
174 wiz.WizardPageSimple_Chain(page3, page4)
af83019e
RD
175
176 if wizard.RunWizard(page1):
8fa876ca 177 wx.MessageBox("Wizard completed successfully", "That's all folks!")
af83019e 178 else:
8fa876ca 179 wx.MessageBox("Wizard was cancelled", "That's all folks!")
af83019e
RD
180
181
6a6ff564
RD
182
183 def OnRunDynamicWizard(self, evt):
85260f24 184 # Create the wizard and the pages
8fa876ca
RD
185 #wizard = wx.PreWizard()
186 #wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON)
f94e8b87
RD
187 #wizard.Create(self, self.ID_wiz, "Simple Wizard",
188 # images.getWizTest1Bitmap())
8fa876ca 189 wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
85260f24
RD
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
8fa876ca 199 page1.sizer.Add(wx.StaticText(page1, -1, """
85260f24
RD
200This wizard shows the ability to choose at runtime the order
201of the pages and also which bitmap is shown.
202"""))
203 wizard.FitToPage(page1)
8fa876ca 204 page5.sizer.Add(wx.StaticText(page5, -1, "\nThis is the last page."))
85260f24
RD
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):
8fa876ca 218 wx.MessageBox("Wizard completed successfully", "That's all folks!")
85260f24 219 else:
8fa876ca 220 wx.MessageBox("Wizard was cancelled", "That's all folks!")
6a6ff564 221
af83019e
RD
222#----------------------------------------------------------------------
223
224def runTest(frame, nb, log):
225 win = TestPanel(nb, log)
226 return win
227
228#----------------------------------------------------------------------
229
230
231
232overview = """<html><body>
233<h2><center>wxWizard</center></h2>
234
235wxWizard is the central class for implementing 'wizard-like'
236dialogs. These dialogs are mostly familiar to Windows users and are
237nothing else but a sequence of 'pages' each of them displayed inside a
238dialog which has the buttons to pass to the next (and previous) pages.
239<p>
240The wizards are typically used to decompose a complex dialog into
241several simple steps and are mainly useful to the novice users, hence
242it is important to keep them as simple as possible.
243
244</body></html>
245"""
246
247
248
249if __name__ == '__main__':
250 import sys,os
251 import run
252 run.main(['', os.path.basename(sys.argv[0])])
253