Marcelo Fern?ndez wrote:
Dave Angel wrote:
I'm writing a wxPython application that displays jpeg images in two > frames. Currently, it's a single image at a time, but I will be doing > multiple ones. <snip>...
self._img = wx.Image(self.fname, wx.BITMAP_TYPE_ANY) <snip>...Just to add a comment... If the application (and its use case) allows it, you could make an "image cache" in a background thread/process while the user is watching some image in foreground. This is very common in image viewers, which preloads the next (one or two) images in the viewing list.
Regards
Marcelo
-- Marcelo F. Fernández
Thanks to all of you for your suggestions. It helps to put it all in perspective.
Since the real problem is one of latency, the image cache would seem to be the most promising. I'm already planning to cache the thumbnails I'll be creating for a scrolling window. But at 30mb per, I can't cache too many of the main Image. So the preload makes lots of sense. Some questions, though, please.
If I did the speculative image load in the GUI thread, I'd be blocking events while it's loading. Is there any way to get periodic control during the load (Image constructor) so I can keep the GUI alive, like you'd do with a long-running calculation? I believe in wxPython, this would involve calls to wx.App.Yield().
If I do it in a separate thread (as you suggest), do you know that calls to Image constructor are safe? I understand that some things are unsafe outside of the GUI thread, and that can depend on the platform, but I don't see any definitive list. And similarly to the Yield question, it'd be very nice to get control periodically, so that if it turns out that this is the wrong image, I can abort the process and get busy on the right one. I know I could accomplish that by killing the thread (by calling the system function directly), but won't because I'd undoubtedly risk leaking some system resources. As far as I can tell, I can't even suspend the thread through well-behaved Python code.
I could also do some experiments with preprocessing the images to have a second set of low-res ones. I'll have to see how bad it'd look to display a low-res image (magnified during the Image.Scale call) turn later into the real one. I could process the real image in an idle event, so that if they go rapidly through the list, the real ones don't get loaded until they slow down.
Does wxPython provide any way to get the thumbnail image out of a jpeg file?