Nicer crash handling for PIL problem with a warning etc.

This commit is contained in:
Cas Cremers 2008-05-02 17:10:29 +02:00
parent eb64f68968
commit 76bf6328b6
4 changed files with 33 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import time
""" Import scyther-gui components """
import Icon
import Preference
import Error
#---------------------------------------------------------------------------
if Preference.usePIL():
@ -70,7 +71,11 @@ class AttackDisplay(wx.ScrolledWindow):
self.original = wx.Image(filename,wx.BITMAP_TYPE_PNG)
elif attack.filetype == "ps":
# depends on PIL lib
self.original = Image.open(filename)
try:
self.original = Image.open(filename)
except:
Preference.doNotUsePIL()
raise Error.PILError
else:
print "Unknown file type %s." % (self.filetype)

View File

@ -31,10 +31,21 @@ import sys
#---------------------------------------------------------------------------
def ShowAndExit(text):
class PILError (Exception):
pass
class NoAttackError(Exception):
pass
#---------------------------------------------------------------------------
def ShowAndReturn(text):
title = "Error"
dlg = wx.MessageDialog(None, text, title, wx.ID_OK | wx.ICON_ERROR)
result = dlg.ShowModal()
dlg.Destroy()
def ShowAndExit(text):
ShowAndReturn(text)
sys.exit()

View File

@ -55,7 +55,7 @@ from time import localtime,strftime
""" Globals """
# Do we have the Python Imaging library?
havePIL = True
havePIL = False # For now, override (bounding box bug on Feisty?)
#havePIL = False # For now, override (bounding box bug on Feisty?)
try:
import Image
except ImportError:
@ -80,6 +80,14 @@ def usePIL():
return False
def doNotUsePIL():
"""
Disable
"""
global havePIL
havePIL = False
#---------------------------------------------------------------------------
class Preferences(dict):

View File

@ -357,8 +357,12 @@ class ResultWindow(wx.Frame):
def onViewButton(self,evt):
btn = evt.GetEventObject()
w = Attackwindow.AttackWindow(btn.claim)
w.Show(True)
try:
w = Attackwindow.AttackWindow(btn.claim)
w.Show(True)
except Error.PILError:
Error.ShowAndReturn("Problem with PIL imaging library: disabled zooming. Please retry to verify the protocol again.")
self.onCloseWindow(None)
def onCloseWindow(self,evt):
""" TODO we should kill self.thread """