LocationCellEditor now systematically change variable name according to name given by CTN, calls VariablePanel' OnVariableNameChange to update POU accordingly.
--- a/controls/LocationCellEditor.py Thu Mar 28 14:06:53 2019 +0100
+++ b/controls/LocationCellEditor.py Tue Apr 02 09:46:58 2019 +0200
@@ -80,6 +80,9 @@
def GetValue(self):
return self.Location.GetValue()
+ def GetName(self):
+ return self.VariableName
+
def OnSize(self, event):
self.Layout()
@@ -118,6 +121,7 @@
location = "%M" + location
self.Location.SetValue(location)
+ self.VariableName = infos["name"]
self.VarType = infos["IEC_type"]
self.Location.SetFocus()
@@ -171,6 +175,10 @@
loc = self.CellControl.GetValue()
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)
self.Table.SetValueByName(row, 'Location', loc)
self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
self.CellControl.Disable()
--- a/controls/VariablePanel.py Thu Mar 28 14:06:53 2019 +0100
+++ b/controls/VariablePanel.py Tue Apr 02 09:46:58 2019 +0200
@@ -150,6 +150,7 @@
return value
def SetValue(self, row, col, value):
+ print("SetValue",row, col, value)
if col < len(self.colnames):
colname = self.GetColLabelValue(col, False)
if colname == "Name":
@@ -788,6 +789,14 @@
dialog.ShowModal()
dialog.Destroy()
+ def OnVariableNameChange(self, old_name, new_name):
+ """ propagate renaming of variable to the rest of the project """
+ if old_name != "":
+ self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_name, new_name)
+ self.Controler.BufferProject()
+ wx.CallAfter(self.ParentWindow.RefreshView, False)
+ self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+
def OnVariablesGridCellChange(self, event):
row, col = event.GetRow(), event.GetCol()
colname = self.Table.GetColLabelValue(col, False)
@@ -806,11 +815,7 @@
else:
self.SaveValues(False)
old_value = self.Table.GetOldValue()
- if old_value != "":
- self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
- self.Controler.BufferProject()
- wx.CallAfter(self.ParentWindow.RefreshView, False)
- self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+ self.OnVariableNameChange(old_value, value)
else:
self.SaveValues()
if colname == "Class":