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 scyther-gui components """
import Icon import Icon
import Preference import Preference
import Error
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
if Preference.usePIL(): if Preference.usePIL():
@ -70,7 +71,11 @@ class AttackDisplay(wx.ScrolledWindow):
self.original = wx.Image(filename,wx.BITMAP_TYPE_PNG) self.original = wx.Image(filename,wx.BITMAP_TYPE_PNG)
elif attack.filetype == "ps": elif attack.filetype == "ps":
# depends on PIL lib # depends on PIL lib
try:
self.original = Image.open(filename) self.original = Image.open(filename)
except:
Preference.doNotUsePIL()
raise Error.PILError
else: else:
print "Unknown file type %s." % (self.filetype) 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" title = "Error"
dlg = wx.MessageDialog(None, text, title, wx.ID_OK | wx.ICON_ERROR) dlg = wx.MessageDialog(None, text, title, wx.ID_OK | wx.ICON_ERROR)
result = dlg.ShowModal() result = dlg.ShowModal()
dlg.Destroy() dlg.Destroy()
def ShowAndExit(text):
ShowAndReturn(text)
sys.exit() sys.exit()

View File

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

View File

@ -357,8 +357,12 @@ class ResultWindow(wx.Frame):
def onViewButton(self,evt): def onViewButton(self,evt):
btn = evt.GetEventObject() btn = evt.GetEventObject()
try:
w = Attackwindow.AttackWindow(btn.claim) w = Attackwindow.AttackWindow(btn.claim)
w.Show(True) 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): def onCloseWindow(self,evt):
""" TODO we should kill self.thread """ """ TODO we should kill self.thread """