- Errors now get a nice colour

This commit is contained in:
ccremers 2007-01-31 15:45:05 +00:00
parent c63b87c750
commit 6e82d585be
5 changed files with 64 additions and 3 deletions

View File

@ -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:

View File

@ -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()
#---------------------------------------------------------------------------

View File

@ -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")

View File

@ -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()

Binary file not shown.