--- a/DataTypeEditor.py Tue Aug 12 18:15:35 2008 +0200
+++ b/DataTypeEditor.py Tue Aug 12 18:16:09 2008 +0200
@@ -25,7 +25,7 @@
import wx
import wx.grid
import wx.gizmos
-from plcopen.structures import GetDataTypeRange, IEC_KEYWORDS
+from plcopen.structures import IEC_KEYWORDS
import re
@@ -165,7 +165,7 @@
self.staticbox = wx.StaticBox(id=ID_DATATYPEEDITORSTATICBOX,
label='Type infos:', name='staticBox1', parent=self,
- pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
+ pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0)
self.staticText1 = wx.StaticText(id=ID_DATATYPEEDITORSTATICTEXT1,
label='Derivation Type:', name='staticText1', parent=self,
@@ -197,8 +197,8 @@
self.DirectlyInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE,
name='DirectlyInitialValue', parent=self.DirectlyPanel, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER)
- self.Bind(wx.EVT_TEXT_ENTER, self.OnInfosChanged, id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE)
+ size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH)
+ self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORDIRECTLYINITIALVALUE)
# Panel for Subrange data types
@@ -296,8 +296,8 @@
self.ArrayInitialValue = wx.TextCtrl(id=ID_DATATYPEEDITORARRAYINITIALVALUE,
name='ArrayInitialValue', parent=self.ArrayPanel, pos=wx.Point(0, 0),
- size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER)
- self.Bind(wx.EVT_TEXT_ENTER, self.OnInfosChanged, id=ID_DATATYPEEDITORARRAYINITIALVALUE)
+ size=wx.Size(0, 24), style=wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.TE_MULTILINE|wx.TE_RICH)
+ self.Bind(wx.EVT_TEXT_ENTER, self.OnReturnKeyPressed, id=ID_DATATYPEEDITORARRAYINITIALVALUE)
self._init_sizers()
@@ -312,6 +312,7 @@
self.EnumeratedPanel.Hide()
self.ArrayPanel.Hide()
self.CurrentPanel = "Directly"
+ self.Errors = []
self.Initializing = False
self.ParentWindow = window
@@ -371,7 +372,7 @@
self.DirectlyBaseType.SetSelection(0)
self.SubrangeBaseType.Clear()
words = self.TagName.split("::")
- for base_type in self.Controler.GetSubrangeTypes():
+ for base_type in self.Controler.GetSubrangeBaseTypes(words[1]):
self.SubrangeBaseType.Append(base_type)
self.SubrangeBaseType.SetSelection(0)
self.RefreshBoundsRange()
@@ -400,6 +401,7 @@
self.ArrayDimensions.SetStrings(map(lambda x : "..".join(map(str, x)), type_infos["dimensions"]))
self.ArrayInitialValue.SetValue(type_infos["initial"])
self.RefreshDisplayedInfos()
+ self.ShowErrors()
self.Initializing = False
def RefreshScaling(self, refresh=True):
@@ -410,6 +412,9 @@
self.RefreshTypeInfos()
event.Skip()
+ def OnReturnKeyPressed(self, event):
+ self.RefreshTypeInfos()
+
def OnInfosChanged(self, event):
self.RefreshTypeInfos()
event.Skip()
@@ -468,7 +473,7 @@
self.EnumeratedInitialValue.SetStringSelection(selected)
def RefreshBoundsRange(self):
- range = GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
+ range = self.Controler.GetDataTypeRange(self.SubrangeBaseType.GetStringSelection())
if range is not None:
min_value, max_value = range
self.SubrangeMinimum.SetRange(min_value, max_value)
@@ -521,3 +526,64 @@
self.ParentWindow.RefreshTitle()
self.ParentWindow.RefreshEditMenu()
+#-------------------------------------------------------------------------------
+# Errors showing functions
+#-------------------------------------------------------------------------------
+
+ def ClearErrors(self):
+ self.Errors = []
+ self.RefreshView()
+
+ def AddShownError(self, infos, start, end):
+ self.Errors.append((infos, start, end))
+
+ def ShowErrors(self):
+ type_infos = self.Controler.GetDataTypeInfos(self.TagName)
+ for infos, start, end in self.Errors:
+ if infos[0] == "base":
+ if type_infos["type"] == "Directly":
+ self.DirectlyBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.DirectlyBaseType.SetForegroundColour(wx.RED)
+ elif type_infos["type"] == "Subrange":
+ self.SubrangeBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.SubrangeBaseType.SetForegroundColour(wx.RED)
+ elif type_infos["type"] == "Array":
+ self.ArrayBaseType.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.ArrayBaseType.SetForegroundColour(wx.RED)
+ elif infos[0] == "lower":
+ self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.SubrangeMaximum.SetForegroundColour(wx.RED)
+ elif infos[0] == "upper":
+ self.SubrangeMinimum.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.SubrangeMaximum.SetForegroundColour(wx.RED)
+ elif infos[0] == "value":
+ listctrl = self.EnumeratedValues.GetListCtrl()
+ listctrl.SetItemBackgroundColour(infos[1], wx.Colour(255, 255, 0))
+ listctrl.SetItemTextColour(infos[1], wx.RED)
+ 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.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:])
+ elif type_infos["type"] == "Subrange":
+ self.SubrangeInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.SubrangeInitialValue.SetForegroundColour(wx.RED)
+ elif type_infos["type"] == "Enumerated":
+ self.EnumeratedInitialValue.SetBackgroundColour(wx.Colour(255, 255, 0))
+ self.EnumeratedInitialValue.SetForegroundColour(wx.RED)
+ 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:])