Python
  Home arrow Python arrow Organization Methods Beyond Sizers
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? 
PYTHON

Organization Methods Beyond Sizers
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    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:
      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


    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
     

       

    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 3 Hosted by Hostway
    Stay green...Green IT