Native Windows error message after SetIcon(), no python exception raised

Documentation of SetIcon (http://wxwidgets.org/manuals/stable/wx_wxtoplevelwindow.html#wxtoplevelwindowseticon) says that it is safe to delete the icon after calling this function. Now here are the wreid things:

1. The icon is displayed correctly in the left top corner, so where is the error?
2. The error message complains about a file. The wx.Icon instance and the wx.Frame instance are already in memory when I call SetIcon. What it has to do with any file?

How do you load the icon?

First I load a PIL image from a png file and convert it to a wx.Image. Then I store the bitmap in a wx.ImageList instance (actually a descendant but I hope it doesn't matter). This descendant has a GetIcon method:

    def GetIcon(self,name):
        bmp = self.copybitmap(name)
        return imagetools.bitmaptoicon( bmp )

The copytobitmap method uses wx.BitmapFromImage to create a wx.Bitmap from the wx.Image. (The original wx.Image was loaded from a png file, the resulting bitmap will have a mask assigned, but I hope this is not related to the problem.)

Finally, here is the bitmaptoicon function:

def bitmaptoicon(bmp):
    """Convert wx.Bitmap to wx.Icon.
       NOTE: The bitmap should already have a mask assigned.
       @param bmp: A wx.Bitmap instance
    """
    ico = wx.Icon('',bmp.GetWidth(),bmp.GetHeight())
    ico.CopyFromBitmap(bmp)
    return ico

Thanks,

  Laszlo

Probably unrelated to you problem, but...

Laszlo Nagy wrote:

First I load a PIL image from a png file and convert it to a wx.Image.

Why not just load it directly into wx.Image from the PNG?

-Chris

ยทยทยท

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Robin Dunn wrote:

   ico = wx.Icon('',bmp.GetWidth(),bmp.GetHeight())

This is where the problem is coming from. You are using the load-from-file constructor but are not supplying a filename.

Great. Thank you! I tried wx.IconFromBitmap and it worked. But I still do not understand what is happening here.

   ico.CopyFromBitmap(bmp)
   return ico

If the constructor fails, then it should raise a Python exception. At least this is what I would expect. But it returns a (half initialized?) instance. I would like to understand.

BTW I figured out something: I used wxPython 2.6 on Ubuntu and 2.8 on Windows. The 2.6 version works with the above code, 2.8 does not.

You can use this instead:

    ico = wx.IconFromBitmap(bmp)
    return ico

Thanks again,

   Laszlo