LocationCellEditor use better source for variable name replacement, and validate variable name before applying it or complains otherwise.
--- a/controls/LocationCellEditor.py Tue Apr 02 09:46:58 2019 +0200
+++ b/controls/LocationCellEditor.py Wed Apr 03 13:20:28 2019 +0200
@@ -60,6 +60,7 @@
self.Controller = None
self.VarType = None
self.Default = False
+ self.VariableName = None
def __del__(self):
self.Controller = None
@@ -75,6 +76,8 @@
def SetValue(self, value):
self.Default = value
+ self.VariableName = None
+ self.VarType = None
self.Location.SetValue(value)
def GetValue(self):
@@ -121,7 +124,7 @@
location = "%M" + location
self.Location.SetValue(location)
- self.VariableName = infos["name"]
+ self.VariableName = infos["var_name"]
self.VarType = infos["IEC_type"]
self.Location.SetFocus()
@@ -176,11 +179,18 @@
changed = loc != old_loc
if changed:
name = self.CellControl.GetName()
- old_name = self.Table.GetValueByName(row, 'Name')
- self.Table.SetValueByName(row, 'Name', name)
- self.Table.Parent.OnVariableNameChange(old_name, name)
+ if name is not None:
+ message = self.Table.Parent.CheckVariableName(name, row)
+ if message is not None:
+ wx.CallAfter(self.Table.Parent.ShowErrorMessage, message)
+ return None
+ old_name = self.Table.GetValueByName(row, 'Name')
+ self.Table.SetValueByName(row, 'Name', name)
+ self.Table.Parent.OnVariableNameChange(old_name, name)
self.Table.SetValueByName(row, 'Location', loc)
- self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
+ var_type = self.CellControl.GetVarType()
+ if var_type is not None:
+ self.Table.SetValueByName(row, 'Type', var_type)
self.CellControl.Disable()
return changed
--- a/controls/VariablePanel.py Tue Apr 02 09:46:58 2019 +0200
+++ b/controls/VariablePanel.py Wed Apr 03 13:20:28 2019 +0200
@@ -34,6 +34,7 @@
from six import string_types
from six.moves import xrange
+
from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
from plcopen.VariableInfoCollector import _VariableInfos
from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
@@ -797,6 +798,19 @@
wx.CallAfter(self.ParentWindow.RefreshView, False)
self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+ def CheckVariableName(self, value, row):
+ if not TestIdentifier(value):
+ message = _("\"%s\" is not a valid identifier!") % value
+ elif value.upper() in IEC_KEYWORDS:
+ message = _("\"%s\" is a keyword. It can't be used!") % value
+ elif value.upper() in self.PouNames:
+ message = _("A POU named \"%s\" already exists!") % value
+ elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]:
+ message = _("A variable with \"%s\" as name already exists in this pou!") % value
+ else:
+ return None
+ return message
+
def OnVariablesGridCellChange(self, event):
row, col = event.GetRow(), event.GetCol()
colname = self.Table.GetColLabelValue(col, False)
@@ -804,15 +818,8 @@
message = None
if colname == "Name" and value != "":
- if not TestIdentifier(value):
- message = _("\"%s\" is not a valid identifier!") % value
- elif value.upper() in IEC_KEYWORDS:
- message = _("\"%s\" is a keyword. It can't be used!") % value
- elif value.upper() in self.PouNames:
- message = _("A POU named \"%s\" already exists!") % value
- elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]:
- message = _("A variable with \"%s\" as name already exists in this pou!") % value
- else:
+ message = self.CheckVariableName(value, row)
+ if message is None:
self.SaveValues(False)
old_value = self.Table.GetOldValue()
self.OnVariableNameChange(old_value, value)