]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Wizard.py
3 import wx
.wizard
as wiz
6 #----------------------------------------------------------------------
8 def makePageTitle(wizPg
, title
):
9 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
11 title
= wx
.StaticText(wizPg
, -1, title
)
12 title
.SetFont(wx
.Font(18, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
))
13 sizer
.AddWindow(title
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5)
14 sizer
.AddWindow(wx
.StaticLine(wizPg
, -1), 0, wx
.EXPAND|wx
.ALL
, 5)
17 #----------------------------------------------------------------------
19 class TitledPage(wiz
.WizardPageSimple
):
20 def __init__(self
, parent
, title
):
21 wiz
.WizardPageSimple
.__init
__(self
, parent
)
22 self
.sizer
= makePageTitle(self
, title
)
25 #----------------------------------------------------------------------
27 class SkipNextPage(wiz
.PyWizardPage
):
28 def __init__(self
, parent
, title
):
29 wiz
.PyWizardPage
.__init
__(self
, parent
)
30 self
.next
= self
.prev
= None
31 self
.sizer
= makePageTitle(self
, title
)
33 self
.cb
= wx
.CheckBox(self
, -1, "Skip next page")
34 self
.sizer
.Add(self
.cb
, 0, wx
.ALL
, 5)
36 def SetNext(self
, next
):
39 def SetPrev(self
, prev
):
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
49 """If the checkbox is set then return the next page's next page"""
51 if self
.cb
.GetValue():
58 #----------------------------------------------------------------------
60 class UseAltBitmapPage(wiz
.PyWizardPage
):
61 def __init__(self
, parent
, title
):
62 wiz
.PyWizardPage
.__init
__(self
, parent
)
63 self
.next
= self
.prev
= None
64 self
.sizer
= makePageTitle(self
, title
)
66 self
.sizer
.Add(wx
.StaticText(self
, -1, "This page uses a different bitmap"),
69 def SetNext(self
, next
):
72 def SetPrev(self
, prev
):
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
89 return images
.getWizTest2Bitmap()
91 #----------------------------------------------------------------------
93 class TestPanel(wx
.Panel
):
94 def __init__(self
, parent
, log
):
96 wx
.Panel
.__init
__(self
, parent
, -1)
98 b
= wx
.Button(self
, -1, "Run Simple Wizard", pos
=(50, 50))
99 self
.Bind(wx
.EVT_BUTTON
, self
.OnRunSimpleWizard
, b
)
101 b
= wx
.Button(self
, -1, "Run Dynamic Wizard", pos
=(50, 100))
102 self
.Bind(wx
.EVT_BUTTON
, self
.OnRunDynamicWizard
, b
)
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
)
109 def OnWizPageChanged(self
, evt
):
110 if evt
.GetDirection():
116 self
.log
.write("OnWizPageChanged: %s, %s\n" % (dir, page
.__class
__))
119 def OnWizPageChanging(self
, evt
):
120 if evt
.GetDirection():
126 self
.log
.write("OnWizPageChanging: %s, %s\n" % (dir, page
.__class
__))
129 def OnWizCancel(self
, evt
):
131 self
.log
.write("OnWizCancel: %s\n" % page
.__class
__)
133 # Show how to prevent cancelling of the wizard. The
134 # other events can be Veto'd too.
135 if page
is self
.page1
:
136 wx
.MessageBox("Cancelling on the first page has been prevented.", "Sorry")
139 def OnWizFinished(self
, evt
):
140 self
.log
.write("OnWizFinished\n")
143 def OnRunSimpleWizard(self
, evt
):
144 # Create the wizard and the pages
145 wizard
= wiz
.Wizard(self
, -1, "Simple Wizard", images
.getWizTest1Bitmap())
146 page1
= TitledPage(wizard
, "Page 1")
147 page2
= TitledPage(wizard
, "Page 2")
148 page3
= TitledPage(wizard
, "Page 3")
149 page4
= TitledPage(wizard
, "Page 4")
152 page1
.sizer
.Add(wx
.StaticText(page1
, -1, """
153 This wizard is totally useless, but is meant to show how to
154 chain simple wizard pages together in a non-dynamic manner.
155 IOW, the order of the pages never changes, and so the
156 wxWizardPageSimple class can easily be used for the pages."""))
157 wizard
.FitToPage(page1
)
158 page4
.sizer
.Add(wx
.StaticText(page4
, -1, "\nThis is the last page."))
160 # Use the convenience Chain function to connect the pages
161 wiz
.WizardPageSimple_Chain(page1
, page2
)
162 wiz
.WizardPageSimple_Chain(page2
, page3
)
163 wiz
.WizardPageSimple_Chain(page3
, page4
)
165 if wizard
.RunWizard(page1
):
166 wx
.MessageBox("Wizard completed successfully", "That's all folks!")
168 wx
.MessageBox("Wizard was cancelled", "That's all folks!")
172 def OnRunDynamicWizard(self
, evt
):
173 # Create the wizard and the pages
174 #wizard = wx.PreWizard()
175 #wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON)
176 #wizard.Create(self, self.ID_wiz, "Simple Wizard",
177 # images.getWizTest1Bitmap())
178 wizard
= wiz
.Wizard(self
, -1, "Simple Wizard", images
.getWizTest1Bitmap())
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")
187 page1
.sizer
.Add(wx
.StaticText(page1
, -1, """
188 This wizard shows the ability to choose at runtime the order
189 of the pages and also which bitmap is shown.
191 wizard
.FitToPage(page1
)
192 page5
.sizer
.Add(wx
.StaticText(page5
, -1, "\nThis is the last page."))
194 # Set the initial order of the pages
205 if wizard
.RunWizard(page1
):
206 wx
.MessageBox("Wizard completed successfully", "That's all folks!")
208 wx
.MessageBox("Wizard was cancelled", "That's all folks!")
210 #----------------------------------------------------------------------
212 def runTest(frame
, nb
, log
):
213 win
= TestPanel(nb
, log
)
216 #----------------------------------------------------------------------
220 overview
= """<html><body>
221 <h2><center>wxWizard</center></h2>
223 wxWizard is the central class for implementing 'wizard-like'
224 dialogs. These dialogs are mostly familiar to Windows users and are
225 nothing else but a sequence of 'pages' each of them displayed inside a
226 dialog which has the buttons to pass to the next (and previous) pages.
228 The wizards are typically used to decompose a complex dialog into
229 several simple steps and are mainly useful to the novice users, hence
230 it is important to keep them as simple as possible.
237 if __name__
== '__main__':
240 run
.main(['', os
.path
.basename(sys
.argv
[0])])