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