I have a problem with the TreeCtrl (a albumlist):
In the imagelist are covers (size 32x32). Not for every album exists a cover and the artist shoul also have no cover.
But when i don't set the image, the treectrl displays a empty image (blank space) and the row height is also 32 pixels.
The rows without any cover should be normal high and the rows with cover should 32 pixels high.
I found the CustomTreeCtrl, fully implemented in Python. With this it works (see right tree on the screenshot) but it's too slow (adding the items does take too long).
Here a screenshot of both treectrls:
On the left it's the normal wx.TreeCtrl and on the right it's the CustomTreeCtrl (this looks what i want but i takes too long to add all items)
But when i don't set the image, the treectrl displays a empty image
(blank space) and the row height is also 32 pixels.
In my opinion, this is a wrong behavior for wx.TreeCtrl. If you
specify wx.TR_HAS_VARIABLE_ROW_HEIGHT. the height should be variable,
no excuse.
I found the CustomTreeCtrl, fully implemented in Python. With this it
works (see right tree on the screenshot) but it's too slow (adding the
items does take too long).
"Slow" is rather approximative. How long does it take? Do you really
need all those checkboxes in your CustomTreeCtrl? Checkboxes are also
images, which take a while to draw and to load.
You have also the possibility to populate your CustomTreeCtrl in
steps. You don't need to assing an image for every TreeItem at the
beginning, you could try to do it only when a parent item is expanded.
Or you could use a thread to populate you CustomTreeCtrl in
background. Obviously, if you have thousands of items, you might stick
with wx.TreeCtrl or re-think your GUI strategy.
I am always open to new suggestions to improve CustomTreeCtrl, even if
I don't see any way at the moment with which it could be sped-up.
"Slow" is rather approximative. How long does it take? Do you really
need all those checkboxes in your CustomTreeCtrl? Checkboxes are also
images, which take a while to draw and to load.
No i can also do it with two trees (it's a small software to handle my music database on the harddisk and the music player)
So i can doubleclick one item on the harddisk and it will be copied on to the player (and to the other tree)
You have also the possibility to populate your CustomTreeCtrl in
steps. You don't need to assing an image for every TreeItem at the
beginning, you could try to do it only when a parent item is expanded.
Ok i'll try this, i think that can work.
There are around 180 Toptelevel entries, with no checkboxes and images - then it shouldn't take so long.
Can i just append the items on the expand event? (or is then the plus-sign missing when i only append the first level of items?)
Or you could use a thread to populate you CustomTreeCtrl in
background. Obviously, if you have thousands of items, you might stick
with wx.TreeCtrl or re-think your GUI strategy.
I am always open to new suggestions to improve CustomTreeCtrl, even if
I don't see any way at the moment with which it could be sped-up.
Ok i'll try this, i think that can work.
There are around 180 Toptelevel entries, with no checkboxes and images -
then it shouldn't take so long.
I have tried with my mp3 list, assuming that 2 albums/songs had a
cover (just to test it). This means that for every artist, 2
albums/songs have a 32x32 icon beside the checkbox. I have used an
ArtProvider icon, just to test.
Well, I have 723 artists, with 1801 songs globally. Populating the
CustomTreeCtrl took 0.141 seconds on my laptop. Using a standard
wx.TreeCtrl took 0.089 seconds (mean values calculated on 10 runs). I
would not say that CustomTreeCtrl runs at speed of light, but it is
surely *not* slow compared to wx.TreeCtrl. It runs about at 2/3 of
wx.TreeCtrl speed, though I don't know if this is linear or it
increases if you have far more items in the tree.
This is a screenshot of what I got:
I attach the script I used. It is inefficient and retrieves tha files
only on my pc directory structure, but you get the idea. If you have
set up a different method to populate the tree or you are doing things
in other ways, let me know.
Can i just append the items on the expand event? (or is then the
plus-sign missing when i only append the first level of items?)
I think you can, though I have never done it. If an item has no
children (because it still has to be populated), you can use as a
workaround:
YourTree.SetItemHasChildren(True)
which forces the appearance of the button next to the item, even if it
doesn't have children.
Can i just append the items on the expand event? (or is then the
plus-sign missing when i only append the first level of items?)
I think you can, though I have never done it. If an item has no
children (because it still has to be populated), you can use as a
workaround:
YourTree.SetItemHasChildren(True)
which forces the appearance of the button next to the item, even if it
doesn't have children.
Thanks that's what i need.
I populated the tree totally wrong ... i didn't sort the artist/album list so i searched through the whole tree to get the artist node, this took extremly long, now i do it the same way as you does.
The most time take the glob-module to get the folder list.