--- a/DataTypeEditor.py Fri Sep 30 17:16:02 2011 +0200
+++ b/DataTypeEditor.py Sun Oct 09 19:51:14 2011 +0200
@@ -26,6 +26,7 @@
import wx.grid
import wx.gizmos
from plcopen.structures import IEC_KEYWORDS, TestIdentifier
+from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD
import re
@@ -261,7 +262,7 @@
parent.AddWindow(self.staticText2, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
parent.AddWindow(self.DirectlyBaseType, 1, border=5, flag=wx.GROW|wx.ALL)
parent.AddWindow(self.staticText3, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
- parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)
+ parent.AddWindow(self.DirectlyInitialValue, 1, border=5, flag=wx.ALL)
def _init_coll_SubrangePanelSizer_Items(self, parent):
parent.AddWindow(self.staticText4, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
@@ -299,7 +300,7 @@
def _init_coll_ArrayPanelRightSizer_Items(self, parent):
parent.AddWindow(self.staticText10, 1, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
- parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.GROW|wx.ALL)
+ parent.AddWindow(self.ArrayInitialValue, 1, border=5, flag=wx.ALL)
def _init_coll_StructurePanelSizer_Items(self, parent):
parent.AddWindow(self.staticText11, 0, border=5, flag=wx.ALL)
@@ -582,12 +583,18 @@
self.ArrayPanel.Hide()
self.StructurePanel.Hide()
self.CurrentPanel = "Directly"
- self.Errors = []
+ self.Highlights = []
self.Initializing = False
self.ParentWindow = window
self.Controler = controler
self.TagName = tagname
+
+ self.RefreshHighlightsTimer = wx.Timer(self, -1)
+ self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
+
+ def __del__(self):
+ self.RefreshHighlightsTimer.Stop()
def SetTagName(self, tagname):
self.TagName = tagname
@@ -921,63 +928,62 @@
self.ParentWindow.RefreshEditMenu()
#-------------------------------------------------------------------------------
-# Errors showing functions
+# Highlights showing functions
#-------------------------------------------------------------------------------
- def ClearErrors(self):
- self.Errors = []
+ def OnRefreshHighlightsTimer(self, event):
self.RefreshView()
-
- def AddShownError(self, infos, start, end):
- self.Errors.append((infos, start, end))
+ event.Skip()
+
+ def ClearHighlights(self, highlight_type=None):
+ if highlight_type is None:
+ self.Highlights = []
+ else:
+ self.Highlights = [(infos, start, end, highlight) for (infos, start, end, highlight) in self.Highlights if highlight != 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):
type_infos = self.Controler.GetDataTypeInfos(self.TagName)
- for infos, start, end in self.Errors:
+ for infos, start, end, highlight_type in self.Highlights:
if infos[0] == "base":
if type_infos["type"] == "Directly":
- self.DirectlyBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.DirectlyBaseType.SetForegroundColour(wx.RED)
+ self.DirectlyBaseType.SetBackgroundColour(highlight_type[0])
+ self.DirectlyBaseType.SetForegroundColour(highlight_type[1])
elif type_infos["type"] == "Subrange":
- self.SubrangeBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.SubrangeBaseType.SetForegroundColour(wx.RED)
+ self.SubrangeBaseType.SetBackgroundColour(highlight_type[0])
+ self.SubrangeBaseType.SetForegroundColour(highlight_type[1])
elif type_infos["type"] == "Array":
- self.ArrayBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.ArrayBaseType.SetForegroundColour(wx.RED)
+ self.ArrayBaseType.SetBackgroundColour(highlight_type[0])
+ self.ArrayBaseType.SetForegroundColour(highlight_type[1])
elif infos[0] == "lower":
- self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.SubrangeMaximum.SetForegroundColour(wx.RED)
+ self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
+ self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
elif infos[0] == "upper":
- self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.SubrangeMaximum.SetForegroundColour(wx.RED)
+ self.SubrangeMinimum.SetBackgroundColour(highlight_type[0])
+ self.SubrangeMaximum.SetForegroundColour(highlight_type[1])
elif infos[0] == "value":
listctrl = self.EnumeratedValues.GetListCtrl()
- listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
- listctrl.SetItemTextColour(infos[1], wx.RED)
+ 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], wx.Colour(255, 255, 0))
- listctrl.SetItemTextColour(infos[1], wx.RED)
+ 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":
- text = self.DirectlyInitialValue.GetValue()
- self.DirectlyInitialValue.SetValue(text[:start[1]])
- self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
- self.DirectlyInitialValue.AppendText(text[start[1]:end[1] + 1])
- self.DirectlyInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
- self.DirectlyInitialValue.AppendText(text[end[1] + 1:])
+ self.DirectlyInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
elif type_infos["type"] == "Subrange":
- self.SubrangeInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.SubrangeInitialValue.SetForegroundColour(wx.RED)
+ self.SubrangeInitialValue.SetBackgroundColour(highlight_type[0])
+ self.SubrangeInitialValue.SetForegroundColour(highlight_type[1])
elif type_infos["type"] == "Enumerated":
- self.EnumeratedInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
- self.EnumeratedInitialValue.SetForegroundColour(wx.RED)
+ self.EnumeratedInitialValue.SetBackgroundColour(highlight_type[0])
+ self.EnumeratedInitialValue.SetForegroundColour(highlight_type[1])
elif type_infos["type"] == "Array":
- text = self.ArrayInitialValue.GetValue()
- self.ArrayInitialValue.SetValue(text[:start[1]])
- self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.RED, wx.Colour(255, 255, 0)))
- self.ArrayInitialValue.AppendText(text[start[1]:end[1] + 1])
- self.ArrayInitialValue.SetDefaultStyle(wx.TextAttr(wx.BLACK, wx.WHITE))
- self.ArrayInitialValue.AppendText(text[end[1] + 1:])
+ self.ArrayInitialValue.SetStyle(start[1], end[1] + 1, wx.TextAttr(highlight_type[1], highlight_type[0]))
+