In Wednesday, February 18, 2004, 6:42:01 PM, scrutinizer wrote:
Hello,
(sorry, I have already asked this, but it is still unsolved)
I want to display the icons associated with a given extensions
(also parent folder and folder) for my little filemanager in a virtual
list control.
I know, wxMimeTypesManager, unfortunatly, I cannot use it (i need indexes
beginning from zero for the imagelist, and I'm not able to get directory
icons)
With win32 extension, I didn't come clear also:
The indexes, which i get from:
dwFlags = Globals.SHGFI_USEFILEATTRIBUTES | Globals.SHGFI_SYSICONINDEX |
Globals.SHGFI_SMALLICON | Globals.SHGFI_ICON
windll.shell32.SHGetFileInfo (item.GetName(),
win32con.FILE_ATTRIBUTE_NORMAL,
byref(Globals.shfileinfo), sizeof(Globals.shfileinfo), dwFlags)
item.m_nIconIdx = Globals.shfileinfo.iIcon
(for example 9 for exe's, 8 html, 7 txt, 4 directories ...)
should correspond to the icons in the list
dwFlags = Globals.SHGFI_USEFILEATTRIBUTES | Globals.SHGFI_SYSICONINDEX |
Globals.SHGFI_SMALLICON
m_hImageList = windll.shell32.SHGetFileInfo('.txt',
win32file.FILE_ATTRIBUTE_NORMAL, byref(Globals.shfileinfo),
sizeof(Globals.shfileinfo), dwFlags)
In wxwindow, it is easy; but in wxPython (?)
Problem is: i get only a int pointer to the iconlist.
Can I transform this, to pass it into the image list; or is there another
solution?
Thank you for any help!
Francesco
Please mind the following snippet of code into the context of the
wxListCtrl example found in the demo. I don't know if this is exactly
what you need, but this do render icons associated to extensions in a
wxListCtrl, under Windows.
# <snip>
self.acdata = {1:["g:\","foo","py"],
2:["g:\","foo","com"],
3:["g:\","foo","html"]}
# <snip>
def PopulateList(self):
# folders, files, extensions
# <snip>
info = wxListItem()
info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
info.m_image = -1
info.m_format = 0
info.m_text = "Folder"
self.list.InsertColumnInfo(0, info)
info.m_format = 0
info.m_text = "Name"
self.list.InsertColumnInfo(1, info)
info.m_format = 0
info.m_text = "Ext"
self.list.InsertColumnInfo(2, info)
items = self.acdata.items();x=None
for x in range(len(items)):
key, data = items
idx1=self.idx1
fileType = wxTheMimeTypesManager.GetFileTypeFromExtension(data[2])
if fileType is not None:
info = fileType.GetIconInfo()
if info is not None:
# Get icon
img=wxBitmapFromIcon(info[0])
else:
# Extension doesn't have an icon associated to it.
fileType = wxTheMimeTypesManager.GetFileTypeFromExtension("exe")
if fileType is not None:
info = fileType.GetIconInfo()
if info is not None:
# Get icon
img=wxBitmapFromIcon(info[0])
else:
# Use this or some sort of 'unknow file'
# icon
img=wxEmptyBitmap(16,16)
# Convert to wxImage
img=wxImageFromBitmap(img)
# Resize to 16x16
img.Rescale(16,16)
# Convert to Bitmap
img=wxBitmapFromImage(img)
# Append Bitmap on self.il
idx1 = self.il.Add(img)
self.list.InsertImageStringItem(x, data[0], idx1)
self.list.SetStringItem(x, 1, data[1])
self.list.SetStringItem(x, 2, data[2])
self.list.SetItemData(x, key)
# <snip>
-- tacao