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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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


    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.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 1 hosted by Hostway