Python
  Home arrow Python arrow Page 5 - 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? 
Google.com  
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 - Boxing in Controls
    ( Page 5 of 5 )

    Sometimes, it is helpful to group related controls together in a box. This can be done with the wxStaticBox widget very easily:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Static Box', size = ( 300, 300 ) )

          # Create a panel to house everything

          self.panel = wxPanel ( self, -1 )

          # Create the wxStaticBox

          self.box = wxStaticBox ( self.panel, -1, 'Just a Box', size = ( 200, 200 ), pos = ( 5, 5 ) )

          # Create a button

          self.button = wxButton ( self.panel, -1, 'Just a button', pos = ( 25, 25 ) )

          self.Show ( True )

    application = wxPySimpleApp()

    Window()

    application.MainLoop()

    One thing to note here is that the wxStaticBox is not the parent of our wxButton. If you set it as the parent of anything, your application will crash, and that's not a key ingredient for a healthy application.

    If we want to organize controls in a wxStaticBox, we can use wxStaticBoxSizer, which works like wxBoxSizer. This can be hooked up to our wxStaticBox. We'll add another button to our box, though, and since this method is not too friendly with absolute positioning, we'll use wxBoxSizer. We'll create two of these to center everything:

    from wxPython.wx import *

    class Window ( wxFrame ):

       def __init__ ( self ):

          wxFrame.__init__ ( self, None, -1, 'Static Box', size = ( 300, 300 ) )

          # Create a panel to house everything

          self.panel = wxPanel ( self, -1 )

          # Create vertical box sizer

          self.sizer = wxBoxSizer ( wxVERTICAL )

          # Create a horizontal box sizer -- we're going to center everything

          self.horizontal = wxBoxSizer ( wxHORIZONTAL )

          # Create the wxStaticBox

          self.box = wxStaticBox ( self.panel, -1, 'Just a Box' )

          # Create our wxStaticBoxSizer

          self.boxSizer = wxStaticBoxSizer ( self.box, wxHORIZONTAL )

          # Create some buttons

          self.button1 = wxButton ( self.panel, -1, 'Just a button' )

          self.button2 = wxButton ( self.panel, -1, 'Another.' )

          # Add the buttons to the sizer

          self.boxSizer.Add ( self.button1 )

          self.boxSizer.Add ( self.button2 )

          # Configure the box sizers

          self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

          self.horizontal.Add ( self.boxSizer )

          self.horizontal.Add ( ( 0, 0 ), 1, wxEXPAND )

          self.sizer.Add ( ( 0, 0 ), 1, wxEXPAND )

          self.sizer.Add ( self.horizontal, 0, wxALIGN_CENTER )

          self.sizer.Add ( ( 0, 0 ), 1, wxEXPAND )

          # Attach everything

          self.panel.SetSizerAndFit ( self.sizer )

          self.Show ( True )

    application = wxPySimpleApp()

    Window()

    application.MainLoop()

    Conclusion

    This article has shown you that, beyond using simple sizers, there are additional ways to organize the controls in your application, giving the user more control over what he or she sees, which makes him or her appreciate your application more. Organization can be done in a variety of ways, including the ones that this article has outlined: switching panels, using tabs, using a list, using a drop-down list and using a wxStaticBox to organize closely related widgets in your application. Ease-of-use must be considered in any application, and this article has given you some tools to use in the process.



     
     
    >>> 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