(wxPython) wx.ProgressDialog - how to cancel out of?

T

Terry Carroll

I'm trying to use wx.ProgressBar, and the cancel button is not
responding.

Here is a simple program that exhibits the problem:

#########################################################
import wx
import time

max = 10
app = wx.PySimpleApp()
dlg = wx.ProgressDialog("Progress dialog example",
"variables to be shown here",
maximum = max,
style = wx.PD_CAN_ABORT
| wx.PD_CAN_SKIP
#| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)

keepGoing = True
skip = False
count = 0

while keepGoing and count < max:
count += 1
wx.MilliSleep(1000)
#time.sleep(1)
newtext = "(before) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
(keepGoing, skip) = dlg.Update(count, newtext)
newtext = "(after) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
dlg.Destroy()
#########################################################

The dialog looks right when this runs, but....

What's right: I get a progress bar; it includes "Skip" and "Cancel"
buttons; it shows 10 seconds of progress, and updates once per second
with the variables' values on each iteration.

What's wrong is that I can't get clicking on the "Skip" or "Cancel"
buttons to have any effect. Instead, as soon as the dialog displays,
I get an hourglass, and it doesn't matter what I click on. Here's
what the print statements display, consistently, regardless of what I
try to click or whether I click nothing at all:

I:\python>test1.py
(before) count: 1, keepGoing: True, skip: False
(after) count: 1, keepGoing: True, skip: False
(before) count: 2, keepGoing: True, skip: False
(after) count: 2, keepGoing: True, skip: True
(before) count: 3, keepGoing: True, skip: True
(after) count: 3, keepGoing: True, skip: True
(before) count: 4, keepGoing: True, skip: True
(after) count: 4, keepGoing: True, skip: True
(before) count: 5, keepGoing: True, skip: True
(after) count: 5, keepGoing: True, skip: True
(before) count: 6, keepGoing: True, skip: True
(after) count: 6, keepGoing: True, skip: True
(before) count: 7, keepGoing: True, skip: True
(after) count: 7, keepGoing: True, skip: True
(before) count: 8, keepGoing: True, skip: True
(after) count: 8, keepGoing: True, skip: True
(before) count: 9, keepGoing: True, skip: True
(after) count: 9, keepGoing: True, skip: True
(before) count: 10, keepGoing: True, skip: True
(after) count: 10, keepGoing: True, skip: True

Two oddities here:

1) As I read the docs, the keepGoing variable should be set to True,
unless I click on "Cancel," in which case it should be set to False
(which would end the loop). That doesn't happen. This is really what
I'm most concerned here with.

2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

You can see some variations in the commented-out code that I tried;
they did not help.

Relevant software and releases:

OS: Windows XP Home Edition, Version 2002, SP2
Python: ActivePython 2.5.0.0
wxPython: 2.8.1.1 (msw-unicode)

Any help appreciated.
 
K

kyosohma

I'm trying to use wx.ProgressBar, and the cancel button is not
responding.

Here is a simple program that exhibits the problem:

#########################################################
import wx
import time

max = 10
app = wx.PySimpleApp()
dlg = wx.ProgressDialog("Progress dialog example",
"variables to be shown here",
maximum = max,
style = wx.PD_CAN_ABORT
| wx.PD_CAN_SKIP
#| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)

keepGoing = True
skip = False
count = 0

while keepGoing and count < max:
count += 1
wx.MilliSleep(1000)
#time.sleep(1)
newtext = "(before) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
(keepGoing, skip) = dlg.Update(count, newtext)
newtext = "(after) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
dlg.Destroy()
#########################################################

The dialog looks right when this runs, but....

What's right: I get a progress bar; it includes "Skip" and "Cancel"
buttons; it shows 10 seconds of progress, and updates once per second
with the variables' values on each iteration.

What's wrong is that I can't get clicking on the "Skip" or "Cancel"
buttons to have any effect. Instead, as soon as the dialog displays,
I get an hourglass, and it doesn't matter what I click on. Here's
what the print statements display, consistently, regardless of what I
try to click or whether I click nothing at all:

I:\python>test1.py
(before) count: 1, keepGoing: True, skip: False
(after) count: 1, keepGoing: True, skip: False
(before) count: 2, keepGoing: True, skip: False
(after) count: 2, keepGoing: True, skip: True
(before) count: 3, keepGoing: True, skip: True
(after) count: 3, keepGoing: True, skip: True
(before) count: 4, keepGoing: True, skip: True
(after) count: 4, keepGoing: True, skip: True
(before) count: 5, keepGoing: True, skip: True
(after) count: 5, keepGoing: True, skip: True
(before) count: 6, keepGoing: True, skip: True
(after) count: 6, keepGoing: True, skip: True
(before) count: 7, keepGoing: True, skip: True
(after) count: 7, keepGoing: True, skip: True
(before) count: 8, keepGoing: True, skip: True
(after) count: 8, keepGoing: True, skip: True
(before) count: 9, keepGoing: True, skip: True
(after) count: 9, keepGoing: True, skip: True
(before) count: 10, keepGoing: True, skip: True
(after) count: 10, keepGoing: True, skip: True

Two oddities here:

1) As I read the docs, the keepGoing variable should be set to True,
unless I click on "Cancel," in which case it should be set to False
(which would end the loop). That doesn't happen. This is really what
I'm most concerned here with.

2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

You can see some variations in the commented-out code that I tried;
they did not help.

Relevant software and releases:

OS: Windows XP Home Edition, Version 2002, SP2
Python: ActivePython 2.5.0.0
wxPython: 2.8.1.1 (msw-unicode)

Any help appreciated.

I'm not seeing the error either. The code looks very similar to the
example in the demo. Maybe you can look at it and see the difference?
The only thing I see is that the demo embeds the ProgressDialog into a
Panel object.

You should probably post this to the wxPython mailing group:
http://wxpython.org/maillist.php

Mike
 
7

7stud

I'm trying to use wx.ProgressBar, and the cancel button is not
responding.

Here is a simple program that exhibits the problem:

#########################################################
import wx
import time

max = 10
app = wx.PySimpleApp()
dlg = wx.ProgressDialog("Progress dialog example",
"variables to be shown here",
maximum = max,
style = wx.PD_CAN_ABORT
| wx.PD_CAN_SKIP
#| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)

keepGoing = True
skip = False
count = 0

while keepGoing and count < max:
count += 1
wx.MilliSleep(1000)
#time.sleep(1)
newtext = "(before) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
(keepGoing, skip) = dlg.Update(count, newtext)
newtext = "(after) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
dlg.Destroy()
#########################################################

The dialog looks right when this runs, but....

What's right: I get a progress bar; it includes "Skip" and "Cancel"
buttons; it shows 10 seconds of progress, and updates once per second
with the variables' values on each iteration.

What's wrong is that I can't get clicking on the "Skip" or "Cancel"
buttons to have any effect. Instead, as soon as the dialog displays,
I get an hourglass, and it doesn't matter what I click on. Here's
what the print statements display, consistently, regardless of what I
try to click or whether I click nothing at all:

I:\python>test1.py
(before) count: 1, keepGoing: True, skip: False
(after) count: 1, keepGoing: True, skip: False
(before) count: 2, keepGoing: True, skip: False
(after) count: 2, keepGoing: True, skip: True
(before) count: 3, keepGoing: True, skip: True
(after) count: 3, keepGoing: True, skip: True
(before) count: 4, keepGoing: True, skip: True
(after) count: 4, keepGoing: True, skip: True
(before) count: 5, keepGoing: True, skip: True
(after) count: 5, keepGoing: True, skip: True
(before) count: 6, keepGoing: True, skip: True
(after) count: 6, keepGoing: True, skip: True
(before) count: 7, keepGoing: True, skip: True
(after) count: 7, keepGoing: True, skip: True
(before) count: 8, keepGoing: True, skip: True
(after) count: 8, keepGoing: True, skip: True
(before) count: 9, keepGoing: True, skip: True
(after) count: 9, keepGoing: True, skip: True
(before) count: 10, keepGoing: True, skip: True
(after) count: 10, keepGoing: True, skip: True

Two oddities here:

1) As I read the docs, the keepGoing variable should be set to True,
unless I click on "Cancel," in which case it should be set to False
(which would end the loop). That doesn't happen. This is really what
I'm most concerned here with.

2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

You can see some variations in the commented-out code that I tried;
they did not help.

Relevant software and releases:

OS: Windows XP Home Edition, Version 2002, SP2
Python: ActivePython 2.5.0.0
wxPython: 2.8.1.1 (msw-unicode)

Any help appreciated.

Supposedly a progress dialog does not work well on its own because
events get screwed up when there isn't a main loop. Try this:

import wx

app = wx.PySimpleApp()

win = wx.Frame(None, -1, "Test Progress Dialog")
button = wx.Button(win, -1, "start download")

def on_button_click(evt):
max = 10
dialog = wx.ProgressDialog(
"Loading",
"progress:",
max,
style = wx.PD_CAN_ABORT
|wx.PD_ELAPSED_TIME
|wx.PD_ESTIMATED_TIME
|wx.PD_REMAINING_TIME
)


keep_going = True
skip = False
count = 0
while keep_going and (count < max):
count += 1
wx.MilliSleep(1000)

(keep_going, skip) = dialog.Update(count)
print skip

dialog.Destroy()


button.Bind(wx.EVT_BUTTON, on_button_click)

win.Show()
app.MainLoop()
 
7

7stud

Terry said:
I'm trying to use wx.ProgressBar, and the cancel button is not
responding.

Here is a simple program that exhibits the problem:

#########################################################
import wx
import time

max = 10
app = wx.PySimpleApp()
dlg = wx.ProgressDialog("Progress dialog example",
"variables to be shown here",
maximum = max,
style = wx.PD_CAN_ABORT
| wx.PD_CAN_SKIP
#| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)

keepGoing = True
skip = False
count = 0

while keepGoing and count < max:
count += 1
wx.MilliSleep(1000)
#time.sleep(1)
newtext = "(before) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
(keepGoing, skip) = dlg.Update(count, newtext)
newtext = "(after) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
dlg.Destroy()
#########################################################

The dialog looks right when this runs, but....

What's right: I get a progress bar; it includes "Skip" and "Cancel"
buttons; it shows 10 seconds of progress, and updates once per second
with the variables' values on each iteration.

What's wrong is that I can't get clicking on the "Skip" or "Cancel"
buttons to have any effect. Instead, as soon as the dialog displays,
I get an hourglass, and it doesn't matter what I click on. Here's
what the print statements display, consistently, regardless of what I
try to click or whether I click nothing at all:

I:\python>test1.py
(before) count: 1, keepGoing: True, skip: False
(after) count: 1, keepGoing: True, skip: False
(before) count: 2, keepGoing: True, skip: False
(after) count: 2, keepGoing: True, skip: True
(before) count: 3, keepGoing: True, skip: True
(after) count: 3, keepGoing: True, skip: True
(before) count: 4, keepGoing: True, skip: True
(after) count: 4, keepGoing: True, skip: True
(before) count: 5, keepGoing: True, skip: True
(after) count: 5, keepGoing: True, skip: True
(before) count: 6, keepGoing: True, skip: True
(after) count: 6, keepGoing: True, skip: True
(before) count: 7, keepGoing: True, skip: True
(after) count: 7, keepGoing: True, skip: True
(before) count: 8, keepGoing: True, skip: True
(after) count: 8, keepGoing: True, skip: True
(before) count: 9, keepGoing: True, skip: True
(after) count: 9, keepGoing: True, skip: True
(before) count: 10, keepGoing: True, skip: True
(after) count: 10, keepGoing: True, skip: True

Two oddities here:

1) As I read the docs, the keepGoing variable should be set to True,
unless I click on "Cancel," in which case it should be set to False
(which would end the loop). That doesn't happen. This is really what
I'm most concerned here with.

2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

You can see some variations in the commented-out code that I tried;
they did not help.

Relevant software and releases:

OS: Windows XP Home Edition, Version 2002, SP2
Python: ActivePython 2.5.0.0
wxPython: 2.8.1.1 (msw-unicode)

Any help appreciated.

Or, if you want the progress dialog to start when your app starts--
rather than after a user clicks on a button--you can use a short
timer:

import wx

app = wx.PySimpleApp()

win = wx.Frame(None, -1, "Test Progress Dialog")
timer = wx.Timer(win)
#win.Bind(wx.EVT_TIMER, on_timer_expiry, timer)

def on_timer_expiry(evt):
max = 10
dialog = wx.ProgressDialog(
"Loading",
"progress:",
max,
style = wx.PD_CAN_ABORT
|wx.PD_ELAPSED_TIME
|wx.PD_ESTIMATED_TIME
|wx.PD_REMAINING_TIME
)


keep_going = True
skip = False
count = 0
while keep_going and (count < max):
count += 1
wx.MilliSleep(1000)

(keep_going, skip) = dialog.Update(count)
print skip

dialog.Destroy()
timer.Stop()

win.Bind(wx.EVT_TIMER, on_timer_expiry, timer)
timer.Start(1000)

win.Show()
app.MainLoop()
 
7

7stud

I'm trying to use wx.ProgressBar, and the cancel button is not
responding.

Here is a simple program that exhibits the problem:

#########################################################
import wx
import time

max = 10
app = wx.PySimpleApp()
dlg = wx.ProgressDialog("Progress dialog example",
"variables to be shown here",
maximum = max,
style = wx.PD_CAN_ABORT
| wx.PD_CAN_SKIP
#| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)

keepGoing = True
skip = False
count = 0

while keepGoing and count < max:
count += 1
wx.MilliSleep(1000)
#time.sleep(1)
newtext = "(before) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
(keepGoing, skip) = dlg.Update(count, newtext)
newtext = "(after) count: %s, keepGoing: %s, skip: %s " % \
(count, keepGoing, skip)
print newtext
dlg.Destroy()
#########################################################

The dialog looks right when this runs, but....

What's right: I get a progress bar; it includes "Skip" and "Cancel"
buttons; it shows 10 seconds of progress, and updates once per second
with the variables' values on each iteration.

What's wrong is that I can't get clicking on the "Skip" or "Cancel"
buttons to have any effect. Instead, as soon as the dialog displays,
I get an hourglass, and it doesn't matter what I click on. Here's
what the print statements display, consistently, regardless of what I
try to click or whether I click nothing at all:

I:\python>test1.py
(before) count: 1, keepGoing: True, skip: False
(after) count: 1, keepGoing: True, skip: False
(before) count: 2, keepGoing: True, skip: False
(after) count: 2, keepGoing: True, skip: True
(before) count: 3, keepGoing: True, skip: True
(after) count: 3, keepGoing: True, skip: True
(before) count: 4, keepGoing: True, skip: True
(after) count: 4, keepGoing: True, skip: True
(before) count: 5, keepGoing: True, skip: True
(after) count: 5, keepGoing: True, skip: True
(before) count: 6, keepGoing: True, skip: True
(after) count: 6, keepGoing: True, skip: True
(before) count: 7, keepGoing: True, skip: True
(after) count: 7, keepGoing: True, skip: True
(before) count: 8, keepGoing: True, skip: True
(after) count: 8, keepGoing: True, skip: True
(before) count: 9, keepGoing: True, skip: True
(after) count: 9, keepGoing: True, skip: True
(before) count: 10, keepGoing: True, skip: True
(after) count: 10, keepGoing: True, skip: True

Two oddities here:

1) As I read the docs, the keepGoing variable should be set to True,
unless I click on "Cancel," in which case it should be set to False
(which would end the loop). That doesn't happen. This is really what
I'm most concerned here with.

2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

You can see some variations in the commented-out code that I tried;
they did not help.

Relevant software and releases:

OS: Windows XP Home Edition, Version 2002, SP2
Python: ActivePython 2.5.0.0
wxPython: 2.8.1.1 (msw-unicode)

Any help appreciated.

And here's a version that hides the frame and shows it only after the
progress dialog has finished or been cancelled:

import wx

app = wx.PySimpleApp()

win = wx.Frame(None, -1, "Test Progress Dialog")
timer = wx.Timer(win)
#win.Bind(wx.EVT_TIMER, on_timer_expiry, timer)

def on_timer_expiry(evt):
max = 10
dialog = wx.ProgressDialog(
"Loading",
"progress:",
max,
style = wx.PD_CAN_ABORT
|wx.PD_CAN_SKIP
|wx.PD_ELAPSED_TIME
|wx.PD_ESTIMATED_TIME
|wx.PD_REMAINING_TIME
)


keep_going = True
skip = False
count = 0
while keep_going and (count < max):
count += 1
wx.MilliSleep(1000)

(keep_going, skip) = dialog.Update(count)
print skip

dialog.Destroy()
timer.Stop()

win.Show() #********************



win.Bind(wx.EVT_TIMER, on_timer_expiry, timer)
timer.Start(1000)

#win.Show()
app.MainLoop()
 
7

7stud

Terry said:
2) The variable "skip: set to False on the first iteration, and then
set to True on subsequent iterations? Note that this happens even if
no buttons are selected. This is just a weirdness to me, and not my
main concern, but I thought I'd mention it in case it's relevant.

The docs say:

wx.PD_CAN_SKIP
This flag tells the dialog that it should have a "Skip" button which
the user may press. If this happens, the next call to Update() will
return True in the second component of its return value.

What I'm seeing is: the second item in the tuple returned by Update()
is False if the skip button wasn't clicked and it's True for one
return value when the skip button was clicked, then the value reverts
back to False when Update() returns the next time.
 
T

Terry Carroll

Thanks to both kyosohma and 7stud for the suggestions. I'll try
variations on the code suggested by 7stud, and follow up to the
wx-python list as kyosohma suggested if I need more help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top