diff --git a/gui/Gui/Attackwindow.py b/gui/Gui/Attackwindow.py index d6ec28d..ec1ce5a 100644 --- a/gui/Gui/Attackwindow.py +++ b/gui/Gui/Attackwindow.py @@ -5,19 +5,17 @@ """ Import externals """ import wx import time -# Python Imaging library? -usePIL = True -try: - import Image -except ImportError: - usePIL = False #--------------------------------------------------------------------------- """ Import scyther-gui components """ import Icon +import Preference #--------------------------------------------------------------------------- +if Preference.usePIL(): + import Image +#--------------------------------------------------------------------------- class AttackDisplay(wx.ScrolledWindow): def __init__(self, daddy, parent, attack): @@ -117,8 +115,6 @@ class AttackDisplay(wx.ScrolledWindow): class AttackWindow(wx.Frame): def __init__(self,cl): - global usePIL - super(AttackWindow, self).__init__(None, size=(400,800)) self.SetBackgroundColour('Default') self.claim = cl @@ -126,7 +122,7 @@ class AttackWindow(wx.Frame): # TODO maybe fitting defaults should come from Preferences. # Now, it is default yes if it looks nice (i.e. we are using # PIL) - if usePIL: + if Preference.usePIL(): self.fit = True else: self.fit = False diff --git a/gui/Gui/Preference.py b/gui/Gui/Preference.py index 7a07611..993b360 100644 --- a/gui/Gui/Preference.py +++ b/gui/Gui/Preference.py @@ -34,6 +34,12 @@ from time import localtime,strftime #--------------------------------------------------------------------------- """ Globals """ +# Do we have the Python Imaging library? +havePIL = True +try: + import Image +except ImportError: + havePIL = False """ Locations of preferences. The last one is supposedly writable. """ prefname = "scythergui-config" @@ -41,6 +47,21 @@ preflocs = [] #--------------------------------------------------------------------------- +def usePIL(): + """ + Determine whether or not we should use the PIL library + """ + global havePIL + + # Only if we have it, and it is windows. + if havePIL: + if sys.platform.startswith("lin"): + return True + + return False + +#--------------------------------------------------------------------------- + class Preferences(dict): def parse(self,line): diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index 608141d..225d072 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -10,13 +10,6 @@ import re import threading import StringIO -# Python Imaging library? -usePIL = True -try: - import Image -except ImportError: - usePIL = False - #--------------------------------------------------------------------------- """ Import scyther components """ @@ -31,7 +24,8 @@ import Attackwindow import Icon #--------------------------------------------------------------------------- - +if Preference.usePIL(): + import Image #--------------------------------------------------------------------------- class ScytherThread(threading.Thread): @@ -117,9 +111,7 @@ class AttackThread(threading.Thread): def makeImage(self,attack): """ create image for this particular attack """ - global usePIL - - if usePIL: + if Preference.usePIL(): # If we have the PIL library, we can do postscript! great # stuff. type = "ps"