]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxWizard.py
2 from wxPython
.wx
import *
3 from wxPython
.wizard
import *
7 #----------------------------------------------------------------------
9 def makePageTitle(wizPg
, title
):
10 sizer
= wxBoxSizer(wxVERTICAL
)
12 title
= wxStaticText(wizPg
, -1, title
)
13 title
.SetFont(wxFont(18, wxSWISS
, wxNORMAL
, wxBOLD
))
14 sizer
.AddWindow(title
, 0, wxALIGN_CENTRE|wxALL
, 5)
15 sizer
.AddWindow(wxStaticLine(wizPg
, -1), 0, wxEXPAND|wxALL
, 5)
18 #----------------------------------------------------------------------
20 class TitledPage(wxWizardPageSimple
):
21 def __init__(self
, parent
, title
):
22 wxWizardPageSimple
.__init
__(self
, parent
)
23 self
.sizer
= makePageTitle(self
, title
)
26 #----------------------------------------------------------------------
28 class SkipNextPage(wxPyWizardPage
):
29 def __init__(self
, parent
, title
):
30 wxPyWizardPage
.__init
__(self
, parent
)
31 self
.next
= self
.prev
= None
32 self
.sizer
= makePageTitle(self
, title
)
34 self
.cb
= wxCheckBox(self
, -1, "Skip next page")
35 self
.sizer
.Add(self
.cb
, 0, wxALL
, 5)
37 def SetNext(self
, next
):
40 def SetPrev(self
, prev
):
44 # Classes derived from wxPyWizardPanel must override
45 # GetNext and GetPrev, and may also override GetBitmap
46 # as well as all those methods overridable by
50 """If the checkbox is set then return the next page's next page"""
52 if self
.cb
.GetValue():
59 #----------------------------------------------------------------------
61 class UseAltBitmapPage(wxPyWizardPage
):
62 def __init__(self
, parent
, title
):
63 wxPyWizardPage
.__init
__(self
, parent
)
64 self
.next
= self
.prev
= None
65 self
.sizer
= makePageTitle(self
, title
)
67 self
.sizer
.Add(wxStaticText(self
, -1, "This page uses a different bitmap"),
70 def SetNext(self
, next
):
73 def SetPrev(self
, prev
):
83 # You usually wouldn't need to override this method
84 # since you can set a non-default bitmap in the
85 # wxWizardPageSimple constructor, but if you need to
86 # dynamically change the bitmap based on the
87 # contents of the wizard, or need to also change the
88 # next/prev order then it can be done by overriding
90 return images
.getWizTest2Bitmap()
92 #----------------------------------------------------------------------
94 class TestPanel(wxPanel
):
97 def __init__(self
, parent
, log
):
99 wxPanel
.__init
__(self
, parent
, -1)
101 b
= wxButton(self
, -1, "Run Simple Wizard", pos
=(50, 50))
102 EVT_BUTTON(self
, b
.GetId(), self
.OnRunSimpleWizard
)
104 b
= wxButton(self
, -1, "Run Dynamic Wizard", pos
=(50, 100))
105 EVT_BUTTON(self
, b
.GetId(), self
.OnRunDynamicWizard
)
107 EVT_WIZARD_PAGE_CHANGED(self
, self
.ID_wiz
, self
.OnWizPageChanged
)
108 EVT_WIZARD_PAGE_CHANGING(self
, self
.ID_wiz
, self
.OnWizPageChanging
)
109 EVT_WIZARD_CANCEL(self
, self
.ID_wiz
, self
.OnWizCancel
)
110 EVT_WIZARD_FINISHED(self
, self
.ID_wiz
, self
.OnWizFinished
)
113 def OnWizPageChanged(self
, evt
):
114 if evt
.GetDirection():
119 self
.log
.write("OnWizPageChanged: %s, %s\n" % (dir, page
.__class
__))
122 def OnWizPageChanging(self
, evt
):
123 if evt
.GetDirection():
128 self
.log
.write("OnWizPageChanging: %s, %s\n" % (dir, page
.__class
__))
131 def OnWizCancel(self
, evt
):
133 self
.log
.write("OnWizCancel: %s\n" % page
.__class
__)
135 # Show how to prevent cancelling of the wizard. The
136 # other events can be Veto'd too.
137 if page
is self
.page1
:
138 wxMessageBox("Cancelling on the first page has been prevented.", "Sorry")
141 def OnWizFinished(self
, evt
):
142 self
.log
.write("OnWizFinished\n")
145 def OnRunSimpleWizard(self
, evt
):
146 # Create the wizard and the pages
147 wizard
= wxWizard(self
, self
.ID_wiz
, "Simple Wizard",
148 images
.getWizTest1Bitmap())
149 page1
= TitledPage(wizard
, "Page 1")
150 page2
= TitledPage(wizard
, "Page 2")
151 page3
= TitledPage(wizard
, "Page 3")
152 page4
= TitledPage(wizard
, "Page 4")
155 page1
.sizer
.Add(wxStaticText(page1
, -1, """
156 This wizard is totally useless, but is meant to show how to
157 chain simple wizard pages together in a non-dynamic manner.
158 IOW, the order of the pages never changes, and so the
159 wxWizardPageSimple class can easily be used for the pages."""))
160 wizard
.FitToPage(page1
)
161 page4
.sizer
.Add(wxStaticText(page4
, -1, "\nThis is the last page."))
163 # Use the convenience Chain function to connect the pages
164 wxWizardPageSimple_Chain(page1
, page2
)
165 wxWizardPageSimple_Chain(page2
, page3
)
166 wxWizardPageSimple_Chain(page3
, page4
)
168 if wizard
.RunWizard(page1
):
169 wxMessageBox("Wizard completed successfully", "That's all folks!")
171 wxMessageBox("Wizard was cancelled", "That's all folks!")
175 def OnRunDynamicWizard(self
, evt
):
176 # Create the wizard and the pages
177 #wizard = wxPreWizard()
178 #wizard.SetExtraStyle(wxWIZARD_EX_HELPBUTTON)
179 #wizard.Create(self, self.ID_wiz, "Simple Wizard",
180 # images.getWizTest1Bitmap())
181 wizard
= wxWizard(self
, self
.ID_wiz
, "Simple Wizard",
182 images
.getWizTest1Bitmap())
184 page1
= TitledPage(wizard
, "Page 1")
185 page2
= SkipNextPage(wizard
, "Page 2")
186 page3
= TitledPage(wizard
, "Page 3")
187 page4
= UseAltBitmapPage(wizard
, "Page 4")
188 page5
= TitledPage(wizard
, "Page 5")
191 page1
.sizer
.Add(wxStaticText(page1
, -1, """
192 This wizard shows the ability to choose at runtime the order
193 of the pages and also which bitmap is shown.
195 wizard
.FitToPage(page1
)
196 page5
.sizer
.Add(wxStaticText(page5
, -1, "\nThis is the last page."))
198 # Set the initial order of the pages
209 if wizard
.RunWizard(page1
):
210 wxMessageBox("Wizard completed successfully", "That's all folks!")
212 wxMessageBox("Wizard was cancelled", "That's all folks!")
214 #----------------------------------------------------------------------
216 def runTest(frame
, nb
, log
):
217 win
= TestPanel(nb
, log
)
220 #----------------------------------------------------------------------
224 overview
= """<html><body>
225 <h2><center>wxWizard</center></h2>
227 wxWizard is the central class for implementing 'wizard-like'
228 dialogs. These dialogs are mostly familiar to Windows users and are
229 nothing else but a sequence of 'pages' each of them displayed inside a
230 dialog which has the buttons to pass to the next (and previous) pages.
232 The wizards are typically used to decompose a complex dialog into
233 several simple steps and are mainly useful to the novice users, hence
234 it is important to keep them as simple as possible.
241 if __name__
== '__main__':
244 run
.main(['', os
.path
.basename(sys
.argv
[0])])