Copy description when DnD variables from CodeFile CTN to POUs
authorEdouard Tisserant
Thu, 10 Jun 2021 09:40:05 +0200
changeset 2739 7278186a2083
parent 2738 58f2e3f22934
child 2740 610801fe1b88
Copy description when DnD variables from CodeFile CTN to POUs
PLCControler.py
editors/CodeFileEditor.py
editors/Viewer.py
plcopen/plcopen.py
--- a/PLCControler.py	Tue May 25 15:05:38 2021 +0200
+++ b/PLCControler.py	Thu Jun 10 09:40:05 2021 +0200
@@ -2049,14 +2049,15 @@
                         self.GetVarTypeObject(var_type),
                         name, **args)
 
-    def AddEditedElementPouExternalVar(self, tagname, var_type, name):
+    def AddEditedElementPouExternalVar(self, tagname, var_type, name, **args):
         if self.Project is not None:
             words = tagname.split("::")
             if words[0] in ['P', 'T', 'A']:
                 pou = self.Project.getpou(words[1])
                 if pou is not None:
                     pou.addpouExternalVar(
-                        self.GetVarTypeObject(var_type), name)
+                        self.GetVarTypeObject(var_type),
+                        name, **args)
 
     def ChangeEditedElementPouVar(self, tagname, old_type, old_name, new_type, new_name):
         if self.Project is not None:
--- a/editors/CodeFileEditor.py	Tue May 25 15:05:38 2021 +0200
+++ b/editors/CodeFileEditor.py	Thu Jun 10 09:40:05 2021 +0200
@@ -857,8 +857,9 @@
             row = event.GetRow()
             data_type = self.Table.GetValueByName(row, "Type")
             var_name = self.Table.GetValueByName(row, "Name")
+            desc = self.Table.GetValueByName(row, "Description")
             data = wx.TextDataObject(str((var_name, "Global", data_type,
-                                          self.Controler.GetCurrentLocation())))
+                                          self.Controler.GetCurrentLocation(), desc)))
             dragSource = wx.DropSource(self.VariablesGrid)
             dragSource.SetData(data)
             dragSource.DoDragDrop()
--- a/editors/Viewer.py	Tue May 25 15:05:38 2021 +0200
+++ b/editors/Viewer.py	Thu Jun 10 09:40:05 2021 +0200
@@ -389,7 +389,8 @@
                 elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
                     message = _("\"%s\" pou already exists!") % var_name
                 elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
-                    self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name)
+                    print(values) 
+                    self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name, description=values[4])
                     self.ParentWindow.RefreshVariablePanel()
                     self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
                     self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2])
--- a/plcopen/plcopen.py	Tue May 25 15:05:38 2021 +0200
+++ b/plcopen/plcopen.py	Thu Jun 10 09:40:05 2021 +0200
@@ -1393,8 +1393,8 @@
         self.interface.setcontent(vars)
     setattr(cls, "setvars", setvars)
 
-    def addpouExternalVar(self, var_type, name):
-        self.addpouVar(var_type, name, "externalVars")
+    def addpouExternalVar(self, var_type, name, **args):
+        self.addpouVar(var_type, name, "externalVars", **args)
     setattr(cls, "addpouExternalVar", addpouExternalVar)
 
     def addpouVar(self, var_type, name, var_class="localVars", location="", description="", initval=""):