SunQuest
 
       Python
  Home arrow Python arrow Page 6 - Dialogs in wxPython
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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

Dialogs in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2005-08-01

    Table of Contents:
  • Dialogs in wxPython
  • wxScrolledMessageDialog
  • wxProgressDialog
  • ImageDialog
  • wxDirDialog
  • wxFileDialog

  • 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

    Dialogs in wxPython - wxFileDialog


    (Page 6 of 6 )

    The last dialog we are going to examine in this article is the wxFileDialog. It allows the user to save or open a file. Setting up a basic dialog is pretty simple. Let's set up one that allows the user to select a file to open:

    from wxPython.wx import *

    application = wxPySimpleApp()

    # Create an open file dialog

    dialog = wxFileDialog ( None, style = wxOPEN )

    # Show the dialog and get user input

    if dialog.ShowModal() == wxID_OK:

       print 'Selected:', dialog.GetPath()

    # The user did not select anything

    else:

       print 'Nothing was selected.'

    # Destroy the dialog

    dialog.Destroy()

    Let's make our dialog more complicated. First, let's create some filters so the user can select a file type from a list. Second, let's display a message on the dialog. Third, let's allow multiple files to be selected:

    from wxPython.wx import *

    application = wxPySimpleApp()

    # Create a list of filters

    # This should be fairly simple to follow, so no explanation is necessary

    filters = 'All files (*.*)|*.*|Text files (*.txt)|*.txt'

    dialog = wxFileDialog ( None, message = 'Open something....', wildcard = filters, style = wxOPEN | wxMULTIPLE )

    if dialog.ShowModal() == wxID_OK:

       # We'll have to make room for multiple files here

       selected = dialog.GetPaths()

       for selection in selected:

          print 'Selected:', selection

    else:

       print 'Nothing was selected.'

    dialog.Destroy()

    Now let's create a dialog that allows us to save files. This is done by simply changing the style wxOPEN to wxSAVE:

    from wxPython.wx import *

    application = wxPySimpleApp()

    # Create a save file dialog

    dialog = wxFileDialog ( None, style = wxSAVE )

    # Show the dialog and get user input

    if dialog.ShowModal() == wxID_OK:

       print 'Selected:', dialog.GetPath()

    # The user did not select anything

    else:

       print 'Nothing was selected.'

    # Destroy the dialog

    dialog.Destroy()

    A lot of applications present the user with a confirmation dialog if he or she selects a file that already exists. This can be accomplished in your own application by using wxOVERWRITE_PROMPT:

    from wxPython.wx import *

    application = wxPySimpleApp()

    # Create a save file dialog

    dialog = wxFileDialog ( None, style = wxSAVE | wxOVERWRITE_PROMPT )

    # Show the dialog and get user input

    if dialog.ShowModal() == wxID_OK:

       print 'Selected:', dialog.GetPath()

    # The user did not select anything

    else:

       print 'Nothing was selected.'

    # Destroy the dialog

    dialog.Destroy()

    Conclusion

    We've looked at a variety of dialogs that wxPython provides. Dialogs allow programmers to implement common features in their applications without doing much work at all. Instead of working with complex controls to do a simple task, a programmer can call a few methods and have it all done for him or her. All dialogs are simple to create and manage, as this article has thrown through examples. They are worth using in many wxPython applications – both large and small.


    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.

       · goog topic, but it doesn't work well :Traceback (most recent call last): File...
       · We returned to the original article and it seemed that a line of code was missed...
       · Vous avez écrit :dialog = wxScrolledMessageDialog ( self, text, 'Fairy Tale'...
     

       

    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 5 hosted by Hostway