Unwanted error dialog appears when I try to load a bad jpeg

0 views
Skip to first unread message

Mark Wright

unread,
May 26, 2003, 12:53:19 PM5/26/03
to wxPytho...@lists.wxwindows.org
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
mwr...@pro-ns.net

Roach, Mark R.

unread,
May 26, 2003, 2:21:51 PM5/26/03
to wxPytho...@lists.wxwindows.org
On Mon, 2003-05-26 at 12:53, Mark Wright wrote:
> 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.
>

Have you tried using wxLog? try setting your log target to wxLogNull
http://www.wxwindows.org/manuals/2.4.0/wx465.htm#wxlogoverview

If that doesn't keep the error message from popping up, then it's
probably a bug. I encountered a similar bug in wxTIFFHandler, basically
the tiff library was popping up the message directly, bypassing
wxwindows altogether. I uploaded a patch for this problem, that you can
probably adapt for libjpeg if this turns out to be the problem.

http://sourceforge.net/tracker/?group_id=9863&atid=309863&func=detail&aid=740071

Cool, looks like it has finally been applied.

Like I say, though, you probably want to just try changing your log
target first.

-Mark


Reply all
Reply to author
Forward
0 new messages