Python
  Home arrow Python arrow Page 3 - 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 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    Dialogs in wxPython - wxProgressDialog


    (Page 3 of 6 )

    Any time you are required to do large amounts of work in your application, it is a good idea to let the user know your application's progress in the process. A wxProgressDialog will do the job nicely. Let's emulate an application that takes a long time:

    import time

    for x in xrange ( 25 ):

       # Spend some time doing nothing

       time.sleep ( 2 )

    When running it, I have no idea how much progress has been made. This is easily fixed. Let's make a wxProgressDialog and update it after each cycle in the loop:

    from wxPython.wx import *

    application = wxPySimpleApp()

    # Create a dialog to show progress

    dialog = wxProgressDialog ( 'Progress', 'Doing nothing in a large amount of time.', maximum = 25 )

    for x in xrange ( 25 ):

       # Spend some time doing nothing

       # We'll use wxSleep rather than time.sleep

       wxSleep ( 2 )

       # Update our progress and change the message

       dialog.Update ( x + 1, 'On step ' + str ( x + 1 ) + '.' )

    Our dialog makes things a lot better. I'm sure you're wondering what the maximum argument is for. Basically, it sets the maximum number that can be set in Update. Once that maximum is hit, the dialog's progress bar will be complete. It's very simple. Because we call the sleep method 25 times, I made maximum match that. You can set maximum to whatever you wish. The default is 100.

    Notice that as soon as our task is complete, the dialog is hidden from us. This is because of the wxPD_AUTO_HIDE style, which is applied by default. It hides the dialog once maximum is reached. We can change this by manually setting the style:

    from wxPython.wx import *

    application = wxPySimpleApp()

    dialog = wxProgressDialog ( 'Progress', 'Doing nothing in a large amount of time.', maximum = 25, style = wxPD_APP_MODAL )

    for x in xrange ( 25 ):

       wxSleep ( 2 )

       dialog.Update ( x + 1, 'On step ' + str ( x + 1 ) + '.' )

    If we want to improve our progress dialog even more, we can do so by applying the wxPD_ELAPSED_TIME style, which shows the total amount of time that has gone by since the start of the process:

    from wxPython.wx import *

    application = wxPySimpleApp()

    dialog = wxProgressDialog ( 'Progress', 'Doing nothing in a large amount of time.', maximum = 5, style = wxPD_APP_MODAL | wxPD_ELAPSED_TIME)

    for x in xrange ( 5 ):

       wxSleep ( 2 )

       dialog.Update ( x + 1, 'On step ' + str ( x + 1 ) + '.' )

    To accompany the wxPD_ELAPSED_TIME style, we can apply the wxPD_ESTIMATED_TIME style. It shows the total time that wxPython thinks the process will take:

    from wxPython.wx import *

    application = wxPySimpleApp()

    dialog = wxProgressDialog ( 'Progress', 'Doing nothing in a large amount of time.', maximum = 5, style = wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME )

    for x in xrange ( 5 ):

       wxSleep ( 2 )

       dialog.Update ( x + 1, 'On step ' + str ( x + 1 ) + '.' )

    Alternatively, we can pass wxPD_REMAINING_TIME. It displays the time wxPython believes is left until the process is finished:

    from wxPython.wx import *

    application = wxPySimpleApp()

    dialog = wxProgressDialog ( 'Progress', 'Doing nothing in a large amount of time.', maximum = 5, style = wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME )

    for x in xrange ( 5 ):

       wxSleep ( 2 )

       dialog.Update ( x + 1, 'On step ' + str ( x + 1 ) + '.' )

    More Python Articles
    More By Peyton McCullough


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