]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxWizard.py
1 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/3-/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o WizardPage* doesn't support GetId()
11 import wx
.wizard
as wiz
14 #----------------------------------------------------------------------
16 def makePageTitle(wizPg
, title
):
17 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
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)
25 #----------------------------------------------------------------------
27 class TitledPage(wiz
.WizardPageSimple
):
28 def __init__(self
, parent
, title
):
29 wiz
.WizardPageSimple
.__init
__(self
, parent
)
30 self
.sizer
= makePageTitle(self
, title
)
33 #----------------------------------------------------------------------
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
)
41 self
.cb
= wx
.CheckBox(self
, -1, "Skip next page")
42 self
.sizer
.Add(self
.cb
, 0, wx
.ALL
, 5)
44 def SetNext(self
, next
):
47 def SetPrev(self
, prev
):
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
57 """If the checkbox is set then return the next page's next page"""
59 if self
.cb
.GetValue():
66 #----------------------------------------------------------------------
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
)
74 self
.sizer
.Add(wx
.StaticText(self
, -1, "This page uses a different bitmap"),
77 def SetNext(self
, next
):
80 def SetPrev(self
, prev
):
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
97 return images
.getWizTest2Bitmap()
99 #----------------------------------------------------------------------
101 class TestPanel(wx
.Panel
):
104 def __init__(self
, parent
, log
):
106 wx
.Panel
.__init
__(self
, parent
, -1)
108 b
= wx
.Button(self
, -1, "Run Simple Wizard", pos
=(50, 50))
109 self
.Bind(wx
.EVT_BUTTON
, self
.OnRunSimpleWizard
, b
)
111 b
= wx
.Button(self
, -1, "Run Dynamic Wizard", pos
=(50, 100))
112 self
.Bind(wx
.EVT_BUTTON
, self
.OnRunDynamicWizard
, b
)
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
)
119 def OnWizPageChanged(self
, evt
):
120 if evt
.GetDirection():
126 self
.log
.write("OnWizPageChanged: %s, %s\n" % (dir, page
.__class
__))
129 def OnWizPageChanging(self
, evt
):
130 if evt
.GetDirection():
136 self
.log
.write("OnWizPageChanging: %s, %s\n" % (dir, page
.__class
__))
139 def OnWizCancel(self
, evt
):
141 self
.log
.write("OnWizCancel: %s\n" % page
.__class
__)
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")
149 def OnWizFinished(self
, evt
):
150 self
.log
.write("OnWizFinished\n")
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")
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."))
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
)
176 if wizard
.RunWizard(page1
):
177 wx
.MessageBox("Wizard completed successfully", "That's all folks!")
179 wx
.MessageBox("Wizard was cancelled", "That's all folks!")
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())
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")
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.
203 wizard
.FitToPage(page1
)
204 page5
.sizer
.Add(wx
.StaticText(page5
, -1, "\nThis is the last page."))
206 # Set the initial order of the pages
217 if wizard
.RunWizard(page1
):
218 wx
.MessageBox("Wizard completed successfully", "That's all folks!")
220 wx
.MessageBox("Wizard was cancelled", "That's all folks!")
222 #----------------------------------------------------------------------
224 def runTest(frame
, nb
, log
):
225 win
= TestPanel(nb
, log
)
228 #----------------------------------------------------------------------
232 overview
= """<html><body>
233 <h2><center>wxWizard</center></h2>
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.
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.
249 if __name__
== '__main__':
252 run
.main(['', os
.path
.basename(sys
.argv
[0])])