]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxWizard.py
fix text scrolling in GTK2 (patch 703988)
[wxWidgets.git] / wxPython / demo / wxWizard.py
CommitLineData
af83019e
RD
1
2from wxPython.wx import *
3from wxPython.wizard import *
4
5import images
6
7#----------------------------------------------------------------------
8
85260f24
RD
9def makePageTitle(wizPg, title):
10 sizer = wxBoxSizer(wxVERTICAL)
11 wizPg.SetSizer(sizer)
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)
16 return sizer
17
18#----------------------------------------------------------------------
19
af83019e
RD
20class TitledPage(wxWizardPageSimple):
21 def __init__(self, parent, title):
22 wxWizardPageSimple.__init__(self, parent)
85260f24
RD
23 self.sizer = makePageTitle(self, title)
24
25
26#----------------------------------------------------------------------
27
28class 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)
33
34 self.cb = wxCheckBox(self, -1, "Skip next page")
35 self.sizer.Add(self.cb, 0, wxALL, 5)
af83019e 36
85260f24
RD
37 def SetNext(self, next):
38 self.next = next
af83019e 39
85260f24
RD
40 def SetPrev(self, prev):
41 self.prev = prev
af83019e
RD
42
43
85260f24
RD
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
47 # wxPyWindow.
48
49 def GetNext(self):
50 """If the checkbox is set then return the next page's next page"""
51 next = self.next
52 if self.cb.GetValue():
53 next = next.GetNext()
54 return next
55
56 def GetPrev(self):
57 return self.prev
58
6a6ff564
RD
59#----------------------------------------------------------------------
60
85260f24
RD
61class 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)
66
67 self.sizer.Add(wxStaticText(self, -1, "This page uses a different bitmap"),
68 0, wxALL, 5)
69
70 def SetNext(self, next):
71 self.next = next
72
73 def SetPrev(self, prev):
74 self.prev = prev
75
76 def GetNext(self):
77 return self.next
78
79 def GetPrev(self):
80 return self.prev
81
82 def GetBitmap(self):
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
89 # GetBitmap.
90 return images.getWizTest2Bitmap()
6a6ff564 91
af83019e
RD
92#----------------------------------------------------------------------
93
94class TestPanel(wxPanel):
95 ID_wiz = wxNewId()
96
97 def __init__(self, parent, log):
98 self.log = log
99 wxPanel.__init__(self, parent, -1)
100
6a6ff564 101 b = wxButton(self, -1, "Run Simple Wizard", pos=(50, 50))
af83019e
RD
102 EVT_BUTTON(self, b.GetId(), self.OnRunSimpleWizard)
103
6a6ff564
RD
104 b = wxButton(self, -1, "Run Dynamic Wizard", pos=(50, 100))
105 EVT_BUTTON(self, b.GetId(), self.OnRunDynamicWizard)
106
af83019e
RD
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
111
112 def OnWizPageChanged(self, evt):
113 if evt.GetDirection():
114 dir = "forward"
115 else:
116 dir = "backward"
6a6ff564
RD
117 page = evt.GetPage()
118 self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__))
119
af83019e
RD
120
121 def OnWizPageChanging(self, evt):
122 if evt.GetDirection():
123 dir = "forward"
124 else:
125 dir = "backward"
6a6ff564
RD
126 page = evt.GetPage()
127 self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__))
128
af83019e
RD
129
130 def OnWizCancel(self, evt):
85260f24
RD
131 page = evt.GetPage()
132 self.log.write("OnWizCancel: %s\n" % page.__class__)
133
134 # Show how to prevent cancelling of the wizard. The
135 # other events can be Veto'd too.
136 if page is self.page1:
137 wxMessageBox("Cancelling on the first page has been prevented.", "Sorry")
138 evt.Veto()
af83019e
RD
139
140
141 def OnRunSimpleWizard(self, evt):
142 # Create the wizard and the pages
143 wizard = wxWizard(self, self.ID_wiz, "Simple Wizard",
144 images.getWizTest1Bitmap())
145 page1 = TitledPage(wizard, "Page 1")
146 page2 = TitledPage(wizard, "Page 2")
147 page3 = TitledPage(wizard, "Page 3")
148 page4 = TitledPage(wizard, "Page 4")
85260f24 149 self.page1 = page1
af83019e 150
85260f24 151 page1.sizer.Add(wxStaticText(page1, -1, """
af83019e
RD
152This wizard is totally useless, but is meant to show how to
153chain simple wizard pages together in a non-dynamic manner.
154IOW, the order of the pages never changes, and so the
6a6ff564 155wxWizardPageSimple class can easily be used for the pages."""))
af83019e 156 wizard.FitToPage(page1)
85260f24 157 page4.sizer.Add(wxStaticText(page4, -1, "\nThis is the last page."))
af83019e
RD
158
159 # Use the convenience Chain function to connect the pages
160 wxWizardPageSimple_Chain(page1, page2)
161 wxWizardPageSimple_Chain(page2, page3)
162 wxWizardPageSimple_Chain(page3, page4)
163
164 if wizard.RunWizard(page1):
165 wxMessageBox("Wizard completed successfully", "That's all folks!")
166 else:
167 wxMessageBox("Wizard was cancelled", "That's all folks!")
168
169
6a6ff564
RD
170
171 def OnRunDynamicWizard(self, evt):
85260f24 172 # Create the wizard and the pages
f94e8b87
RD
173 #wizard = wxPreWizard()
174 #wizard.SetExtraStyle(wxWIZARD_EX_HELPBUTTON)
175 #wizard.Create(self, self.ID_wiz, "Simple Wizard",
176 # images.getWizTest1Bitmap())
85260f24
RD
177 wizard = wxWizard(self, self.ID_wiz, "Simple Wizard",
178 images.getWizTest1Bitmap())
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
187 page1.sizer.Add(wxStaticText(page1, -1, """
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)
192 page5.sizer.Add(wxStaticText(page5, -1, "\nThis is the last page."))
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):
206 wxMessageBox("Wizard completed successfully", "That's all folks!")
207 else:
208 wxMessageBox("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
240 run.main(['', os.path.basename(sys.argv[0])])
241