I try to use the wxMimeTypesManager, and it works for most suffixes, except for some for which the default icon cannot be loaded. I wrap the code in try ... except statements and check for invalid icon data and the exceptions are indeed thrown and properly catched, but there is still a "Python Error" dialog that pops up each time (XP/SP2):
"Python Error" - "Failed to load icon from file '%1' (error 2: System cannot find the specified file.)"
The same error occurs in the wxMimeTypesManager demo, but there it is silently logged to the background. How do I prevent the dialog from appearing? After all, my application successfully recovers from the error and falls back to a default icon.
Here's the code:
def getIconAndInfo(self, suffix):
try:
if suffix == "":
raise
fileType = wx.TheMimeTypesManager.GetFileTypeFromExtension(suffix)
if fileType == None: raise
icon = fileType.GetIconInfo()[0]
if not icon.Ok(): raise
return (icon, self.makeInfo(suffix))
except: return (self.defaultIcon, self.makeInfo(self.defaultSuffix))