--- 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.VariableName = None @@ -75,6 +76,8 @@
def SetValue(self, value):
+ self.VariableName = None self.Location.SetValue(value)
@@ -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"]
@@ -176,11 +179,18 @@
name = self.CellControl.GetName()
- old_name = self.Table.GetValueByName(row, 'Name')
- self.Table.SetValueByName(row, 'Name', name)
- self.Table.Parent.OnVariableNameChange(old_name, name)
+ message = self.Table.Parent.CheckVariableName(name, row) + if message is not None: + wx.CallAfter(self.Table.Parent.ShowErrorMessage, message) + 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()
--- 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 def OnVariablesGridCellChange(self, event):
row, col = event.GetRow(), event.GetCol()
colname = self.Table.GetColLabelValue(col, False)
@@ -804,15 +818,8 @@
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
+ message = self.CheckVariableName(value, row) old_value = self.Table.GetOldValue()
self.OnVariableNameChange(old_value, value)