I have an application that attempts to display a jpeg file. If the user tries to load a non-jpeg file, a dialog appears that says "JPEG: Couldn't load - file is probably corrupted". I'd like to handle the error myself - is there any way to prevent this dialog from appearing? Wrapping the LoadFile() call in a try/except block doesn't help.
I'm using wxWindows 2.3.1 and python 2.1.2 on Windows2000. The offending code is (locatedb.txt is just a non-jpeg file that I happen to have on my HD):
i = wxImage("c:\\locatedb.txt", wxBITMAP_TYPE_JPEG)
The dialog won't appear if there are no windows displayed. If I just type the above from an interactive session (after doing wxInitAllImageHandlers()), this error appears on stdout instead:
Not a JPEG file: starts with 0x63 0x3a
11:44:56: Error: JPEG: Couldn't load - file is probably corrupted.
I'm attaching a program that reproduces the problem:
···
=====================================================================
from wxPython.wx import *
class BadJpg(wxDialog):
def __init__(self, parent):
wxDialog.__init__(self, parent, -1, "BadJpg")
# create controls
self.okButton = wxButton(self, 1, "O&k")
EVT_BUTTON(self, 1, self.OnOk)
def OnOk(self, event):
try:
i = wxImage("c:\\locatedb.txt", wxBITMAP_TYPE_JPEG)
except:
pass
wxInitAllImageHandlers()
app = wxPySimpleApp()
dlg = BadJpg(None)
dlg.ShowModal()
--
Mark Wright
mwright@pro-ns.net