RessourceEditor.py
changeset 566 6014ef82a98a
parent 564 5024d42e1050
child 573 0a6b2e1f8ce3
--- a/RessourceEditor.py	Fri Sep 30 17:16:02 2011 +0200
+++ b/RessourceEditor.py	Sun Oct 09 19:51:14 2011 +0200
@@ -101,7 +101,7 @@
         wx.grid.PyGridTableBase.__init__(self)
         self.data = data
         self.colnames = colnames
-        self.Errors = {}
+        self.Highlights = {}
         self.Parent = parent
         
         self.ColAlignements = []
@@ -210,6 +210,7 @@
             grid.SetColSize(col, self.ColSizes[col])
         
         for row in range(self.GetNumberRows()):
+            row_highlights = self.Highlights.get(row, {})
             for col in range(self.GetNumberCols()):
                 editor = None
                 renderer = None
@@ -244,13 +245,9 @@
                 grid.SetCellEditor(row, col, editor)
                 grid.SetCellRenderer(row, col, renderer)
                 
-                if row in self.Errors and self.Errors[row][0] == colname.lower():
-                    grid.SetCellBackgroundColour(row, col, wx.Colour(255, 255, 0))
-                    grid.SetCellTextColour(row, col, wx.RED)
-                    grid.MakeCellVisible(row, col)
-                else:
-                    grid.SetCellTextColour(row, col, wx.BLACK)
-                    grid.SetCellBackgroundColour(row, col, wx.WHITE)
+                highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
+                grid.SetCellBackgroundColour(row, col, highlight_colours[0])
+                grid.SetCellTextColour(row, col, highlight_colours[1])
             if wx.Platform == '__WXMSW__':
                 grid.SetRowMinimalHeight(row, 20)
             else:
@@ -289,11 +286,31 @@
         self.data = []
         self.editors = []
 
-    def AddError(self, infos):
-        self.Errors[infos[0]] = infos[1:]
-
-    def ClearErrors(self):
-        self.Errors = {}
+#-------------------------------------------------------------------------------
+#                        Highlights showing functions
+#-------------------------------------------------------------------------------
+
+    def OnRefreshHighlightsTimer(self, event):
+        self.Table.ResetView(self.VariablesGrid)
+        event.Skip()
+
+    def AddHighlight(self, infos, highlight_type):
+        row_highlights = self.Highlights.setdefault(infos[0], {})
+        col_highlights = row_highlights.setdefault(infos[1], [])
+        col_highlights.append(highlight_type)
+        self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
+
+    def ClearHighlights(self, highlight_type=None):
+        if highlight_type is None:
+            self.Highlights = {}
+        else:
+            for row, row_highlights in self.Highlights.iteritems():
+                row_items = row_highlights.items()
+                for col, col_highlights in row_items:
+                    if highlight_type in col_highlights:
+                        col_highlights.remove(highlight_type)
+                    if len(col_highlights) == 0:
+                        row_highlights.pop(col)
 
 [ID_RESOURCEEDITOR, ID_RESOURCEEDITORSTATICTEXT1,
  ID_RESOURCEEDITORSTATICTEXT2, ID_RESOURCEEDITORINSTANCESGRID,
@@ -465,6 +482,9 @@
         self.Controler = controler
         self.TagName = tagname
         
+        self.RefreshHighlightsTimer = wx.Timer(self, -1)
+        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
+        
         self.TasksDefaultValue = {"Name" : "", "Triggering" : "", "Single" : "", "Interval" : "", "Priority" : 0}
         self.TasksTable = ResourceTable(self, [], GetTasksTableColnames())
         self.TasksTable.SetColAlignements([wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT])
@@ -481,6 +501,9 @@
         self.InstancesGrid.SetRowLabelSize(0)
         self.InstancesTable.ResetView(self.InstancesGrid)
 
+    def __del__(self):
+        self.RefreshHighlightsTimer.Stop()
+
     def SetTagName(self, tagname):
         self.TagName = tagname
         
@@ -668,21 +691,37 @@
         event.Skip()
 
 #-------------------------------------------------------------------------------
-#                        Errors showing functions
-#-------------------------------------------------------------------------------
-
-    def ClearErrors(self):
-        self.TasksTable.ClearErrors()
-        self.InstancesTable.ClearErrors()
+#                      Search result showing functions
+#-------------------------------------------------------------------------------
+
+    def AddShownSearchResult(self, infos, start, end):
+        if infos[0] == "task":
+            self.TasksTable.AddSearchResult(infos[1:])
+        elif infos[0] == "instance":
+            self.InstancesTable.AddSearchResult(infos[1:])
+
+    def ClearSearchResults(self):
+        self.TasksTable.ClearSearchResults()
+        self.InstancesTable.ClearSearchResults()
         self.TasksTable.ResetView(self.TasksGrid)
         self.InstancesTable.ResetView(self.InstancesGrid)
 
-    def AddShownError(self, infos, start, end):
+
+#-------------------------------------------------------------------------------
+#                        Highlights showing functions
+#-------------------------------------------------------------------------------
+
+    def AddHighlight(self, infos, start, end, highlight_type):
         if infos[0] == "task":
-            self.TasksTable.AddError(infos[1:])
+            self.TasksTable.AddHighlight(infos[1:], highlight_type)
         elif infos[0] == "instance":
-            self.InstancesTable.AddError(infos[1:])
-
+            self.InstancesTable.AddHighlight(infos[1:], highlight_type)
+
+    def ClearHighlights(self, highlight_type=None):
+        self.TasksTable.ClearHighlights(highlight_type)
+        self.InstancesTable.ClearHighlights(highlight_type)
+        self.TasksTable.ResetView(self.TasksGrid)
+        self.InstancesTable.ResetView(self.InstancesGrid)
 
 class DurationCellControl(wx.PyControl):