# HG changeset patch
# User Edouard Tisserant
# Date 1623310805 -7200
# Node ID 7278186a2083be7d78d887d4681b3df156e6e74f
# Parent  58f2e3f22934130263efc5ab437a8d2243cc8042
Copy description when DnD variables from CodeFile CTN to POUs

diff -r 58f2e3f22934 -r 7278186a2083 PLCControler.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:
diff -r 58f2e3f22934 -r 7278186a2083 editors/CodeFileEditor.py
--- 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()
diff -r 58f2e3f22934 -r 7278186a2083 editors/Viewer.py
--- 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])
diff -r 58f2e3f22934 -r 7278186a2083 plcopen/plcopen.py
--- 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=""):