diff --git a/gui/Changelog.txt b/gui/Changelog.txt index abfc8dc..7188218 100644 --- a/gui/Changelog.txt +++ b/gui/Changelog.txt @@ -8,7 +8,7 @@ Scyther 1.0-beta6 * [Gui] Added Mac support (added universal binary) * [Gui] Switched to Scintilla editor component, providing undo - and line numbering. + and line numbering, and highlighting of error lines. Other new features: diff --git a/gui/Gui/Editor.py b/gui/Gui/Editor.py index 6a15fbc..b8c40d5 100644 --- a/gui/Gui/Editor.py +++ b/gui/Gui/Editor.py @@ -4,6 +4,7 @@ """ Import externals """ import wx +import string # Use Scintilla editor? useStc = True # It looks nicer! @@ -26,6 +27,34 @@ if useStc: #--------------------------------------------------------------------------- +def justNumbers(txt): + for x in txt: + if not x in string.digits: + return False + return True + +def lineInError(txt): + # First option: square braces + x1 = txt.find("[") + if x1 >= 0: + x2 = txt.find("]") + if x2 > x1: + nrstring = txt[(x1+1):x2] + if justNumbers(nrstring): + return int(nrstring) + # Alternative: ...line x + pref = " line " + i = txt.find(pref) + if i >= 0: + i = i + len(pref) + j = i + while txt[j] in string.digits: + j = j+1 + if j > i: + return int(txt[i:j]) + + return None + def selectEditor(parent): """ Pick an editor (Scintilla or default) and return the object. @@ -43,6 +72,9 @@ class Editor(object): # Empty start self.SetText("") + def SetErrors(self,errors): + pass + #--------------------------------------------------------------------------- class EditorNormal(Editor): @@ -72,11 +104,34 @@ class EditorStc(Editor): # Call parent Editor.__init__(self,parent) + # Set variable for error style + self.errorstyle = 5 + self.control.StyleSetSpec(self.errorstyle, "fore:#FFFF0000,back:#FF0000") + def GetText(self): return self.control.GetText() def SetText(self, txt): self.control.SetText(txt) + def SetErrorLine(self,line): + line = line - 1 # Start at 0 in stc, but on screen count is 1 + pos = self.control.GetLineIndentPosition(line) + last = self.control.GetLineEndPosition(line) + self.control.StartStyling(pos,31) + self.control.SetStyling(last-pos,self.errorstyle) + + def ClearErrors(self): + self.control.ClearDocumentStyle() + + def SetErrors(self,errors): + if errors: + for el in errors: + nr = lineInError(el) + if nr: + self.SetErrorLine(nr) + else: + self.ClearErrors() + #--------------------------------------------------------------------------- diff --git a/gui/Gui/Mainwindow.py b/gui/Gui/Mainwindow.py index 6e3185a..006ece5 100644 --- a/gui/Gui/Mainwindow.py +++ b/gui/Gui/Mainwindow.py @@ -208,8 +208,11 @@ class MainWindow(wx.Frame): os.chdir(self.dirname) def RunScyther(self, mode): + # Clear errors before verification + self.editor.SetErrors(None) + # Verify spdl spdl = self.editor.GetText() - s = Scytherthread.ScytherRun(self,mode,spdl) + s = Scytherthread.ScytherRun(self,mode,spdl,self.editor.SetErrors) def OnVerify(self, event): self.RunScyther("verify") diff --git a/gui/Gui/Scytherthread.py b/gui/Gui/Scytherthread.py index bf27fef..36a5624 100644 --- a/gui/Gui/Scytherthread.py +++ b/gui/Gui/Scytherthread.py @@ -444,13 +444,14 @@ class ResultWindow(wx.Frame): class ScytherRun(object): - def __init__(self,mainwin,mode,spdl): + def __init__(self,mainwin,mode,spdl,errorcallback=None): self.mainwin = mainwin self.mode = mode self.spdl = spdl self.verified = False self.options = mainwin.settings.ScytherArguments(mode) + self.errorcallback=errorcallback self.main() def main(self): @@ -540,6 +541,8 @@ class ScytherRun(object): Verification process generated errors. Show them. """ + if self.errorcallback: + self.errorcallback(self.scyther.errors) title = "Scyther errors : %s" % self.mode errorwin = ErrorWindow(self.mainwin,title,errors=self.scyther.errors) errorwin.Center() diff --git a/gui/Scyther/Bin/scyther-linux b/gui/Scyther/Bin/scyther-linux index 695ad9d..3a74461 100755 Binary files a/gui/Scyther/Bin/scyther-linux and b/gui/Scyther/Bin/scyther-linux differ