Problems with wx.ProgressDialog sample...

I am working my way through the wxPython In Action book and have run into problems with the wx.ProgressDialog sample code (listing 9.5 in the book). The code is below:

import wx

if (‘main’ == name):
app = wx.PySimpleApp()
progress_max = 100

dialog = wx.ProgressDialog('A progress box',
                           'Time Remaining:',
                           progress_max,
                           style=wx.PD_CAN_ABORT
                               > wx.PD_ELAPSED_TIME
                               > wx.PD_REMAINING_TIME)

keep_going = True
count = 0
while (keep_going and count < progress_max):
    count = count + 1
    wx.Sleep(1)
    (keep_going, skip) = dialog.Update(count)
dialog.Destroy()

The first problem I ran into was setting a breakpoint on just about any line after the dialog = wx.ProgressDialog(…) line causes Python to abend. I am using Komodo IDE 4.0.3, but the same thing happened to me under PythonWin. Secondly, the dialog will not cancel. I figured out that dialog.Update(count) returns a tuple and not a single value as shown in the books example code, but the dialog still will not cancel.

I took a look at the demo code for the progress dialog and it’s a bit more involved than this code is - but the demo code does seem to react correctly when the cancel button is pressed. I’m not really looking for a “code it like the demo does” type of an answer, what I am looking for is a “Here’s why the demo code works and the book code doesn’t.” type of an answer… My guess at this point is that my demo code doesn’t have a parent window for the dialog, while the demo code does specify a parent window, but I am not sure of this answer at all.

Thanks,

-John Clark

Hi John,

This might be of help:
http://www.wxpython.org/bookerrata.php

Saturday, May 5, 2007, 10:02:22 PM, you wrote:

···

I am working my way through the wxPython In Action book and have run into
problems with the wx.ProgressDialog sample code (listing 9.5 in the book).
The code is below:

import wx

if ('__main__' == __name__):
    app = wx.PySimpleApp()
    progress_max = 100
    
    dialog = wx.ProgressDialog('A progress box',
                               'Time Remaining:',
                               progress_max,
                               style=wx.PD_CAN_ABORT
                                   > wx.PD_ELAPSED_TIME
                                   > wx.PD_REMAINING_TIME)
    
    keep_going = True
    count = 0
    while (keep_going and count < progress_max):
        count = count + 1
        wx.Sleep(1)
        (keep_going, skip) = dialog.Update(count)
    dialog.Destroy()

The first problem I ran into was setting a breakpoint on just about any line
after the dialog = wx.ProgressDialog(...) line causes Python to abend. I am
using Komodo IDE 4.0.3, but the same thing happened to me under PythonWin.
Secondly, the dialog will not cancel. I figured out that
dialog.Update(count) returns a tuple and not a single value as shown in the
books example code, but the dialog still will not cancel.

I took a look at the demo code for the progress dialog and it's a bit more
involved than this code is - but the demo code does seem to react correctly
when the cancel button is pressed. I'm not really looking for a "code it
like the demo does" type of an answer, what I am looking for is a "Here's
why the demo code works and the book code doesn't." type of an answer... My
guess at this point is that my demo code doesn't have a parent window for
the dialog, while the demo code does specify a parent window, but I am not
sure of this answer at all.

Thanks,
-John Clark

Phillip Stevens <mailto:pmstevens@verizon.net> scribbled on Saturday, May
05, 2007 10:08 PM:

Hi John,

This might be of help:
http://www.wxpython.org/bookerrata.php

Thanks for the pointer - however, there is still an error in this code, as
wx.ProgressDialog.Update(...) returns a tuple and the code as shown on the
errata page still won't cancel out. - Does anyone know how to report this
so that it can be changed?

I'm still looking for an explanation for why the parent frame helps the
cancel processing, as (without the parent frame) the button press is
obviously being processed as the button changes state and yet the update
call seems to not report the cancel event. What message(s) are they that
the parent frame is processing that makes this work?

Also - the changes here seem to help with the breakpoint / abend issue - but
I am curious if anyone can explain why the book code was abending when
setting breakpoints after dialog creation?

Thanks,
-John Clark