Using `wx.Image` when I have the file and not its name

Hi,

I want to create a `wx.Image` from a file. Problem is, I have the
file, and not the file's name. (The reason for that is that I'm in
py2exe and all the files are in a big zipfile, so I `pkg_resources`
can't get their filename, but only as a stream.)

Is this possible at all?

Thanks,
Ram.

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi,

···

On Thu, Apr 29, 2010 at 12:53 PM, cool-RR <ram.rachum@gmail.com> wrote:

Hi,

I want to create a `wx.Image` from a file. Problem is, I have the
file, and not the file's name. (The reason for that is that I'm in
py2exe and all the files are in a big zipfile, so I `pkg_resources`
can't get their filename, but only as a stream.)

Is this possible at all?

Yes, did you try to look for the answer?

http://lmgtfy.com/?q=wx.Image+stream
http://www.wxpython.org/docs/api/wx.Image-class.html

Cody

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

I went over it a few times and I don’t see an obvious answer. Is it LoadStream? I don’t understand how that works, given it takes a self. What self am I supposed to put into it.

Ram.

···

On Thu, Apr 29, 2010 at 8:03 PM, Cody Precord codyprecord@gmail.com wrote:

Hi,

On Thu, Apr 29, 2010 at 12:53 PM, cool-RR ram.rachum@gmail.com wrote:

Hi,

I want to create a wx.Image from a file. Problem is, I have the

file, and not the file’s name. (The reason for that is that I’m in

py2exe and all the files are in a big zipfile, so I pkg_resources

can’t get their filename, but only as a stream.)

Is this possible at all?

Yes, did you try to look for the answer?

http://lmgtfy.com/?q=wx.Image+stream

http://www.wxpython.org/docs/api/wx.Image-class.html

Cody

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I found wx.ImageFromStream now, thanks.

Ram.

···

On Thu, Apr 29, 2010 at 8:12 PM, cool-RR cool-rr@cool-rr.com wrote:

On Thu, Apr 29, 2010 at 8:03 PM, Cody Precord codyprecord@gmail.com wrote:

Hi,

On Thu, Apr 29, 2010 at 12:53 PM, cool-RR ram.rachum@gmail.com wrote:

Hi,

I want to create a wx.Image from a file. Problem is, I have the

file, and not the file’s name. (The reason for that is that I’m in

py2exe and all the files are in a big zipfile, so I pkg_resources

can’t get their filename, but only as a stream.)

Is this possible at all?

Yes, did you try to look for the answer?

http://lmgtfy.com/?q=wx.Image+stream

http://www.wxpython.org/docs/api/wx.Image-class.html

Cody

I went over it a few times and I don’t see an obvious answer. Is it LoadStream? I don’t understand how that works, given it takes a self. What self am I supposed to put into it.

Ram.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Cody,

You were dismissive enough in your first message. But the things you’re saying are really not obvious, and one of them is wrong: There is such a thing as a staticmethod, that doesn’t take a self, which would actually have been a reasonable choice for LoadStream.

The fact that I’m supposed to create an empty image is not obvious; I did not

even know it was possible with the standard constructor.

Anyway, now I’m okay with wx.ImageFromStream, thanks.

Ram.

···

On Thu, Apr 29, 2010 at 8:27 PM, Cody Precord codyprecord@gmail.com wrote:

Hi,

On Thu, Apr 29, 2010 at 1:12 PM, cool-RR cool-rr@cool-rr.com wrote:

On Thu, Apr 29, 2010 at 8:03 PM, Cody Precord codyprecord@gmail.com wrote:

I went over it a few times and I don’t see an obvious answer. Is it

LoadStream? I don’t understand how that works, given it takes a self.

What self am I supposed to put into it.

LoadStream(self, stream, type, index)

All Python objects take an implict self argument.

myImage = wx.Image(…)

myImage.LoadStream(file_like_obj, wx.BITMAP_TYPE_FOO)

myImage is the self parameter.

FYI: there is a convinience function called wx.ImageFromStream that

you can use to.

Cody


Sincerely,
Ram Rachum

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Now I have a question in a similar vein: How do I make an IconBundle from a stream?

Ram.

···

On Thu, Apr 29, 2010 at 8:40 PM, cool-RR cool-rr@cool-rr.com wrote:

On Thu, Apr 29, 2010 at 8:27 PM, Cody Precord codyprecord@gmail.com wrote:

Hi,

On Thu, Apr 29, 2010 at 1:12 PM, cool-RR cool-rr@cool-rr.com wrote:

On Thu, Apr 29, 2010 at 8:03 PM, Cody Precord codyprecord@gmail.com wrote:

I went over it a few times and I don’t see an obvious answer. Is it

LoadStream? I don’t understand how that works, given it takes a self.

What self am I supposed to put into it.

LoadStream(self, stream, type, index)

All Python objects take an implict self argument.

myImage = wx.Image(…)

myImage.LoadStream(file_like_obj, wx.BITMAP_TYPE_FOO)

myImage is the self parameter.

FYI: there is a convinience function called wx.ImageFromStream that

you can use to.

Cody

Cody,

You were dismissive enough in your first message. But the things you’re saying are really not obvious, and one of them is wrong: There is such a thing as a staticmethod, that doesn’t take a self, which would actually have been a reasonable choice for LoadStream.

The fact that I’m supposed to create an empty image is not obvious; I did not

even know it was possible with the standard constructor.

Anyway, now I’m okay with wx.ImageFromStream, thanks.

Ram.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Slightly better than Cody's suggestion:

1. Run the demo
2. Type "image" in the search control in the lower left corner
3. Click on the ImageFromStream sample revealed in the tree
4. Click on the Demo Code tab in the notebook
5. Read the source code
6. Be Happy :slight_smile:

···

On 4/29/10 11:12 AM, cool-RR wrote:

On Thu, Apr 29, 2010 at 8:03 PM, Cody Precord <codyprecord@gmail.com > <mailto:codyprecord@gmail.com>> wrote:

    Hi,

    On Thu, Apr 29, 2010 at 12:53 PM, cool-RR <ram.rachum@gmail.com > <mailto:ram.rachum@gmail.com>> wrote:
     > Hi,
     >
     > I want to create a `wx.Image` from a file. Problem is, I have the
     > file, and not the file's name. (The reason for that is that I'm in
     > py2exe and all the files are in a big zipfile, so I `pkg_resources`
     > can't get their filename, but only as a stream.)
     >
     > Is this possible at all?

    Yes, did you try to look for the answer?

    http://lmgtfy.com/?q=wx.Image+stream
    wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

    Cody

I went over it a few times and I don't see an obvious answer. Is it
`LoadStream`? I don't understand how that works, given it takes a
`self`. What `self` am I supposed to put into it.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

It is not supported.

···

On 4/29/10 11:46 AM, cool-RR wrote:

Now I have a question in a similar vein: How do I make an `IconBundle`
from a stream?

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Then what would be the best way to solve my problem? I have an ico file with plenty of differently-sized icons in it. I can’t load it as a filename, I can load it as a stream. I want that icon with all the different sizes to be used by my program. What do I do?

Ram

···

On Thu, Apr 29, 2010 at 9:00 PM, Robin Dunn robin@alldunn.com wrote:

On 4/29/10 11:46 AM, cool-RR wrote:

Now I have a question in a similar vein: How do I make an IconBundle

from a stream?

It is not supported.

Robin Dunn

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Either save the stream to a temporary file and load it from there, or split it into separate images that are loaded individually (you can then load them into an IconBundle at runtime if desired, or just use them individually as needed) or you can use img2py to put your images in Python code instead and just import them like any other Python module.

···

On 4/29/10 12:06 PM, cool-RR wrote:

On Thu, Apr 29, 2010 at 9:00 PM, Robin Dunn <robin@alldunn.com > <mailto:robin@alldunn.com>> wrote:

    On 4/29/10 11:46 AM, cool-RR wrote:

        Now I have a question in a similar vein: How do I make an
        `IconBundle`
        from a stream?

    It is not supported.
    --
    Robin Dunn

Then what would be the best way to solve my problem? I have an `ico`
file with plenty of differently-sized icons in it. I can't load it as a
filename, I can load it as a stream. I want that icon with all the
different sizes to be used by my program. What do I do?

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

I think I will go with the solution of splitting them to different images. Just for the record, am I really supposed to be doing icon = IconFromBitmap(BitmapFromImage(ImageFromStream(stream)))?

Ram.

···

On Thu, Apr 29, 2010 at 10:04 PM, Robin Dunn robin@alldunn.com wrote:

On 4/29/10 12:06 PM, cool-RR wrote:

On Thu, Apr 29, 2010 at 9:00 PM, Robin Dunn <robin@alldunn.com > > mailto:robin@alldunn.com> wrote:

On 4/29/10 11:46 AM, cool-RR wrote:





    Now I have a question in a similar vein: How do I make an

    `IconBundle`

    from a stream?





It is not supported.

--

Robin Dunn

Then what would be the best way to solve my problem? I have an ico

file with plenty of differently-sized icons in it. I can’t load it as a

filename, I can load it as a stream. I want that icon with all the

different sizes to be used by my program. What do I do?

Either save the stream to a temporary file and load it from there, or split it into separate images that are loaded individually (you can then load them into an IconBundle at runtime if desired, or just use them individually as needed) or you can use img2py to put your images in Python code instead and just import them like any other Python module.

Robin Dunn

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en