Python
  Home arrow Python arrow Organization Methods Beyond Sizers
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
PYTHON

Organization Methods Beyond Sizers
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2005-08-15

    Table of Contents:
  • Organization Methods Beyond Sizers
  • Using Tabs for Navigation
  • Using a List for Navigation
  • Using a Drop-Down List for Navigation
  • Boxing in Controls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Organization Methods Beyond Sizers
    (Page 1 of 5 )

    A well-designed application will have its widgets organized neatly so that a user can easily access them. To accomplish this, we can use sizers to organize widgets, making them easier to locate and use. However, there are more methods of organization beyond sizers. This article will introduce you to methods of organization that work in conjunction with sizers and such, so you can organize your widgets even more, further benefitting those who use your applications.

    Switching Panels

    A simple way to organize widgets is to give the user the option to change the controls on the screen completely with a single click. This can be done by switching panels when the user presses a button on the current panel. Each panel would have its own widgets. Going this route isn't very hard. All that is necessary is to create several wxPanel subclasses with their own sets of widgets and then a wxFrame. Buttons for navigation would be placed on the panels. When a button is clicked, the panels would be quickly switched.

    Let's take a big leap and put out the whole thing:

    from wxPython.wx import *

    # Create the frame

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Organized Application', size = ( 250, 250 ) )

          # Create an empty variable to house our panel

          self.panel = None

          self.Show ( True )

       # Create the methods that switch the panels

       def goPanel1 ( self, event ):

          self.panel = instance1

          instance1.Show ( True )

          instance2.Show ( False )

          instance3.Show ( False )

       def goPanel2 ( self, event ):

          self.panel = instance2

          instance1.Show ( False )

          instance2.Show ( True )

          instance3.Show ( False )

       def goPanel3 ( self, event ):

          self.panel = instance3

          instance1.Show ( False )

          instance2.Show ( False )

          instance3.Show ( True )

    # Create one panel that uses absolute positioning

    class Panel1 ( wxPanel ):

       def __init__ ( self, parent ):

          wxPanel.__init__ ( self, parent, -1 )

          # Create some navigation buttons

          self.button2 = wxButton ( self, 2, 'Panel 2', pos = ( 5, 5 ) )

          self.button3 = wxButton ( self, 3, 'Panel 3', pos = ( 50, 35 ) )

          # Hook up the navigation events

          EVT_BUTTON ( self, 2, parent.goPanel2 )

          EVT_BUTTON ( self, 3, parent.goPanel3 )

          # Set the size of the panel to match the frame

          self.SetSize ( parent.GetClientSize() )

          # Do not make the panel visible at first

          self.Show ( False )

    # Create one panel that uses a horizontal box sizer

    class Panel2 ( wxPanel ):

       def __init__ ( self, parent ):

          wxPanel.__init__ ( self, parent, -1 )

          # Create sizer

          self.sizer = wxBoxSizer ( wxHORIZONTAL )

          # Create some navigation buttons

          self.button1 = wxButton ( self, 1, 'Panel 1' )

          self.button3 = wxButton ( self, 3, 'Panel 3' )

          # Add the navigation buttons

          self.sizer.Add ( self.button1 )

          self.sizer.Add ( self.button3 )

          # Hook up the navigation events

          EVT_BUTTON ( self, 1, parent.goPanel1 )

          EVT_BUTTON ( self, 3, parent.goPanel3 )

          # Resize the sizer and add it

          self.sizer.SetMinSize ( parent.GetClientSize() )

          self.SetSizerAndFit ( self.sizer )

          # Do not make the panel visible at first

          self.Show ( False )

    # Create one panel that uses a vertical box sizer

    class Panel3 ( wxPanel ):

       def __init__ ( self, parent ):

          wxPanel.__init__ ( self, parent, -1 )

          # Create sizer

          self.sizer = wxBoxSizer ( wxVERTICAL )

          # Create some navigation buttons

          self.button1 = wxButton ( self, 1, 'Panel 1' )

          self.button2 = wxButton ( self, 2, 'Panel 2' )

          # Add the navigation buttons

          self.sizer.Add ( self.button1 )

          self.sizer.Add ( self.button2 )

          # Hook up the navigation events

          EVT_BUTTON ( self, 1, parent.goPanel1 )

          EVT_BUTTON ( self, 2, parent.goPanel2 )

          # Resize the sizer and add it

          self.sizer.SetMinSize ( parent.GetClientSize() )

          self.SetSizerAndFit ( self.sizer )

          # Do not make the panel visible at first

          self.Show ( False )

    application = wxPySimpleApp()

    frame = Window()

    # Create the panels

    instance1 = Panel1 ( frame )

    instance2 = Panel2 ( frame )

    instance3 = Panel3 ( frame )

    # Set the default panel

    frame.goPanel1 ( None )

    application.MainLoop()

    First, we create our main frame class with an empty variable, panel. We then create three different panel classes, and create instances of everything. When the user pushes a button, the corresponding method is called, and the panel is switched. It's nothing new or complex; it's just a bit long. 

    More Python Articles
    More By Peyton McCullough


       · Hello. I wrote this article to explore more techniques of organization. In my...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway