2003-12-08 20:23:28 -05:00
|
|
|
# 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Updated for wx namespace
|
|
|
|
#
|
|
|
|
# 11/3-/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o WizardPage* doesn't support GetId()
|
|
|
|
#
|
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.wizard as wiz
|
|
|
|
import images
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2002-08-21 20:00:04 -04:00
|
|
|
def makePageTitle(wizPg, title):
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
2002-08-21 20:00:04 -04:00
|
|
|
wizPg.SetSizer(sizer)
|
2003-12-08 20:23:28 -05:00
|
|
|
title = wx.StaticText(wizPg, -1, title)
|
|
|
|
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
|
|
|
|
sizer.AddWindow(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
|
|
|
|
sizer.AddWindow(wx.StaticLine(wizPg, -1), 0, wx.EXPAND|wx.ALL, 5)
|
2002-08-21 20:00:04 -04:00
|
|
|
return sizer
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TitledPage(wiz.WizardPageSimple):
|
2002-08-17 15:08:21 -04:00
|
|
|
def __init__(self, parent, title):
|
2003-12-08 20:23:28 -05:00
|
|
|
wiz.WizardPageSimple.__init__(self, parent)
|
2002-08-21 20:00:04 -04:00
|
|
|
self.sizer = makePageTitle(self, title)
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class SkipNextPage(wiz.PyWizardPage):
|
2002-08-21 20:00:04 -04:00
|
|
|
def __init__(self, parent, title):
|
2003-12-08 20:23:28 -05:00
|
|
|
wiz.PyWizardPage.__init__(self, parent)
|
2002-08-21 20:00:04 -04:00
|
|
|
self.next = self.prev = None
|
|
|
|
self.sizer = makePageTitle(self, title)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.cb = wx.CheckBox(self, -1, "Skip next page")
|
|
|
|
self.sizer.Add(self.cb, 0, wx.ALL, 5)
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2002-08-21 20:00:04 -04:00
|
|
|
def SetNext(self, next):
|
|
|
|
self.next = next
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2002-08-21 20:00:04 -04:00
|
|
|
def SetPrev(self, prev):
|
|
|
|
self.prev = prev
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
|
2002-08-21 20:00:04 -04:00
|
|
|
# Classes derived from wxPyWizardPanel must override
|
|
|
|
# GetNext and GetPrev, and may also override GetBitmap
|
|
|
|
# as well as all those methods overridable by
|
2003-12-08 20:23:28 -05:00
|
|
|
# wx.PyWindow.
|
2002-08-21 20:00:04 -04:00
|
|
|
|
|
|
|
def GetNext(self):
|
|
|
|
"""If the checkbox is set then return the next page's next page"""
|
|
|
|
next = self.next
|
|
|
|
if self.cb.GetValue():
|
|
|
|
next = next.GetNext()
|
|
|
|
return next
|
|
|
|
|
|
|
|
def GetPrev(self):
|
|
|
|
return self.prev
|
|
|
|
|
2002-08-21 17:46:53 -04:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class UseAltBitmapPage(wiz.PyWizardPage):
|
2002-08-21 20:00:04 -04:00
|
|
|
def __init__(self, parent, title):
|
2003-12-08 20:23:28 -05:00
|
|
|
wiz.PyWizardPage.__init__(self, parent)
|
2002-08-21 20:00:04 -04:00
|
|
|
self.next = self.prev = None
|
|
|
|
self.sizer = makePageTitle(self, title)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.sizer.Add(wx.StaticText(self, -1, "This page uses a different bitmap"),
|
|
|
|
0, wx.ALL, 5)
|
2002-08-21 20:00:04 -04:00
|
|
|
|
|
|
|
def SetNext(self, next):
|
|
|
|
self.next = next
|
|
|
|
|
|
|
|
def SetPrev(self, prev):
|
|
|
|
self.prev = prev
|
|
|
|
|
|
|
|
def GetNext(self):
|
|
|
|
return self.next
|
|
|
|
|
|
|
|
def GetPrev(self):
|
|
|
|
return self.prev
|
|
|
|
|
|
|
|
def GetBitmap(self):
|
|
|
|
# You usually wouldn't need to override this method
|
|
|
|
# since you can set a non-default bitmap in the
|
|
|
|
# wxWizardPageSimple constructor, but if you need to
|
|
|
|
# dynamically change the bitmap based on the
|
|
|
|
# contents of the wizard, or need to also change the
|
|
|
|
# next/prev order then it can be done by overriding
|
|
|
|
# GetBitmap.
|
|
|
|
return images.getWizTest2Bitmap()
|
2002-08-21 17:46:53 -04:00
|
|
|
|
2002-08-17 15:08:21 -04:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
|
|
|
ID_wiz = wx.NewId()
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
b = wx.Button(self, -1, "Run Simple Wizard", pos=(50, 50))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnRunSimpleWizard, b)
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
b = wx.Button(self, -1, "Run Dynamic Wizard", pos=(50, 100))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnRunDynamicWizard, b)
|
2002-08-21 17:46:53 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
wiz.EVT_WIZARD_PAGE_CHANGED(self, self.ID_wiz, self.OnWizPageChanged)
|
|
|
|
wiz.EVT_WIZARD_PAGE_CHANGING(self, self.ID_wiz, self.OnWizPageChanging)
|
|
|
|
wiz.EVT_WIZARD_CANCEL(self, self.ID_wiz, self.OnWizCancel)
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnWizPageChanged(self, evt):
|
|
|
|
if evt.GetDirection():
|
|
|
|
dir = "forward"
|
|
|
|
else:
|
|
|
|
dir = "backward"
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2002-08-21 17:46:53 -04:00
|
|
|
page = evt.GetPage()
|
|
|
|
self.log.write("OnWizPageChanged: %s, %s\n" % (dir, page.__class__))
|
|
|
|
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
def OnWizPageChanging(self, evt):
|
|
|
|
if evt.GetDirection():
|
|
|
|
dir = "forward"
|
|
|
|
else:
|
|
|
|
dir = "backward"
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2002-08-21 17:46:53 -04:00
|
|
|
page = evt.GetPage()
|
|
|
|
self.log.write("OnWizPageChanging: %s, %s\n" % (dir, page.__class__))
|
|
|
|
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
def OnWizCancel(self, evt):
|
2002-08-21 20:00:04 -04:00
|
|
|
page = evt.GetPage()
|
|
|
|
self.log.write("OnWizCancel: %s\n" % page.__class__)
|
|
|
|
|
|
|
|
# Show how to prevent cancelling of the wizard. The
|
|
|
|
# other events can be Veto'd too.
|
|
|
|
if page is self.page1:
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox("Cancelling on the first page has been prevented.", "Sorry")
|
2002-08-21 20:00:04 -04:00
|
|
|
evt.Veto()
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2003-10-18 00:31:26 -04:00
|
|
|
def OnWizFinished(self, evt):
|
|
|
|
self.log.write("OnWizFinished\n")
|
|
|
|
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
def OnRunSimpleWizard(self, evt):
|
|
|
|
# Create the wizard and the pages
|
2003-12-08 20:23:28 -05:00
|
|
|
wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
|
2002-08-17 15:08:21 -04:00
|
|
|
images.getWizTest1Bitmap())
|
|
|
|
page1 = TitledPage(wizard, "Page 1")
|
|
|
|
page2 = TitledPage(wizard, "Page 2")
|
|
|
|
page3 = TitledPage(wizard, "Page 3")
|
|
|
|
page4 = TitledPage(wizard, "Page 4")
|
2002-08-21 20:00:04 -04:00
|
|
|
self.page1 = page1
|
2002-08-17 15:08:21 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
page1.sizer.Add(wx.StaticText(page1, -1, """
|
2002-08-17 15:08:21 -04:00
|
|
|
This wizard is totally useless, but is meant to show how to
|
|
|
|
chain simple wizard pages together in a non-dynamic manner.
|
|
|
|
IOW, the order of the pages never changes, and so the
|
2002-08-21 17:46:53 -04:00
|
|
|
wxWizardPageSimple class can easily be used for the pages."""))
|
2002-08-17 15:08:21 -04:00
|
|
|
wizard.FitToPage(page1)
|
2003-12-08 20:23:28 -05:00
|
|
|
page4.sizer.Add(wx.StaticText(page4, -1, "\nThis is the last page."))
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
# Use the convenience Chain function to connect the pages
|
2003-12-08 20:23:28 -05:00
|
|
|
wiz.WizardPageSimple_Chain(page1, page2)
|
|
|
|
wiz.WizardPageSimple_Chain(page2, page3)
|
|
|
|
wiz.WizardPageSimple_Chain(page3, page4)
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
if wizard.RunWizard(page1):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox("Wizard completed successfully", "That's all folks!")
|
2002-08-17 15:08:21 -04:00
|
|
|
else:
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox("Wizard was cancelled", "That's all folks!")
|
2002-08-17 15:08:21 -04:00
|
|
|
|
|
|
|
|
2002-08-21 17:46:53 -04:00
|
|
|
|
|
|
|
def OnRunDynamicWizard(self, evt):
|
2002-08-21 20:00:04 -04:00
|
|
|
# Create the wizard and the pages
|
2003-12-08 20:23:28 -05:00
|
|
|
#wizard = wx.PreWizard()
|
|
|
|
#wizard.SetExtraStyle(wx.WIZARD_EX_HELPBUTTON)
|
2003-08-22 18:44:36 -04:00
|
|
|
#wizard.Create(self, self.ID_wiz, "Simple Wizard",
|
|
|
|
# images.getWizTest1Bitmap())
|
2003-12-08 20:23:28 -05:00
|
|
|
wizard = wiz.Wizard(self, self.ID_wiz, "Simple Wizard",
|
2002-08-21 20:00:04 -04:00
|
|
|
images.getWizTest1Bitmap())
|
|
|
|
|
|
|
|
page1 = TitledPage(wizard, "Page 1")
|
|
|
|
page2 = SkipNextPage(wizard, "Page 2")
|
|
|
|
page3 = TitledPage(wizard, "Page 3")
|
|
|
|
page4 = UseAltBitmapPage(wizard, "Page 4")
|
|
|
|
page5 = TitledPage(wizard, "Page 5")
|
|
|
|
self.page1 = page1
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
page1.sizer.Add(wx.StaticText(page1, -1, """
|
2002-08-21 20:00:04 -04:00
|
|
|
This wizard shows the ability to choose at runtime the order
|
|
|
|
of the pages and also which bitmap is shown.
|
|
|
|
"""))
|
|
|
|
wizard.FitToPage(page1)
|
2003-12-08 20:23:28 -05:00
|
|
|
page5.sizer.Add(wx.StaticText(page5, -1, "\nThis is the last page."))
|
2002-08-21 20:00:04 -04:00
|
|
|
|
|
|
|
# Set the initial order of the pages
|
|
|
|
page1.SetNext(page2)
|
|
|
|
page2.SetPrev(page1)
|
|
|
|
page2.SetNext(page3)
|
|
|
|
page3.SetPrev(page2)
|
|
|
|
page3.SetNext(page4)
|
|
|
|
page4.SetPrev(page3)
|
|
|
|
page4.SetNext(page5)
|
|
|
|
page5.SetPrev(page4)
|
|
|
|
|
|
|
|
|
|
|
|
if wizard.RunWizard(page1):
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox("Wizard completed successfully", "That's all folks!")
|
2002-08-21 20:00:04 -04:00
|
|
|
else:
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.MessageBox("Wizard was cancelled", "That's all folks!")
|
2002-08-21 17:46:53 -04:00
|
|
|
|
2002-08-17 15:08:21 -04:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h2><center>wxWizard</center></h2>
|
|
|
|
|
|
|
|
wxWizard is the central class for implementing 'wizard-like'
|
|
|
|
dialogs. These dialogs are mostly familiar to Windows users and are
|
|
|
|
nothing else but a sequence of 'pages' each of them displayed inside a
|
|
|
|
dialog which has the buttons to pass to the next (and previous) pages.
|
|
|
|
<p>
|
|
|
|
The wizards are typically used to decompose a complex dialog into
|
|
|
|
several simple steps and are mainly useful to the novice users, hence
|
|
|
|
it is important to keep them as simple as possible.
|
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|
|
|
|
|