Home arrow Python arrow Page 3 - Alternative Frames in wxPython

wxWizard - Python

I'm sure you know all about wxPython's primary frame, wxFrame. It is the basis for most of your windows and will most likely continue to be. Of course, though, wxPython offers other things to put controls on. I'm sure you're getting bored of attaching your controls to slight variations of the same exact thing. In this article, we'll explore other frames offered by wxPython, examining what they are for, how they are used and how to change their appearance.

TABLE OF CONTENTS:
  1. Alternative Frames in wxPython
  2. wxDialog
  3. wxWizard
  4. Multiple Document Interface
By: Peyton McCullough
Rating: starstarstarstarstar / 9
August 29, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

We've all seen wizards in all sorts of applications. They exist to make tasks easy. They are found in installers, graphics programs and even wxPython. Using the wizard module, we can create wizards to use in our applications, making them even more user-friendly. Best of all, these wizards are pretty easy to create. Here's a very simple dummy wizard:

from wxPython.wx import *

# The wizard-related classes are here:

from wxPython.wizard import *

application = wxPySimpleApp()

# Create a wizard with the title "A Wizard"

wizard = wxWizard ( None, -1, 'A Wizard' )

# Create three pages for the wizard

# This is very simple

wizardPage1 = wxWizardPageSimple ( wizard )

wizardPage2 = wxWizardPageSimple ( wizard )

wizardPage3 = wxWizardPageSimple ( wizard )

# Add a label to each page

label1 = wxStaticText ( wizardPage1, -1, 'This is the first page.' )

label2 = wxStaticText ( wizardPage2, -1, 'This is the second page.' )

label3 = wxStaticText ( wizardPage3, -1, 'This is the third and final page.' )

# Link the pages together

# 1 to 2 and 2 to 3

wxWizardPageSimple_Chain ( wizardPage1, wizardPage2 )

wxWizardPageSimple_Chain ( wizardPage2, wizardPage3 )

# Run the wizard and display a message if it was completed successfully

# Otherwise, yell at the user

if wizard.RunWizard ( wizardPage1 ):

   dialog = wxMessageDialog ( None, 'Wizard finished!', 'Finished', style = wxOK )

   dialog.ShowModal()

   dialog.Destroy()

else:

   dialog = wxMessageDialog ( None, 'Grr!', 'Not Finished', style = wxOK )

   dialog.ShowModal()

   dialog.Destroy()

# Destroy the wizard

wizard.Destroy()

There are more advanced and flexible methods for creating wizards, too. Let's suppose we are creating an installer with two installation modes: minimal and full. Based on the user's selection, we want to go to different sections of the wizard. This is completely possible, but it is done a little differently from the way we did it above:

from wxPython.wx import *

# Import the wizard-related data

from wxPython.wizard import *

# Create the wizard page that allows the use to select an installation type

# We wills subclass wxPyWizardPage here

class TypePage ( wxPyWizardPage ):

   def __init__ ( self, parent ):

      # Call __init__

      wxPyWizardPage.__init__ ( self, parent )

      # Specify None for the next and previous pages

      self.next = None

      self.previous = None

      # Add a wxRadioBox that displays the two installation options

      self.box = wxRadioBox ( self, -1, 'Instalation Method', choices = [ 'Minimal', 'Full' ] )

   def GetNext ( self ):

      # Return a value based on the radio buttons elected

      if self.box.GetSelection() == 0:

         return minimal

      else:

         return full

   def GetPrev ( self ):

      return self.previous

application = wxPySimpleApp()

# Create the wizard

wizard = wxWizard ( None, -1, 'Installer' )

# Create the installation type page

type = TypePage ( wizard )

# Create a page for the minimal mode

minimal = wxWizardPageSimple ( wizard )

minimalText = wxStaticText ( minimal, -1, 'Poof. Your application has been installed minimally.' )

# Create a page for the full mode

full = wxWizardPageSimple ( wizard )

fullText = wxStaticText ( full, -1, 'Bang. Your application has been fully installed.' )

# Create an additional page

register = wxWizardPageSimple ( wizard )

registerText = wxStaticText ( register, -1, 'Please register your product online,nor we will keep nagging you.' )

# Link the pages that have fixed links ( minimal and full )

minimal.SetNext ( register )

full.SetNext ( register )

# Run the wizard

wizard.RunWizard ( type )

# Destroy the wizard

wizard.Destroy()

If you feel inclined to do so, you can easily add an image to your wizard by creating it like this, where “wizard.PNG” is the name of the image:

wizard = wxWizard ( None, -1, 'My Wizard', wxBitmap ( 'wizard.PNG' )



 
 
>>> More Python Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: