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