- Refactoring helps a lot.
This commit is contained in:
parent
afe1947255
commit
83e1d9375d
@ -35,6 +35,7 @@ class ScytherThread(threading.Thread):
|
|||||||
self.verifywin = verifywin
|
self.verifywin = verifywin
|
||||||
self.spdl = spdl
|
self.spdl = spdl
|
||||||
self.details = details
|
self.details = details
|
||||||
|
self.verified = False
|
||||||
|
|
||||||
self.claims = []
|
self.claims = []
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ class ScytherThread(threading.Thread):
|
|||||||
# Results are done (claimstatus can be reported)
|
# Results are done (claimstatus can be reported)
|
||||||
|
|
||||||
# Shoot down the verification window and let the RunScyther function handle the rest
|
# Shoot down the verification window and let the RunScyther function handle the rest
|
||||||
self.mainwin.verified = True
|
self.verified = True
|
||||||
self.verifywin.Close()
|
self.verifywin.Close()
|
||||||
|
|
||||||
def claimResults(self):
|
def claimResults(self):
|
||||||
@ -148,12 +149,32 @@ class ResultWindow(wx.Frame):
|
|||||||
self.thread = None
|
self.thread = None
|
||||||
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
|
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
|
||||||
|
|
||||||
|
self.BuildTable()
|
||||||
|
|
||||||
|
|
||||||
|
def onViewButton(self,evt):
|
||||||
|
btn = evt.GetEventObject()
|
||||||
|
(y,x) = self.grid.GetItemPosition(btn)
|
||||||
|
n = len(self.mainwindow.claims)
|
||||||
|
cln = n-y
|
||||||
|
cl = self.mainwindow.claims[cln]
|
||||||
|
w = Attackwindow.AttackWindow(cl)
|
||||||
|
|
||||||
|
def onCloseWindow(self,evt):
|
||||||
|
# TODO we should kill self.thread
|
||||||
|
self.mainwindow.claims = None
|
||||||
|
self.Destroy()
|
||||||
|
|
||||||
|
|
||||||
|
def BuildTable(self):
|
||||||
# Now continue with the normal construction of the dialog
|
# Now continue with the normal construction of the dialog
|
||||||
# contents
|
# contents
|
||||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
|
||||||
|
# For these claims...
|
||||||
|
claims = self.mainwindow.claims
|
||||||
|
|
||||||
# set up grid
|
# set up grid
|
||||||
claims = mainwindow.claims
|
|
||||||
self.grid = grid = wx.GridBagSizer(7,1+len(claims))
|
self.grid = grid = wx.GridBagSizer(7,1+len(claims))
|
||||||
|
|
||||||
def titlebar(x,title,width=1):
|
def titlebar(x,title,width=1):
|
||||||
@ -170,16 +191,22 @@ class ResultWindow(wx.Frame):
|
|||||||
resultxt = "Results"
|
resultxt = "Results"
|
||||||
titlebar(5,resulttxt,2)
|
titlebar(5,resulttxt,2)
|
||||||
|
|
||||||
lastprot = None
|
self.lastprot = None
|
||||||
lastrole = None
|
self.lastrole = None
|
||||||
for index in range(0,len(claims)):
|
for index in range(0,len(claims)):
|
||||||
cl = claims[len(claims)-index-1]
|
|
||||||
# we reverse the display order of the claims!
|
# we reverse the display order of the claims!
|
||||||
y = index+1
|
cl = claims[len(claims)-index-1]
|
||||||
|
self.BuildClaim(grid,cl,index+1)
|
||||||
|
|
||||||
|
sizer.Add(grid, 0,wx.ALIGN_CENTRE|wx.ALL,5)
|
||||||
|
|
||||||
|
self.SetSizer(sizer)
|
||||||
|
sizer.Fit(self)
|
||||||
|
|
||||||
|
def BuildClaim(self,grid,cl,ypos):
|
||||||
# a support function
|
# a support function
|
||||||
def addtxt(txt,column):
|
def addtxt(txt,column):
|
||||||
grid.Add(wx.StaticText(self,-1,txt),(y,column),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
grid.Add(wx.StaticText(self,-1,txt),(ypos,column),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
||||||
|
|
||||||
# button for ok/fail
|
# button for ok/fail
|
||||||
tsize = (16,16)
|
tsize = (16,16)
|
||||||
@ -191,17 +218,22 @@ class ResultWindow(wx.Frame):
|
|||||||
bmp = wx.EmptyBitmap(tsize)
|
bmp = wx.EmptyBitmap(tsize)
|
||||||
bmpfield = wx.StaticBitmap(self,-1,bmp)
|
bmpfield = wx.StaticBitmap(self,-1,bmp)
|
||||||
|
|
||||||
grid.Add(bmpfield,(y,0),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
grid.Add(bmpfield,(ypos,0),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
||||||
|
|
||||||
# protocol, role, label
|
# protocol, role, label
|
||||||
prot = str(cl.protocol)
|
prot = str(cl.protocol)
|
||||||
if prot != lastprot:
|
showPR = False
|
||||||
addtxt(prot,1)
|
if prot != self.lastprot:
|
||||||
lastprot = prot
|
self.lastprot = prot
|
||||||
|
showPR = True
|
||||||
role = str(cl.role)
|
role = str(cl.role)
|
||||||
if role != lastrole:
|
if role != self.lastrole:
|
||||||
|
self.lastrole = role
|
||||||
|
showPR = True
|
||||||
|
if showPR:
|
||||||
|
addtxt(prot,1)
|
||||||
addtxt(role,2)
|
addtxt(role,2)
|
||||||
lastrole = role
|
|
||||||
addtxt(str(cl.shortlabel),3)
|
addtxt(str(cl.shortlabel),3)
|
||||||
|
|
||||||
claimdetails = str(cl.claimtype)
|
claimdetails = str(cl.claimtype)
|
||||||
@ -212,7 +244,7 @@ class ResultWindow(wx.Frame):
|
|||||||
# add view button (if needed)
|
# add view button (if needed)
|
||||||
n = len(cl.attacks)
|
n = len(cl.attacks)
|
||||||
cl.button = wx.Button(self,-1,"%i %s" % (n,cl.stateName(n)))
|
cl.button = wx.Button(self,-1,"%i %s" % (n,cl.stateName(n)))
|
||||||
grid.Add(cl.button,(y,5),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
grid.Add(cl.button,(ypos,5),(1,1),wx.ALIGN_CENTER_VERTICAL)
|
||||||
cl.button.Disable()
|
cl.button.Disable()
|
||||||
if n > 0:
|
if n > 0:
|
||||||
# Aha, something to show
|
# Aha, something to show
|
||||||
@ -236,33 +268,6 @@ class ResultWindow(wx.Frame):
|
|||||||
remark = "exactly"
|
remark = "exactly"
|
||||||
addtxt(" (%s)" % remark,6)
|
addtxt(" (%s)" % remark,6)
|
||||||
|
|
||||||
sizer.Add(grid, 0,wx.ALIGN_CENTRE|wx.ALL,5)
|
|
||||||
|
|
||||||
# # separator
|
|
||||||
# line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
|
|
||||||
# sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
|
|
||||||
|
|
||||||
# btn = wx.Button(self, -1,"Close window")
|
|
||||||
# self.Bind(wx.EVT_BUTTON,self.onCloseButton,btn)
|
|
||||||
|
|
||||||
# sizer.Add(btn, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.ALIGN_RIGHT, 5)
|
|
||||||
|
|
||||||
|
|
||||||
self.SetSizer(sizer)
|
|
||||||
sizer.Fit(self)
|
|
||||||
|
|
||||||
|
|
||||||
def onViewButton(self,evt):
|
|
||||||
btn = evt.GetEventObject()
|
|
||||||
(y,x) = self.grid.GetItemPosition(btn)
|
|
||||||
n = len(self.mainwindow.claims)
|
|
||||||
cln = n-y
|
|
||||||
cl = self.mainwindow.claims[cln]
|
|
||||||
w = Attackwindow.AttackWindow(cl)
|
|
||||||
|
|
||||||
def onCloseWindow(self,evt):
|
|
||||||
# TODO we should kill self.thread
|
|
||||||
self.Destroy()
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -279,7 +284,6 @@ def RunScyther(mainwin,mode):
|
|||||||
|
|
||||||
verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
|
verifywin.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
|
||||||
|
|
||||||
mainwin.verified = False
|
|
||||||
mainwin.settings.mode = mode
|
mainwin.settings.mode = mode
|
||||||
t = ScytherThread(mainwin,mainwin.control.GetValue(),"",verifywin)
|
t = ScytherThread(mainwin,mainwin.control.GetValue(),"",verifywin)
|
||||||
t.start()
|
t.start()
|
||||||
@ -293,7 +297,7 @@ def RunScyther(mainwin,mode):
|
|||||||
# Cursor back to normal
|
# Cursor back to normal
|
||||||
verifywin.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
verifywin.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
|
||||||
|
|
||||||
if mainwin.verified:
|
if t.verified:
|
||||||
# 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" % mode
|
||||||
resultwin = ResultWindow(mainwin,-1,title)
|
resultwin = ResultWindow(mainwin,-1,title)
|
||||||
|
Loading…
Reference in New Issue
Block a user