[wxPython] Help: wxTreeCtrl doesn't display images

Hello!

Could anyone please tell me why the hell wxTreeCtrl doesn't display images?
(I've browsed the list arhcive and found that is was a problem some times ago. Is it still broken? Or the problem is in my code?!)
Here comes what I do:

···

#-----------------------------------
class MyTreeCtrl(wx.wxTreeCtrl):
def __init__(...):
  ...
wx.wxInitAllImageHandlers() folderbitmap=wx.wxImage("folder.bmp",wx.wxBITMAP_TYPE_BMP).ConvertToBitmap() imagelist=wx.wxImageList(16,16) idx=imagelist.Add(folderbitmap)
self.SetImageList(imagelist) root=self.AddRoot("root",idx,-1)
#-------------------------------------

Thanx
Zoltan Szalay
szz@philoslabs.com <mailto:szz@philoslabs.com>

Szalay Zoltan wrote:

Could anyone please tell me why wxTreeCtrl doesn't display images?
(I've browsed the list arhcive and found that is was a problem some
times ago. Is it still broken? Or the problem is in my code?!)

Images work for me on Linux, but not well on Windows.(I'm using plain
wxWindows, not wxPython.) I haven't updated my Windows version of
wxTreeCtrl, so I don't know if there have been any fixes recently.

It would help if you said what machine you are using and what version of
wxWindows. It may also help in reporting problems to use a debugging
build of wxWindows.

Edward

···

--------------------------------------------------------------------
Edward K. Ream email: edream@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------

Could anyone please tell me why the hell wxTreeCtrl doesn't display

images?

(I've browsed the list arhcive and found that is was a problem some
times ago. Is it still broken? Or the problem is in my code?!)
Here comes what I do:

#-----------------------------------
class MyTreeCtrl(wx.wxTreeCtrl):
def __init__(...):
  ...
wx.wxInitAllImageHandlers()

folderbitmap=wx.wxImage("folder.bmp",wx.wxBITMAP_TYPE_BMP).ConvertToBitmap()

imagelist=wx.wxImageList(16,16)
idx=imagelist.Add(folderbitmap)
self.SetImageList(imagelist)
root=self.AddRoot("root",idx,-1)
#-------------------------------------

Since wxImageLists are meant to be shared, the tree doesn't take over
ownership of the object like other things do in wxWindows. Because of this
you need to keep a reference to the image list so the C++ object isn't
destroyed when the Python one is.

    self.imagelist = imagelist

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Robin Dunn wrote:

Since wxImageLists are meant to be shared, the tree doesn't take over
ownership of the object like other things do in wxWindows. Because of this
you need to keep a reference to the image list so the C++ object isn't
destroyed when the Python one is.

    self.imagelist = imagelist

Is this a wxPython issue only, or could there be a related issue for
straight wxWindows code? I don't see anything about this in the
wxWindows documentation for wxTreeCtrl::SetItemList.

Edward

···

--------------------------------------------------------------------
Edward K. Ream email: edream@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------

Robin Dunn wrote:

> Since wxImageLists are meant to be shared, the tree doesn't take over
> ownership of the object like other things do in wxWindows. Because of

this

> you need to keep a reference to the image list so the C++ object isn't
> destroyed when the Python one is.
>
> self.imagelist = imagelist

Is this a wxPython issue only, or could there be a related issue for
straight wxWindows code? I don't see anything about this in the
wxWindows documentation for wxTreeCtrl::SetItemList.

Your program is probably leaking image lists. I don't recall right now if
it is in 2.2.x or not, but look at the differences between AssignImageList
and SetImageList. The 2.3 docs say this:

void AssignImageList(wxImageList* imageList)

Sets the normal image list. Image list assigned with this method will be
deleted by wxTreeCtrl's destructor (i.e. it takes ownership of it).

void SetImageList(wxImageList* imageList)

Sets the normal image list. Image list assigned with this method will not be
deleted by wxTreeCtrl's destructor, you must delete it yourself.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Robin Dunn wrote:

Your program is probably leaking image lists. I don't recall right now if
it is in 2.2.x or not, but look at the differences between AssignImageList
and SetImageList.

Thanks very much! This may clear up a long-running problem.

Edward

···

--------------------------------------------------------------------
Edward K. Ream email: edream@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------