How to use wxWizard?

I wanted to write a very simple program using the either wxWizard or wxWizardPageSimple. I have included below some code that I pulled from
the demo.py wizard example and tweeked a bit to try and make a very simple stand alone Wizard application.

wizard = wxWizard(None, -1, "Hello World")
seems to be the line that is causing problems.

Can anyone see what's wrong with my code? Has anyone ever successfully built a very simple wxWizard based application???

Please reply to me directly as I cannot read the messages on this mailing list.

Thanks,

Darren

···

----------------------------------------------------------------------
from wxPython.wx import *
from wxPython.wizard import *

def makePageTitle(wizPg, title):
     sizer = wxBoxSizer(wxVERTICAL)
     wizPg.SetSizer(sizer)
     title = wxStaticText(wizPg, -1, title)
     title.SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD))
     sizer.AddWindow(title, 0, wxALIGN_CENTRE|wxALL, 5)
     sizer.AddWindow(wxStaticLine(wizPg, -1), 0, wxEXPAND|wxALL, 5)
     return sizer

class TitledPage(wxWizardPageSimple):
     def __init__(self, parent, title):
         wxWizardPageSimple.__init__(self, parent)
         self.sizer = makePageTitle(self, title)

wizard = wxWizard(None, -1, "Hello World")
page1 = TitledPage(wizard, "Page 1")
page2 = TitledPage(wizard, "Page 2")
page3 = TitledPage(wizard, "Page 3")

wxWizardPageSimple_Chain(page1, page2)
wxWizardPageSimple_Chain(page2, page3)

wizard.RunWizard(page1)
if wizard.RunWizard(page1):
     wxMessageBox("Wizard completed successfully", "That's all folks!")
else:
     wxMessageBox("Wizard was cancelled", "That's all folks!")

Hi,
Every wx app needs a mainloop. The wizard probably also needs a wxFrame to
be placed into.

Something like:

class theApp(wxApp):
def OnInit(self):
  frame = frameClass(None, -1,"Title") # this could create the wizard like
you want in it's init method
  frame.Show(true)
  self.SetTopWindow(frame)
  return true

def main():
try:
  demoPath = os.path.dirname(__file__)
  os.chdir(demoPath)
except:
  pass
myApp = theApp( 0 )
myApp.MainLoop()

if __name__ == "__main__":
main()

I hope this helps.

-Rick King
Southfield MI USA

···

I wanted to write a very simple program using the either wxWizard or
wxWizardPageSimple. I have included below some code that I pulled from
the demo.py wizard example and tweeked a bit to try and make a very
simple stand alone Wizard application.

wizard = wxWizard(None, -1, "Hello World")
seems to be the line that is causing problems.

Can anyone see what's wrong with my code? Has anyone ever successfully
built a very simple wxWizard based application???

Darren Blaser wrote:

I wanted to write a very simple program using the either wxWizard or wxWizardPageSimple. I have included below some code that I pulled from
the demo.py wizard example and tweeked a bit to try and make a very simple stand alone Wizard application.

wizard = wxWizard(None, -1, "Hello World")
seems to be the line that is causing problems.

Can anyone see what's wrong with my code? Has anyone ever successfully built a very simple wxWizard based application???

You need to create a wxApp (wxPySimpleApp is okay) first as there is a bunch of initialization that happens there. Also eventhough the wizard is a wxDialog you need to call app.MainLoop after it is done so the system can cleanup after itself.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks to both Robin and Rick for the tips on using wxApp or wxPySimpleApp.

I went back and read the Full Getting started page
http://wiki.wxpython.org/index.cgi/Getting_20Started
and made sure I understood everything on it.

Then I noticed in the demo code that wxWizard is in the "Base Frame and Dialogs" section of the wxPython demo.py and concluded that it should be used similar to how to wxFrame and wxDialog are used.

The code I am working on now is below in it's entirety. I am very confident that the
  def makePageTitle(wizPg, title):
and
  class TitledPage(wxWizardPageSimple):
sections do not have any problems as I cut and pasted them directly out of the working demo.py script.

The program part:
app = wxPySimpleApp()
wizard = MyWizard(None, -1)
app.MainLoop()

Should be OK correct too except for the
wizard = MyWizard(None, -1)
line which I am just guessing at since I can't find any useful wxWizardPageSimple documentation anyware. This page seems like it should be useful but I'm obviously still missing something....
http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin420.htm#wxwizardpagesimple

And the
  class MyWizard(wxWizardPageSimple):
section which I am just guessing at as well. See no documentation comment above :frowning:

Has anyone else ever created a simple standalone wxWizard application in wxPython?

Here's the latest version of code I'm working on. I really don't understand why this is so difficult for me... Can anyone help?

···

__________________________________________________________________

from wxPython.wx import *
from wxPython.wizard import *

def makePageTitle(wizPg, title):
     sizer = wxBoxSizer(wxVERTICAL)
     wizPg.SetSizer(sizer)
     title = wxStaticText(wizPg, -1, title)
     title.SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD))
     sizer.AddWindow(title, 0, wxALIGN_CENTRE|wxALL, 5)
     sizer.AddWindow(wxStaticLine(wizPg, -1), 0, wxEXPAND|wxALL, 5)
     return sizer

class TitledPage(wxWizardPageSimple):
     def __init__(self, parent, title):
         wxWizardPageSimple.__init__(self, parent)
         self.sizer = makePageTitle(self, title)

class MyWizard(wxWizardPageSimple):
     def __init__(self, parent, id):
         wxWizardPageSimple.__init__(self, parent, id)
         page1 = TitledPage(self, "Page 1")
         page2 = TitledPage(self, "Page 2")
         self.wizard = wxWizard(self, page1, page2)
         #self.wizard = wxWizard(self, -1, "Simple Wizard")
         self.Show(true)

app = wxPySimpleApp()
wizard = MyWizard(None, -1)
app.MainLoop()

Darren Blaser wrote:

Then I noticed in the demo code that wxWizard is in the "Base Frame and Dialogs" section of the wxPython demo.py and concluded that it should be used similar to how to wxFrame and wxDialog are used.

It's derived from wxDialog so it's very similar to that.

Here is a working version of your sample:

from wxPython.wx import *
from wxPython.wizard import *

def makePageTitle(wizPg, title):
     sizer = wxBoxSizer(wxVERTICAL)
     wizPg.SetSizer(sizer)
     title = wxStaticText(wizPg, -1, title)
     title.SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD))
     sizer.AddWindow(title, 0, wxALIGN_CENTRE|wxALL, 5)
     sizer.AddWindow(wxStaticLine(wizPg, -1), 0, wxEXPAND|wxALL, 5)
     return sizer

class TitledPage(wxWizardPageSimple):
     def __init__(self, parent, title):
         wxWizardPageSimple.__init__(self, parent)
         self.sizer = makePageTitle(self, title)

app = wxPySimpleApp()
wizard = wxWizard(None, -1, "Simple Wizard")
page1 = TitledPage(wizard, "Page 1")
page2 = TitledPage(wizard, "Page 2")
wxWizardPageSimple_Chain(page1, page2)
wizard.FitToPage(page1)
wizard.RunWizard(page1)
wizard.Destroy()
app.MainLoop()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!