ProgressDialog and Pulse

387 views
Skip to first unread message

Stefanie Lück

unread,
Jun 11, 2009, 5:00:51 AM6/11/09
to wxPython-users
Hi everybody!

I want to have a wx.ProgressDialog in my application which just Pulse
all the time and from function to function to Update a message text.

How I can do this without to think for timings? The wx.Gauge should
just move and show that it's doing something. Is this possible?

Thanks in advance
Stefanie

Andrea Gavana

unread,
Jun 11, 2009, 5:21:10 AM6/11/09
to wxPytho...@googlegroups.com
Hi Stefanie,

Yes, if I understand your question correctly. Just do this:

dlg = wx.ProgressDialog(title, message, parent,
style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME)

dlg.Pulse("My first message")
wx.SafeYield()

... a while later

dlg.Pulse("My second message")
wx.SafeYield()

... a while later

dlg.Pulse("My third message")
wx.SafeYield()


HTH.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

Donn Ingle

unread,
Jun 11, 2009, 5:25:59 AM6/11/09
to wxpytho...@lists.wxwidgets.org
Stefanie Lück wrote:
> How I can do this without to think for timings? The wx.Gauge should
> just move and show that it's doing something. Is this possible?
Get the wx demo and look at the sample code for the Gauge (core controls) --
it's really simple and should not cause you trouble. Failing that, look at
the sample code for the AnimateCtrl (using images) which uses animated gifs.
Perhaps that will be better; make a kind of Ajax busy animation. Then
there's the Throbber (under more controls).

\d


Stefanie Lück

unread,
Jun 11, 2009, 6:24:47 AM6/11/09
to wxPytho...@googlegroups.com
Thanks!

This I tried but the progress bar dosen't Pulse. Only when it's change to
the next

dlg.Pulse("My first message")
wx.SafeYield()

but this may take time and the user might think that the program crashes.
Is there a possibility to keep it pulsing without a timer?

If not I'll switch to AnimateCtrl as Donn recommended. I tried several
things with the ProgressDialog but it either crashes or don't Pulse when I
want.

Thanks!
Stefanie

Andrea Gavana

unread,
Jun 11, 2009, 6:35:35 AM6/11/09
to wxPytho...@googlegroups.com
Hi Stefanie,

On Thu, Jun 11, 2009 at 11:24 AM, Stefanie Lück wrote:
>
> Thanks!
>
> This I tried but the progress bar dosen't Pulse. Only when it's change to
> the next
>
> dlg.Pulse("My first message")
> wx.SafeYield()
>
> but this may take time and the user might think that the program crashes.

This is because you are doing some long running task in the GUI
thread. If you can separate this task and put it in a separate thread
(which does *not* call any GUI-related code), then you can make your
progress dialog pulse as you wish. For example:

dlg = wx.ProgressDialog(title, message, parent,
style=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME)

thread = MyLongRunningTask_Thread()

counter = 1
while thread.isAlive():
wx.MilliSleep(300)
dlg.Pulse("Doing computation %d"%counter)
counter += 1

There is a simple example of this usage in a little tool I posted to
the list a week ago, called EventsInStyle, here:

http://xoomer.virgilio.it/infinity77/Zipped/EventsInStyle.py

(or http://xoomer.alice.it/infinity77/Zipped/EventsInStyle.py)

Which basically connect to the internet, read the wxWidgets docs,
formats them and in the meanwhile the progressdialog pulses
independently.

You may also take a look at these Wiki pages:

http://wiki.wxpython.org/LongRunningTasks
http://wiki.wxpython.org/Non-Blocking%20Gui

Reply all
Reply to author
Forward
0 new messages