--- a/editors/IECCodeViewer.py Tue Apr 23 23:02:35 2013 +0200
+++ b/editors/IECCodeViewer.py Wed Apr 24 00:20:13 2013 +0200
@@ -1,9 +1,13 @@
from editors.TextViewer import TextViewer
+from plcopen.plcopen import TestTextElement class IECCodeViewer(TextViewer):
if getattr(self, "_OnClose"):
\ No newline at end of file
+ def Search(self, criteria): + return [((self.TagName, "body", 0),) + result for result in TestTextElement(self.Editor.GetText(), criteria)] \ No newline at end of file
--- a/editors/TextViewer.py Tue Apr 23 23:02:35 2013 +0200
+++ b/editors/TextViewer.py Wed Apr 24 00:20:13 2013 +0200
@@ -764,6 +764,9 @@
+ def Search(self, criteria): + return self.Controler.SearchInPou(self.TagName, criteria, self.Debug) def Find(self, direction, search_params):
if self.SearchParams != search_params:
self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT)
@@ -779,7 +782,8 @@
(infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)
for infos, start, end, text in
- self.Controler.SearchInPou(self.TagName, criteria, self.Debug)]
+ self.CurrentFindHighlight = None if len(self.SearchResults) > 0:
if self.CurrentFindHighlight is not None:
@@ -801,6 +805,8 @@
self.RemoveHighlight(*self.CurrentFindHighlight)
self.CurrentFindHighlight = None
+ print self.CurrentFindHighlight self.Controler.SetEditedElementText(self.TagName, self.GetText())
--- a/editors/Viewer.py Tue Apr 23 23:02:35 2013 +0200
+++ b/editors/Viewer.py Wed Apr 24 00:20:13 2013 +0200
@@ -3167,6 +3167,7 @@
blocks.append((block, (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)))
self.SearchResults.extend([infos for block, infos in blocks])
+ self.CurrentFindHighlight = None if len(self.SearchResults) > 0:
if self.CurrentFindHighlight is not None:
--- a/py_ext/PythonEditor.py Tue Apr 23 23:02:35 2013 +0200
+++ b/py_ext/PythonEditor.py Wed Apr 24 00:20:13 2013 +0200
@@ -1,9 +1,20 @@
+from plcopen.plcopen import TestTextElement +from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD +from editors.ConfTreeNodeEditor import ConfTreeNodeEditor -from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
+[STC_PYTHON_ERROR, STC_PYTHON_SEARCH_RESULT] = range(15, 17) + ERROR_HIGHLIGHT: STC_PYTHON_ERROR, + SEARCH_RESULT_HIGHLIGHT: STC_PYTHON_SEARCH_RESULT, if wx.Platform == '__WXMSW__':
faces = { 'times': 'Times New Roman',
@@ -155,39 +166,43 @@
# The rest remains unchanged.
- self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_LINENUMBER,'fore:#000000,back:#99A9C2') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_BRACELIGHT,'fore:#00009D,back:#FFFF00') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_BRACEBAD,'fore:#00009D,back:#FF0000') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD")
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_STYLE_INDENTGUIDE, "fore:#CDCDCD") - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#000000')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_DEFAULT, 'fore:#000000') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_COMMENTLINE, 'fore:#008000,back:#F0FFF0')
- self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_COMMENTLINE, 'fore:#008000,back:#F0FFF0') + self.PythonCodeEditor.StyleSetSpec(stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#008080')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_NUMBER, 'fore:#008080') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#800080')
- self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#800080')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_STRING, 'fore:#800080') + self.PythonCodeEditor.StyleSetSpec(stc.STC_P_CHARACTER, 'fore:#800080') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#000080,bold')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_WORD, 'fore:#000080,bold') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA')
- self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA') + self.PythonCodeEditor.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#0000FF,bold')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_CLASSNAME, 'fore:#0000FF,bold') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#008080,bold')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_DEFNAME, 'fore:#008080,bold') - self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#800000,bold')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_OPERATOR, 'fore:#800000,bold') # Identifiers. I leave this as not bold because everything seems
# to be an identifier if it doesn't match the above criterae
- self.PythonCodeEditor.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#000000')
+ self.PythonCodeEditor.StyleSetSpec(stc.STC_P_IDENTIFIER, 'fore:#000000') + self.PythonCodeEditor.StyleSetSpec(STC_PYTHON_ERROR, "fore:#FF0000,back:#FFFF00") + self.PythonCodeEditor.StyleSetSpec(STC_PYTHON_SEARCH_RESULT, "fore:#FFFFFF,back:#FFA500") self.PythonCodeEditor.SetCaretForeground("BLUE")
@@ -219,13 +234,13 @@
# EOL: Since we are loading/saving ourselves, and the
# strings will always have \n's in them, set the STC to
- self.PythonCodeEditor.SetEOLMode(wx.stc.STC_EOL_LF)
+ self.PythonCodeEditor.SetEOLMode(stc.STC_EOL_LF) self.PythonCodeEditor.SetViewEOL(False)
# No right-edge mode indicator
self.PythonCodeEditor.SetEdgeMode(stc.STC_EDGE_NONE)
- self.PythonCodeEditor.SetModEventMask(wx.stc.STC_MOD_BEFOREINSERT|wx.stc.STC_MOD_BEFOREDELETE)
+ self.PythonCodeEditor.SetModEventMask(stc.STC_MOD_BEFOREINSERT|stc.STC_MOD_BEFOREDELETE) self.PythonCodeEditor.Bind(wx.stc.EVT_STC_DO_DROP, self.OnDoDrop, id=ID_PYTHONEDITOR)
self.PythonCodeEditor.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
@@ -239,6 +254,14 @@
self.DisableEvents = False
self.CurrentAction = None
+ self.SearchParams = None + self.SearchResults = None + self.CurrentFindHighlight = None + self.RefreshHighlightsTimer = wx.Timer(self, -1) + self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer) def GetBufferState(self):
return self.Controler.GetBufferState()
@@ -318,6 +341,8 @@
self.DisableEvents = False
self.PythonCodeEditor.Colourise(0, -1)
self.Controler.SetPythonCode(self.PythonCodeEditor.GetText())
@@ -483,3 +508,89 @@
self.DisableEvents = False
+ def Find(self, direction, search_params): + if self.SearchParams != search_params: + self.ClearHighlights(SEARCH_RESULT_HIGHLIGHT) + self.SearchParams = search_params + "raw_pattern": search_params["find_pattern"], + "pattern": re.compile(search_params["find_pattern"]), + "case_sensitive": search_params["case_sensitive"], + "regular_expression": search_params["regular_expression"], + (start, end, SEARCH_RESULT_HIGHLIGHT) + for start, end, text in + TestTextElement(self.PythonCodeEditor.GetText(), criteria)] + self.CurrentFindHighlight = None + if len(self.SearchResults) > 0: + if self.CurrentFindHighlight is not None: + old_idx = self.SearchResults.index(self.CurrentFindHighlight) + if self.SearchParams["wrap"]: + idx = (old_idx + direction) % len(self.SearchResults) + idx = max(0, min(old_idx + direction, len(self.SearchResults) - 1)) + self.RemoveHighlight(*self.CurrentFindHighlight) + self.CurrentFindHighlight = self.SearchResults[idx] + self.AddHighlight(*self.CurrentFindHighlight) + self.CurrentFindHighlight = self.SearchResults[0] + self.AddHighlight(*self.CurrentFindHighlight) + if self.CurrentFindHighlight is not None: + self.RemoveHighlight(*self.CurrentFindHighlight) + self.CurrentFindHighlight = None +#------------------------------------------------------------------------------- +# Highlights showing functions +#------------------------------------------------------------------------------- + def OnRefreshHighlightsTimer(self, event): + def ClearHighlights(self, highlight_type=None): + if highlight_type is None: + highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) + if highlight_type is not None: + self.Highlights = [(start, end, highlight) for (start, end, highlight) in self.Highlights if highlight != highlight_type] + def AddHighlight(self, start, end, highlight_type): + highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) + if highlight_type is not None: + self.Highlights.append((start, end, highlight_type)) + self.PythonCodeEditor.GotoPos(self.PythonCodeEditor.PositionFromLine(start[0]) + start[1]) + self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) + def RemoveHighlight(self, start, end, highlight_type): + highlight_type = HIGHLIGHT_TYPES.get(highlight_type, None) + if (highlight_type is not None and + (start, end, highlight_type) in self.Highlights): + self.Highlights.remove((start, end, highlight_type)) + self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True) + def ShowHighlights(self): + for start, end, highlight_type in self.Highlights: + highlight_start_pos = start[1] + highlight_start_pos = self.PythonCodeEditor.GetLineEndPosition(start[0] - 1) + start[1] + 1 + highlight_end_pos = end[1] - indent + 1 + highlight_end_pos = self.PythonCodeEditor.GetLineEndPosition(end[0] - 1) + end[1] + 2 + self.PythonCodeEditor.StartStyling(highlight_start_pos, 0xff) + self.PythonCodeEditor.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type) + self.PythonCodeEditor.StartStyling(highlight_start_pos, 0x00) + self.PythonCodeEditor.SetStyling(len(self.PythonCodeEditor.GetText()) - highlight_end_pos, stc.STC_STYLE_DEFAULT)