# HG changeset patch # User edouard # Date 1302022695 -7200 # Node ID 99ba2e3949ed5ca763099c63202db1d74d724222 # Parent 457578c3107456a6ea648f8477eef989070d5824 Added drag'n'drop of functions and function blocks diff -r 457578c31074 -r 99ba2e3949ed 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":