--- a/DataTypeEditor.py Wed Apr 16 10:26:33 2008 +0200
+++ b/DataTypeEditor.py Tue Apr 22 10:25:24 2008 +0200
@@ -27,6 +27,10 @@
import wx.gizmos
from plcopen.structures import GetDataTypeRange, IEC_KEYWORDS
+import re
+
+DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
+
if wx.VERSION >= (2, 8, 0):
import wx.aui
@@ -393,7 +397,7 @@
self.EnumeratedInitialValue.SetStringSelection(type_infos["initial"])
elif type_infos["type"] == "Array":
self.ArrayBaseType.SetStringSelection(type_infos["base_type"])
- self.ArrayDimensions.SetStrings(type_infos["dimensions"])
+ self.ArrayDimensions.SetStrings(map(lambda x : "..".join(map(str, x)), type_infos["dimensions"]))
self.ArrayInitialValue.SetValue(type_infos["initial"])
self.RefreshDisplayedInfos()
self.Initializing = False
@@ -495,7 +499,23 @@
infos["initial"] = self.EnumeratedInitialValue.GetStringSelection()
elif selected == "Array":
infos["base_type"] = self.ArrayBaseType.GetStringSelection()
- infos["dimensions"] = self.ArrayDimensions.GetStrings()
+ infos["dimensions"] = []
+ for dimensions in self.ArrayDimensions.GetStrings():
+ result = DIMENSION_MODEL.match(dimensions)
+ if result is None:
+ message = wx.MessageDialog(self, "\"%s\" value isn't a valid array dimension!"%dimensions, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ self.RefreshView()
+ return
+ bounds = result.groups()
+ if bounds[0] >= bounds[1]:
+ message = wx.MessageDialog(self, "\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value."%dimensions, "Error", wx.OK|wx.ICON_ERROR)
+ message.ShowModal()
+ message.Destroy()
+ self.RefreshView()
+ return
+ infos["dimensions"].append(map(int, bounds))
infos["initial"] = self.ArrayInitialValue.GetValue()
self.Controler.SetDataTypeInfos(self.TagName, infos)
self.ParentWindow.RefreshTitle()