0

The program I am developing uses threads to deal with long running processes. I want to be able to use Gauge Pulse to show the user that whilst a long running thread is in progress, something is actually taking place. Otherwise visually nothing will happen for quite some time when processing large files & the user might think that the program is doing nothing.

I have placed a guage within the status bar of the program. My problem is this. I am having problems when trying to call gauge pulse, no matter where I place the code it either runs to fast then halts, or runs at the correct speed for a few seconds then halts.

I've tried placing the one line of code below into the thread itself. I have also tried create another thread from within the long running process thread to call the code below. I still get the same sort of problems.

I do not think that I could use wx.CallAfter as this would defeat the point. Pulse needs to be called whilst process is running, not after the fact. Also tried usin time.sleep(2) which is also not good as it slows the process down, which is something I want to avoid. Even when using time.sleep(2) I still had the same problems.

Any help would be massively appreciated!

progress_bar.Pulse()
Clinton Moffat
  • 211
  • 1
  • 2
  • 12

1 Answers1

2

You will need to find someway to send update requests to the main GUI from your thread during the long running process. For example, if you were downloading a very large file using a thread, you would download it in chunks and after each chunk is complete, you would send an update to the GUI.

If you are running something that doesn't really allow chunks, such as creating a large PDF with fop, then I suppose you could use a wx.Timer() that just tells the gauge to pulse every so often. Then when the thread finishes, it would send a message to stop the timer object from updating the gauge.

The former is best for showing progress while the latter works if you just want to show the user that your app is doing something. See also

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Thanks for the reply Mike. The App is just apet project of mine. !st program I've ever attempted to write. It's a file encryption programm for linux, so the long running process would relate to encrypting a file. Larger the file the longer it takes. For small files it's almost instant, but after testing the App with some larger files it became apparent that I need some kind of busy object to let the user knwo that something is happening. Thansk for the links. I had already looked at those. – Clinton Moffat Sep 16 '13 at 13:53
  • Threading seems a quite complicated process just to produce a progress bar. Will take a look at wx.Timer, that might do the job if I just pulse progress bar. – Clinton Moffat Sep 16 '13 at 13:54
  • Yeah...the main reason to use threading is to keep the long running process from blocking the main loop of the GUI thread which will make your app appear frozen. I probably should have linked to my timer tutorial, so here you go: http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/ – Mike Driscoll Sep 16 '13 at 14:12