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

Dialogs in wxPython
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 14
    2005-08-01


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

  • 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


    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
     

       

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek