- Thread rewrite for improved stability
This commit is contained in:
parent
654c2e3500
commit
4750f1b309
@ -24,7 +24,11 @@ class AttackDisplay(wx.ScrolledWindow):
|
|||||||
self.attack = attack
|
self.attack = attack
|
||||||
|
|
||||||
wx.ScrolledWindow.__init__(self,parent,id=-1)
|
wx.ScrolledWindow.__init__(self,parent,id=-1)
|
||||||
self.SetBackgroundColour('White')
|
|
||||||
|
# [CC][X] The below statement might be iffy on older versions.
|
||||||
|
# (Python 2.3? What settings?)
|
||||||
|
# Cf. bug report Vimal Subra
|
||||||
|
self.SetBackgroundColour(wx.Colour(255,255,255))
|
||||||
|
|
||||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1))
|
self.Image = wx.StaticBitmap(self, -1, wx.EmptyBitmap(1,1))
|
||||||
|
@ -29,42 +29,40 @@ if Preference.usePIL():
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
class ScytherThread(threading.Thread):
|
class ScytherThread(threading.Thread):
|
||||||
|
"""
|
||||||
""" The reason this is a thread is because we might to decide to
|
Apply Scyther algorithm to input and retrieve results
|
||||||
abort it. However, apparently Python has no good support for killing
|
"""
|
||||||
threads yet :( """
|
|
||||||
|
|
||||||
# Override Thread's __init__ method to accept the parameters needed:
|
# Override Thread's __init__ method to accept the parameters needed:
|
||||||
def __init__ ( self, parent ):
|
def __init__ ( self, spdl, options="", callback=None ):
|
||||||
|
|
||||||
self.parent = parent
|
|
||||||
parent.verified = False
|
|
||||||
parent.claims = []
|
|
||||||
|
|
||||||
|
self.spdl = spdl
|
||||||
|
self.options = options
|
||||||
|
self.callback = callback
|
||||||
threading.Thread.__init__ ( self )
|
threading.Thread.__init__ ( self )
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
self.claimResults()
|
(scyther, claims, summary) = self.claimResults()
|
||||||
|
|
||||||
# Results are done (claimstatus can be reported)
|
# Results are done (claimstatus can be reported)
|
||||||
|
if self.callback:
|
||||||
|
wx.CallAfter(self.callback, scyther, claims, summary)
|
||||||
|
|
||||||
# Shoot down the verification window and let the RunScyther function handle the rest
|
|
||||||
self.parent.verified = True
|
|
||||||
self.parent.verifywin.Close()
|
|
||||||
|
|
||||||
def claimResults(self):
|
def claimResults(self):
|
||||||
""" Convert spdl to result (using Scyther)
|
""" Convert spdl to result (using Scyther)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.parent.scyther = scyther = Scyther.Scyther()
|
scyther = Scyther.Scyther()
|
||||||
scyther.options = self.parent.options
|
scyther.options = self.options
|
||||||
scyther.setInput(self.parent.spdl)
|
scyther.setInput(self.spdl)
|
||||||
|
|
||||||
# verification start
|
# verification start
|
||||||
self.parent.claims = scyther.verify()
|
claims = scyther.verify()
|
||||||
|
summary = str(scyther)
|
||||||
|
|
||||||
self.parent.summary = str(scyther)
|
return (scyther, claims, summary)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -97,6 +95,7 @@ class AttackThread(threading.Thread):
|
|||||||
|
|
||||||
def makeImages(self):
|
def makeImages(self):
|
||||||
""" create images """
|
""" create images """
|
||||||
|
|
||||||
done = 0
|
done = 0
|
||||||
for cl in self.parent.claims:
|
for cl in self.parent.claims:
|
||||||
for attack in cl.attacks:
|
for attack in cl.attacks:
|
||||||
@ -261,11 +260,6 @@ class ResultWindow(wx.Frame):
|
|||||||
"""
|
"""
|
||||||
Displays the claims status and contains buttons to show the actual
|
Displays the claims status and contains buttons to show the actual
|
||||||
attack graphs
|
attack graphs
|
||||||
|
|
||||||
TODO: this really should have a statusbar that works.
|
|
||||||
|
|
||||||
TODO: on windows, it updates really slow, and the background is the
|
|
||||||
wrong colour. Basically, it inhales air. Hard.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -429,34 +423,29 @@ class ScytherRun(object):
|
|||||||
self.mainwin = mainwin
|
self.mainwin = mainwin
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.spdl = mainwin.control.GetValue()
|
self.spdl = mainwin.control.GetValue()
|
||||||
|
|
||||||
# Verification window
|
|
||||||
|
|
||||||
self.verifywin = verifywin = VerificationWindow(mainwin,"Running Scyther %s process" % mode)
|
|
||||||
verifywin.Center()
|
|
||||||
verifywin.Show(True)
|
|
||||||
|
|
||||||
# start the thread
|
|
||||||
|
|
||||||
self.options = mainwin.settings.ScytherArguments(mode)
|
|
||||||
self.verified = False
|
self.verified = False
|
||||||
verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
|
self.options = mainwin.settings.ScytherArguments(mode)
|
||||||
|
self.main()
|
||||||
|
|
||||||
t = ScytherThread(self)
|
def verificationDone(self, scyther, claims, summary):
|
||||||
t.start()
|
|
||||||
|
|
||||||
# start the window and show until something happens
|
self.scyther = scyther
|
||||||
# if it terminates, this is a cancel, and should also kill the thread. (what happens to a spawned Scyther in that case?)
|
self.claims = claims
|
||||||
# if the thread terminames, it should close the window normally, and we end up here as well.
|
self.summary = summary
|
||||||
val = verifywin.ShowModal()
|
|
||||||
|
|
||||||
if self.verified:
|
self.verified = True
|
||||||
# Scyther program is done (the alternative is that it was
|
self.verifywin.Close()
|
||||||
# cancelled)
|
|
||||||
|
# Process the claims
|
||||||
if self.scyther.errorcount == 0:
|
if self.scyther.errorcount == 0:
|
||||||
|
self.verificationOkay()
|
||||||
|
else:
|
||||||
|
self.verificationErrors()
|
||||||
|
|
||||||
|
def verificationOkay(self):
|
||||||
# Great, we verified stuff, progress to the claim report
|
# Great, we verified stuff, progress to the claim report
|
||||||
title = "Scyther results : %s" % mode
|
title = "Scyther results : %s" % self.mode
|
||||||
self.resultwin = resultwin = ResultWindow(self,mainwin,title)
|
self.resultwin = resultwin = ResultWindow(self,self.mainwin,title)
|
||||||
|
|
||||||
def attackDone(attack,total,done):
|
def attackDone(attack,total,done):
|
||||||
if resultwin:
|
if resultwin:
|
||||||
@ -485,13 +474,39 @@ class ScytherRun(object):
|
|||||||
|
|
||||||
resultwin.thread = t
|
resultwin.thread = t
|
||||||
|
|
||||||
else:
|
def verificationErrors(self):
|
||||||
# Darn, some errors. report.
|
"""
|
||||||
title = "Scyther errors : %s" % mode
|
Verification process generated errors. Show them.
|
||||||
errorwin = ErrorWindow(mainwin,title,errors=self.scyther.errors)
|
"""
|
||||||
|
|
||||||
|
title = "Scyther errors : %s" % self.mode
|
||||||
|
errorwin = ErrorWindow(self.mainwin,title,errors=self.scyther.errors)
|
||||||
errorwin.Center()
|
errorwin.Center()
|
||||||
val = errorwin.ShowModal()
|
val = errorwin.ShowModal()
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
"""
|
||||||
|
Start process
|
||||||
|
"""
|
||||||
|
|
||||||
|
title = "Running Scyther %s process" % self.mode
|
||||||
|
self.verifywin = VerificationWindow(self.mainwin,title)
|
||||||
|
self.verifywin.Center()
|
||||||
|
self.verifywin.Show(True)
|
||||||
|
|
||||||
|
# start the thread
|
||||||
|
|
||||||
|
self.verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
|
||||||
|
|
||||||
|
t = ScytherThread(self.spdl, self.options, self.verificationDone)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
# start the window and show until something happens
|
||||||
|
# if it terminates, this is a cancel, and should also kill the thread. (what happens to a spawned Scyther in that case?)
|
||||||
|
# if the thread terminames, it should close the window normally, and we end up here as well.
|
||||||
|
val = self.verifywin.ShowModal()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user