Robin Dunn discussed an issue with wxImageList (Dec 23, 1999) that causes the images to get garbage-collected prematurely. He proposed a work-around in maintaining a reference to the wxImageList to prevent it from getting garbage-collected. However, not only is it necessary to maintain a reference to the list itself, but also to the window that contains the list.
Below is a program that demonstrates the bug. The workaround is to use
def OnInit(self):
self.win = ListFrame(None, -1, "")
self.win.Show(true)
however, this seems clumsy (I have to maintain a reference to every window that uses a wxImageList) and it took me quite some time to figure it out.
# ========== code start =================
from wxPython.wx import *
class ListFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title)
list = wxListCtrl(self, -1, style = wxLC_REPORT)
list.InsertColumn(0, "col 0")
self.il = wxImageList(16, 16)
list.SetImageList(self.il, wxIMAGE_LIST_SMALL)
icon = wxBitmap('smiles.bmp', wxBITMAP_TYPE_BMP)
index = self.il.Add(icon)
for i in range(10):
list.InsertImageStringItem(0, 'label %d' % i, index)
class Application(wxApp):
def OnInit(self):
win = ListFrame(None, -1, "")
win.Show(true)
return true
app = Application()
app.MainLoop()
"Kevin A. White" wrote:
···
Sorry for the repost, but I am down to the last part of my app, and no one
commented on why my code is giving me grief. I am trying to use the
wxLC_ICON style with the wxListCtrl, but the icons never display. Below is a
test code snippet. Anyone see what I am doing wrong?
from wxPython.wx import *
class CTest( wxFrame ):
def __init__(self):
wxFrame.__init__(self, NULL, -1, "test" )
il = wxImageList(16, 16)
idx1 = il.Add( wxBitmap('inboxs.bmp', wxBITMAP_TYPE_BMP) )
list = wxListCtrl(self, -1, style = wxLC_ICON )
list.SetImageList(il, wxIMAGE_LIST_NORMAL)
list.InsertImageStringItem(0, "test label", idx1)
class CApp( wxApp ):
def OnInit(self):
frame = CTest()
frame.Show(true)
self.SetTopWindow(frame)
return true
app = CApp(0)
app.MainLoop()
_______________________________________________
wxPython-users mailing list wxPython-users@wxwindows.org
http://wxwindows.org/mailman/listinfo/wxpython-users