DataTypeEditor.py
changeset 576 3f2024f30553
parent 566 6014ef82a98a
child 577 9dbb79722fbc
--- a/DataTypeEditor.py	Wed Oct 12 15:08:47 2011 +0200
+++ b/DataTypeEditor.py	Wed Oct 12 23:47:48 2011 +0200
@@ -57,7 +57,7 @@
         self.data = data
         self.old_value = None
         self.colnames = colnames
-        self.Errors = {}
+        self.Highlights = {}
         self.Parent = parent
         # XXX
         # we need to store the row length and collength to
@@ -148,6 +148,7 @@
         """
         
         for row in range(self.GetNumberRows()):
+            row_highlights = self.Highlights.get(row, {})
             for col in range(self.GetNumberCols()):
                 editor = None
                 renderer = None
@@ -168,13 +169,14 @@
                 grid.SetCellEditor(row, col, editor)
                 grid.SetCellRenderer(row, col, renderer)
                 
-                if self.Errors.has_key(row) 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:
+                grid.SetRowMinimalHeight(row, 28)
+            grid.AutoSizeRow(row, False)
     
     def SetData(self, data):
         self.data = data
@@ -202,11 +204,25 @@
         self.data = []
         self.editors = []
 
-    def AddError(self, infos):
-        self.Errors[infos[0]] = infos[1:]
-
-    def ClearErrors(self):
-        self.Errors = {}
+    def AddHighlight(self, infos, highlight_type):
+        row_highlights = self.Highlights.setdefault(infos[0], {})
+        if infos[1] == "initial":
+            col_highlights = row_highlights.setdefault("initial value", [])
+        else:
+            col_highlights = row_highlights.setdefault(infos[1], [])
+        col_highlights.append(highlight_type)
+
+    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)
 
 #-------------------------------------------------------------------------------
 #                          Datatype Editor class
@@ -383,6 +399,7 @@
         self.DirectlyBaseType = wx.ComboBox(id=ID_DATATYPEEDITORDIRECTLYBASETYPE, 
               name='DirectlyBaseType', parent=self.DirectlyPanel, pos=wx.Point(0, 0),
               size=wx.Size(0, 28), style=wx.CB_READONLY)
+        self.DirectlyBaseType.SetBackgroundColour(wx.BLUE)
         self.Bind(wx.EVT_COMBOBOX, self.OnInfosChanged, id=ID_DATATYPEEDITORDIRECTLYBASETYPE)
 
         self.staticText3 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT3,
@@ -407,6 +424,7 @@
         self.SubrangeBaseType = wx.ComboBox(id=ID_DATATYPEEDITORSUBRANGEBASETYPE, 
               name='SubrangeBaseType', parent=self.SubrangePanel, pos=wx.Point(0, 0),
               size=wx.Size(0, 28), style=wx.CB_READONLY)
+        self.SubrangeBaseType.SetBackgroundColour(wx.BLUE)
         self.Bind(wx.EVT_COMBOBOX, self.OnSubrangeBaseTypeChanged, id=ID_DATATYPEEDITORSUBRANGEBASETYPE)
 
         self.staticText5 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT5,
@@ -590,6 +608,20 @@
         self.Controler = controler
         self.TagName = tagname
         
+        self.HighlightControls = {
+            ("Directly", "base"): self.DirectlyBaseType,
+            ("Directly", "initial"): self.DirectlyInitialValue,
+            ("Subrange", "base"): self.SubrangeBaseType,
+            ("Subrange", "lower"): self.SubrangeMinimum,
+            ("Subrange", "upper"): self.SubrangeMaximum,
+            ("Subrange", "initial"): self.SubrangeInitialValue,
+            ("Enumerated", "value"): self.EnumeratedValues,
+            ("Enumerated", "initial"): self.EnumeratedInitialValue,
+            ("Array", "initial"): self.ArrayInitialValue,
+            ("Array", "base"): self.ArrayBaseType,
+            ("Array", "range"): self.ArrayDimensions,
+        }
+        
         self.RefreshHighlightsTimer = wx.Timer(self, -1)
         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
         
@@ -655,9 +687,9 @@
                 self.ArrayInitialValue.SetValue(type_infos["initial"])
             elif type_infos["type"] == "Structure":
                 self.StructureElementsTable.SetData(type_infos["elements"])
-                self.StructureElementsTable.ResetView(self.StructureElementsGrid)
             self.RefreshDisplayedInfos()
-        self.ShowErrors()
+        self.ShowHighlights()
+        self.StructureElementsTable.ResetView(self.StructureElementsGrid)
         self.Initializing = False
 
     def RefreshScaling(self, refresh=True):
@@ -940,50 +972,41 @@
             self.Highlights = []
         else:
             self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != highlight_type]
+        for control in self.HighlightControls.itervalues():
+            if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
+                control.SetBackgroundColour(wx.NullColour)
+                control.SetForegroundColour(wx.NullColour)
+            elif isinstance(control, wx.TextCtrl):
+                value = control.GetValue()
+                control.SetStyle(0, len(value), wx.TextAttr(wx.NullColour))
+            elif isinstance(control, wx.gizmos.EditableListBox):
+                listctrl = control.GetListCtrl()
+                for i in xrange(listctrl.GetItemCount()):
+                    listctrl.SetItemBackgroundColour(i, wx.NullColour)
+                    listctrl.SetItemTextColour(i, wx.NullColour)
+        self.StructureElementsTable.ClearHighlights(highlight_type)
         self.RefreshView()
 
     def AddHighlight(self, infos, start, end ,highlight_type):
         self.Highlights.append((infos, start, end, highlight_type))
         self.RefreshHighlightsTimer.Start(int(REFRESH_HIGHLIGHT_PERIOD * 1000), oneShot=True)
 
-    def ShowErrors(self):
+    def ShowHighlights(self):
         type_infos = self.Controler.GetDataTypeInfos(self.TagName)
         for infos, start, end, highlight_type in self.Highlights:
-            if infos[0] == "base":
-                if type_infos["type"] == "Directly":
-                    self.DirectlyBaseType.SetBackgroundColour(highlight_type[0])
-                    self.DirectlyBaseType.SetForegroundColour(highlight_type[1])
-                elif type_infos["type"] == "Subrange":
-                    self.SubrangeBaseType.SetBackgroundColour(highlight_type[0])
-                    self.SubrangeBaseType.SetForegroundColour(highlight_type[1])
-                elif type_infos["type"] == "Array":
-                    self.ArrayBaseType.SetBackgroundColour(highlight_type[0])
-                    self.ArrayBaseType.SetForegroundColour(highlight_type[1])
-            elif infos[0] == "lower":
-                self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
-                self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
-            elif infos[0] == "upper":
-                self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
-                self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
-            elif infos[0] == "value":
-                listctrl = self.EnumeratedValues.GetListCtrl()
-                listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
-                listctrl.SetItemTextColour(infos[1], highlight_type[1])
-                listctrl.Select(listctrl.FocusedItem, False)
-            elif infos[0] == "range":
-                listctrl = self.EnumeratedValues.GetListCtrl()
-                listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
-                listctrl.SetItemTextColour(infos[1], highlight_type[1])
-                listctrl.SetStringSelection("")
-            elif infos[0] == "initial":
-                if type_infos["type"] == "Directly":
-                    self.DirectlyInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
-                elif type_infos["type"] == "Subrange":
-                    self.SubrangeInitialValue.SetBackgroundColour(highlight_type[0])
-                    self.SubrangeInitialValue.SetForegroundColour(highlight_type[1])
-                elif type_infos["type"] == "Enumerated":
-                    self.EnumeratedInitialValue.SetBackgroundColour(highlight_type[0])
-                    self.EnumeratedInitialValue.SetForegroundColour(highlight_type[1])
-                elif type_infos["type"] == "Array":
-                    self.ArrayInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
-
+            if infos[0] == "struct":
+                self.StructureElementsTable.AddHighlight(infos[1:], highlight_type)
+            else:
+                control = self.HighlightControls.get((type_infos["type"], infos[0]), None)
+                if control is not None:
+                    if isinstance(control, (wx.ComboBox, wx.SpinCtrl)):
+                        control.SetBackgroundColour(highlight_type[0])
+                        control.SetForegroundColour(highlight_type[1])
+                    elif isinstance(control, wx.TextCtrl):
+                        control.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
+                    elif isinstance(control, wx.gizmos.EditableListBox):
+                        listctrl = control.GetListCtrl()
+                        listctrl.SetItemBackgroundColour(infos[1], highlight_type[0])
+                        listctrl.SetItemTextColour(infos[1], highlight_type[1])
+                        listctrl.Select(listctrl.FocusedItem, False)
+