473,372 Members | 1,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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

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.
Sep 15 '07 #1
7 6754
On Sep 15, 12:57 am, Terry Carroll <carr...@nospam-tjc.comwrote:
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

Sep 15 '07 #2
On Sep 14, 11:57 pm, Terry Carroll <carr...@nospam-tjc.comwrote:
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()

Sep 15 '07 #3

Terry Carroll wrote:
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()

Sep 15 '07 #4
On Sep 14, 11:57 pm, Terry Carroll <carr...@nospam-tjc.comwrote:
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()

Sep 15 '07 #5
Terry Carroll wrote:
>
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.

Sep 15 '07 #6
On Sep 15, 5:25 pm, 7stud <bbxx789_0...@yahoo.comwrote:
dialog.Destroy()
timer.Stop()
win.Show() #********************
You can also change that last line to win.Destroy(), and then the user
will never see the frame.

Sep 16 '07 #7
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.
Sep 18 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: plumpy321 | last post by:
Hi, I took an example from wxPython with the IE web browser and created a refresh button to automatically refresh a web page in 5 second intervals. But I notice that the memory utilization in...
5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
2
by: ccahoon | last post by:
In wxPython, I want to be able to start downloading a file and have the window doing such remain interactive, so that the user can cancel downloading the next file. Also, if there is a way to...
7
by: John Salerno | last post by:
I was reading in the wxPython wiki that most of the time you don't have to include the id parameter at all, and you can just use keyword arguments for other parameters. But I'm having trouble...
8
by: Patrick Smith | last post by:
Hi, I'm hoping someone here will be able to help as I've been struggling with this problem for a few days now. I'm working on an application that is creating a ProgressDialog, and then creating...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
5
by: Benjamin | last post by:
I'm writing a search engine in Python with wxPython as the GUI. I have the actual searching preformed on a different thread from Gui thread. It sends it's results through a Queue to the results...
4
by: Jimmy | last post by:
Hi, wxPython is cool and easy to use, But I ran into a problem recently when I try to write a GUI. The thing is I want to periodically update the content of StatixText object, so after create...
6
by: Iain King | last post by:
Hi. I have a modal dialog whcih has a "Browse..." button which pops up a file selector. This all works fine, but the first thing the user has to do when they open the dialog is select a file, so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.