How to use your own icons in wx.GenericDirCtrl, rather than the defaults provided. Note this only works with the wx.DIRCTRL_DIR_ONLY option. here's one example (using icons from the Berlin subway KDE theme):
What Objects are Involved
If you want to use your own image files, first step would be to create them. I am using .ico files for this example, however you can use any image type supported by wx.Bitmap. You can also use wx.ArtProvider_GetBitmap (this is the default) and/or the 'images' module. Next we create a 7 item image list and add the images to it. Finally assign said image list to the DirCtrl's TreeCtrl via GetTreeCtrl().
This will only work properly if you are using the wx.DIRCTRL_DIR_ONLY option in your wx.GenericDirCtrl. Since we are replacing the default ImageList with a different (and smaller) one, the images for the different mime types never get set. So when files are listed there will not be an image next to them, though the text will appear properly. I'm sure there is a way around this, however I did not need to do it for my purposes.
I'm only showing you the wx.GenericDirCtrl construction, though you should be able to just copy this, change the images, size/position, and basta. I copied heavily from the samples.
1 # initial construction: 2 self.dirPicker = wx.GenericDirCtrl(self, size=(300, -1), name='dirPicker', style=wx.DIRCTRL_DIR_ONLY | wx.DIRCTRL_3D_INTERNAL) 3 4 # create the image list: 5 isz = (16, 16) 6 il = wx.ImageList(isz, isz) 7 8 # Add images to list. You need to keep the same order in order for 9 # this to work! 10 11 # closed folder: 12 il.Add(wx.Bitmap("art/icons/folder.ico",wx.BITMAP_TYPE_ICO)) 13 14 # open folder: 15 il.Add(wx.Bitmap("art/icons/folder_open.ico",wx.BITMAP_TYPE_ICO)) 16 17 # root of filesystem (linux): 18 il.Add(wx.Bitmap("art/icons/root.ico",wx.BITMAP_TYPE_ICO)) 19 20 # drive letter (windows): 21 il.Add(wx.Bitmap("art/icons/hdd.ico",wx.BITMAP_TYPE_ICO)) 22 23 # cdrom drive: 24 il.Add(wx.Bitmap("art/icons/cdrom.ico",wx.BITMAP_TYPE_ICO)) 25 26 # removable drive on win98: 27 il.Add(wx.Bitmap('art/icons/floppy.ico',wx.BITMAP_TYPE_ICO)) 28 29 # removable drive (floppy, flash, etc): 30 il.Add(wx.Bitmap("art/icons/floppy.ico",wx.BITMAP_TYPE_ICO)) 31 32 33 # assign image list: 34 self.il = il 35 self.dirPicker.GetTreeCtrl().SetImageList(il)
Ianaré Sévi - ianare at gmail dot com
Many thanks for the tip -- used in Fonty Python!