wxPython: images from URLs

Anand Pillai pythonguy at Hotpop.com
Thu Jan 29 02:37:15 EST 2004


This is the straight forward way to do this in wxPython
but somehow it always pops up that ugly error window.
I remember trying many options to do this purely using
wxPython (wxWindows), but I failed. 

If you use PIL in your program you can conver the
wx Image instance to a PIL image of type BMP and then
display it by reconverting it back to the wxImage
instance. PyWiew has methods to do this. The source code
is available somewhere in my Python page at
http://members.lycos.co.uk/anandpillai . I no longer
maintain that program, but the latest source code should
be available there.

Regards

-Anand

Jonathan Daugherty <cygnus at cprogrammer.org> wrote in message news:<mailman.931.1075308709.12720.python-list at python.org>...
> # self._imgstream = urllib2.urlopen(url).read()
> # stream=cStringIO.StringIO(self._imgstream)
> # 
> # try:
> #    img=wxImageFromStream(stream)
> # except:
> #    pass
> 
> I have tried this and it appears to work, but once I have
> the image (from wxImageFromStream), I use it as follows:
> 
> try:
>     bm = wxBitmap(img)
>     self.bitmap.setBitmap(bm)
> except Exception, e:
>     print e
> 
> And the exception (raised by wxBitmap(img)) is:
> 
>   String or Unicode type required
> 
> (The exception is a TypeError exception.)
> 
> Any ideas?  No exceptions are raised by the block that
> creates the image from the data stream.  The image is
> a JPG image, and I pass wxBITMAP_TYPE_JPEG to
> wxImageFromStream.  I have also tried omitting it as
> well.



More information about the Python-list mailing list