def simple_load_icon(module, index, as_data=False, size=ICON_SIZE): ' Use the win32 API ExtractIcon to load the icon. This restricts icon size to 32x32, but has less chance of failing ' try: large_icons, small_icons = win32gui.ExtractIconEx(module, index, 10) except pywintypes.error as err: if err.winerror != winerror.ERROR_FILE_NOT_FOUND: raise prints('File %r does not exist, cannot load icon' % module) return icons = large_icons + small_icons try: if icons: must_use_qt() pixmap = copy_to_size(QtWin.fromHICON(icons[0]), size=size) if as_data: return pixmap_to_data(pixmap) return QIcon(pixmap) finally: tuple(map(win32gui.DestroyIcon, icons))
def hicon_to_pixmap(hicon): return QtWin.fromHICON(hicon)