Adding support for drag'n dropping constant values
authorLaurent Bessard
Thu, 28 Jun 2012 12:00:45 +0200
changeset 716 2681a6da58d6
parent 715 6a3792a6bf7b
child 717 86a2d1786684
Adding support for drag'n dropping constant values
TextViewer.py
Viewer.py
controls/VariablePanel.py
--- a/TextViewer.py	Mon Jun 25 23:10:49 2012 +0200
+++ b/TextViewer.py	Thu Jun 28 12:00:45 2012 +0200
@@ -341,6 +341,8 @@
                         self.RefreshVariablePanel()
                         self.RefreshVariableTree()
                     event.SetDragText(var_name)
+            elif values[1] == "Constant":
+                event.SetDragText(values[0])
             elif values[3] == self.TagName:
                 self.ResetBuffer()
                 event.SetDragText(values[0])
--- a/Viewer.py	Mon Jun 25 23:10:49 2012 +0200
+++ b/Viewer.py	Thu Jun 28 12:00:45 2012 +0200
@@ -302,6 +302,8 @@
                         self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name)
                         self.ParentWindow.RefreshVariablePanel()
                     self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2])
+            elif values[1] == "Constant":
+                self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, values[0], None)
             elif values[3] == tagname:
                 if values[1] == "Output":
                     var_class = OUTPUT
@@ -1161,8 +1163,6 @@
                       instance["id"], len(connectors["inputs"]), 
                       connectors=connectors, executionControl=executionControl, 
                       executionOrder=specific_values["executionOrder"])
-        element.SetPosition(instance["x"], instance["y"])
-        element.SetSize(instance["width"], instance["height"])
         if isinstance(element, Comment):
             self.AddComment(element)
         else:
@@ -1185,6 +1185,8 @@
                 if output_connector.get("edge", "none") != "none":
                     connector.SetEdge(output_connector["edge"])
                 connector.SetPosition(wx.Point(*output_connector["position"]))
+        element.SetPosition(instance["x"], instance["y"])
+        element.SetSize(instance["width"], instance["height"])
         if selection is not None and selection[0].get(instance["id"], False):
             self.SelectInGroup(element)
 
--- a/controls/VariablePanel.py	Mon Jun 25 23:10:49 2012 +0200
+++ b/controls/VariablePanel.py	Thu Jun 28 12:00:45 2012 +0200
@@ -247,44 +247,51 @@
             values = None
         if values is not None:
             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
-                if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
-                    return
-                if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
-                    message = _("Can't give a location to a function block instance")
-                elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
-                    message = _("Can only give a location to local or global variables")
-                elif values is not None and values[1] == "location":
-                    location = values[0]
-                    variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
-                    base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
-                    if location.startswith("%"):
-                        if base_type != values[2]:
-                            message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
-                        else:
-                            self.ParentWindow.Table.SetValue(row, col, location)
-                            self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
-                            self.ParentWindow.SaveValues()
+                colname = self.ParentWindow.Table.GetColLabelValue(col, False)
+                if colname == "Location" and values[1] == "location":
+                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
+                        message = _("Can't give a location to a function block instance")
+                    elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
+                        message = _("Can only give a location to local or global variables")
                     else:
-                        if location[0].isdigit() and base_type != "BOOL":
-                            message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
-                        elif location[0] not in LOCATIONDATATYPES:
-                            message = _("Unrecognized data size \"%s\"")%location[0]
-                        elif base_type not in LOCATIONDATATYPES[location[0]]:
-                            message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
-                        else:
-                            dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL)
-                            if dialog.ShowModal() == wx.ID_OK:
-                                selected = dialog.GetSelection()
-                                if selected == 0:
-                                    location = "%I" + location
-                                elif selected == 1:
-                                    location = "%Q" + location
-                                else:
-                                    location = "%M" + location
+                        location = values[0]
+                        variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
+                        base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
+                        if location.startswith("%"):
+                            if base_type != values[2]:
+                                message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
+                            else:
                                 self.ParentWindow.Table.SetValue(row, col, location)
                                 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
                                 self.ParentWindow.SaveValues()
-                            dialog.Destroy()
+                        else:
+                            if location[0].isdigit() and base_type != "BOOL":
+                                message = _("Incompatible size of data between \"%s\" and \"BOOL\"")%location
+                            elif location[0] not in LOCATIONDATATYPES:
+                                message = _("Unrecognized data size \"%s\"")%location[0]
+                            elif base_type not in LOCATIONDATATYPES[location[0]]:
+                                message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
+                            else:
+                                dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Select a variable class:"), _("Variable class"), ["Input", "Output", "Memory"], wx.OK|wx.CANCEL)
+                                if dialog.ShowModal() == wx.ID_OK:
+                                    selected = dialog.GetSelection()
+                                    if selected == 0:
+                                        location = "%I" + location
+                                    elif selected == 1:
+                                        location = "%Q" + location
+                                    else:
+                                        location = "%M" + location
+                                    self.ParentWindow.Table.SetValue(row, col, location)
+                                    self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
+                                    self.ParentWindow.SaveValues()
+                                dialog.Destroy()
+                elif colname == "Initial Value" and values[1] == "Constant":
+                    if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
+                        message = _("Can't set an initial value to a function block instance")
+                    else:
+                        self.ParentWindow.Table.SetValue(row, col, values[0])
+                        self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
+                        self.ParentWindow.SaveValues()
             elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or
                   element_type in ["config", "resource"] and values[1] == "location"):
                 if values[1] == "location":