Added drag'n'drop of functions and function blocks
authoredouard
Tue, 05 Apr 2011 18:58:15 +0200
changeset 523 99ba2e3949ed
parent 521 457578c31074
child 524 9a5fa6679a94
Added drag'n'drop of functions and function blocks
TextViewer.py
--- a/TextViewer.py	Tue Apr 05 15:18:35 2011 +0200
+++ b/TextViewer.py	Tue Apr 05 18:58:15 2011 +0200
@@ -217,10 +217,35 @@
             values = event.GetDragText()
         if isinstance(values, tuple):
             message = None
-            if values[1] in ["functionBlock", "program", "debug"]:
+            if values[1] in ["program", "debug"]:
                 event.SetDragText("")
-            elif values[1] == "function":
-                event.SetDragText(values[0])
+            elif values[1] in ["functionBlock", "function"]:
+                blockname = values[2]
+                if len(values) > 3:
+                    blockinputs = values[3]
+                else:
+                    blockinputs = None
+                if values[1] != "function": 
+                    if  blockname == "":
+                        dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
+                        if dialog.ShowModal() == wx.ID_OK:
+                            blockname = dialog.GetValue()
+                        else:
+                            return
+                        dialog.Destroy()
+                    if blockname.upper() in [name.upper() for name in self.Controler.GetProjectPouNames(self.Debug)]:
+                        message = _("\"%s\" pou already exists!")%blockname
+                    elif blockname.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]:
+                        message = _("\"%s\" element for this pou already exists!")%blockname
+                    else:
+                        self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
+                        self.ParentWindow.RefreshVariablePanel(self.TagName)
+                        self.RefreshVariableTree()
+                blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug)
+                hint = ',\n    '.join(
+                            [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
+                            [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
+                event.SetDragText(blockname+"(\n    "+hint+")")
             elif values[1] == "location":
                 pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
                 if len(values) > 2 and pou_type == "program":