Python
  Home arrow Python arrow Page 3 - Alternative Frames in wxPython
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Alternative Frames in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2005-08-29


    Table of Contents:
  • Alternative Frames in wxPython
  • wxDialog
  • wxWizard
  • Multiple Document Interface

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Alternative Frames in wxPython - wxWizard
    ( Page 3 of 4 )

    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
     

       

    PYTHON ARTICLES

    - 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
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek