[PyAR2] PyGTK and canceling downloads
srilyk at gmail.com
Wed Jun 11 14:08:45 CEST 2008
On Tue, Jun 10, 2008 at 11:56 PM, Kwadroke of The Wired
<kwadroke at gmail.com> wrote:
> I have written a PyGTK program that downloads files off the internet
> using urllib.urlretrieve. The downloading works fine, but I'm having a
> hard time finding out how to cancel the download as it is running.
> I'm wanting the user to be able to hit cancel on a GUI and stop the
> download. I've searched Google with no success. Any ideas or docs
> someone can point me to?
> I figured out how to interact with gtk to accept button presses, but,
> I can't figure out how to actually stop urlretrieve from pulling down
> the file.
I'm not 100% sure on this - I've done a few things with pyGTK, so I'm
The first thing I would try is just create a keyboard interrupt method
for stopping the download. I *think* it might work similar to what
would happen if you ctrl-c'ed a command line run of it.
Another option is using sockets, and creating a "hidden" window -
basically just don't run the .show()
So, for instance, you would have your main window, whatever you call
that, and then another window that contains the urlretrieve method.
When you click "download" in the main window it would send a signal,
via sockets, to your hidden window. This hidden window would then
start the actual download. If you're using a progress meter it would
report back, via socket, to the main window. Then when you clicked on
"cancel", it would emit the destroy signal to that window, which I
*think* should take care of the urlretrieve. I'm not 100% sure on
Hopefully one of those methods work, or at least points you in the
right direction. If neither of those work, threading will probably be
the way to go, but I have a really dim concept of putting threading
into practice :P
More information about the PyAR2