File list with icons on wxPython/Windows
I recently wanted to show a list of files in wxPython, with the file icons (on Windows). I found the answer in this post by Mark Hammond, then had to search around a bit to find how to get the icon handle into a wxPython bitmap for the image list. I thought I'd save any future searchers the trouble.
Here's the meat of the code:
from win32com.shell import shell, shellcon
from win32con import FILE_ATTRIBUTE_NORMAL
"""dot is mandatory in extension"""
flags = shellcon.SHGFI_SMALLICON | \
shellcon.SHGFI_ICON | \
retval, info = shell.SHGetFileInfo(extension,
# non-zero on success
hicon, iicon, attr, display_name, type_name = info
# Get the bitmap
icon = wx.EmptyIcon()
Here is a python file with a subclass of wx.ListCtrl that shows a list of files, and a simple demo as proof of concept.