views:

42

answers:

2

I am writing a chatroom client in wxPython in which there are 3 wx.HtmlWindows for each chatroom on a notebook page: one for the messages, one for the title of the room, and one for the topic of the room (two similar things)

The program works fine, loads images when images are in the message's code, etc. But when it suddenly has to load a bunch of images at once, or an animated image that takes longer to load, or a combination (the images are generally just 50x50 - 100x100) it can be a problem because sometimes it will lock up and then the program won't respond because it's taking too long. The question posing is, how would I stop the locking up from happening? I don't know how to go about binding wx.HtmlWindow's image loading to have the images load dynamically in a worker thread instead of the program having to wait for the images to load to continue.

If you need a sample code of what I am writing let me know.

EDIT: I'm stil having trouble figuring out an answer for this.. I have gotten literally no where on this project because of this. my application needs to be able to dynamically load messages/images without it locking up and I simply do not know how to force any image loading into a different thread so that the frames of the images and the messages are displayed, while the loader thread loads the images and updates the empty frames when done. This all needs to happen in an HtmlWindow. I want it to act like a real web browser when it comes to loading images (you see the frames and the images slowly appear)

A: 

Long running processes will block the main loop of your application, which causes it to "lock up". You'll want to do the downloading in a separate thread and then update your UI when that's finished. Here are a couple links on using threads (and other methods) that might help you:

http://wiki.wxpython.org/LongRunningTasks

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

Mike Driscoll
that doesn't really help with his issue though as he's not sure where to bind for the images being loaded.
Steven Sproat
I already know how to use threads I just wasn't sure how to get the window to do the image loading in a different thread instead. Thanks though
Blazer
I was thinking that you could download the images with the thread and then use PubSub or PostEvent to tell your application to display it.
Mike Driscoll
A: 

In addition to Mike's answer (what he says applies), you can hook into an image being loaded by overriding the OnOpeningURL method from HTMLWindow and specifying the type of wx.html.HTML_URL_IMAGE.

See: these wx docs for an explanation.

Steven Sproat
Thanks! Do you happen to know how to make the wxHtmlWindow add a blank frame in place of images while it loads the page and then update the page when it's done loading? This way the messages wouldn't get mixed up from the time they are actually received (a message without an image that was actually received after a message with an image might appear first, messing up the order, for example)
Blazer
Hmm, I'm not sure, sorry. I haven't used wx.HtmlWindow
Steven Sproat