controls/VariablePanel.py
changeset 616 8a60ffcfd70b
parent 606 d65122c61eaf
child 623 e747685e4241
equal deleted inserted replaced
615:8baeb9dff775 616:8a60ffcfd70b
   218     
   218     
   219     def OnDropText(self, x, y, data):
   219     def OnDropText(self, x, y, data):
   220         x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
   220         x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
   221         col = self.ParentWindow.VariablesGrid.XToCol(x)
   221         col = self.ParentWindow.VariablesGrid.XToCol(x)
   222         row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
   222         row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
   223         if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   223         message = None
   224             if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
   224         element_type = self.ParentWindow.ElementType
   225                 return
   225         try:
   226             message = None
   226             values = eval(data)    
   227             if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
   227         except:
   228                 message = _("Can't give a location to a function block instance")
   228             message = _("Invalid value \"%s\" for variable grid element")%data
   229             elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
   229             values = None
   230                 message = _("Can only give a location to local or global variables")
   230         if not isinstance(values, TupleType):
   231             else:
   231             message = _("Invalid value \"%s\" for variable grid element")%data
   232                 try:
   232             values = None
   233                     values = eval(data)    
   233         if values is not None:
   234                 except:
   234             if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
   235                     message = _("Invalid value \"%s\" for location")%data
   235                 if self.ParentWindow.Table.GetColLabelValue(col, False) != "Location":
   236                     values = None
   236                     return
   237                 if not isinstance(values, TupleType):
   237                 if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
   238                     message = _("Invalid value \"%s\" for location")%data
   238                     message = _("Can't give a location to a function block instance")
   239                     values = None
   239                 elif self.ParentWindow.Table.GetValueByName(row, "Class") not in ["Local", "Global"]:
   240                 if values is not None and values[1] == "location":
   240                     message = _("Can only give a location to local or global variables")
       
   241                 elif values is not None and values[1] == "location":
   241                     location = values[0]
   242                     location = values[0]
   242                     variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
   243                     variable_type = self.ParentWindow.Table.GetValueByName(row, "Type")
   243                     base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
   244                     base_type = self.ParentWindow.Controler.GetBaseType(variable_type)
   244                     message = None
       
   245                     if location.startswith("%"):
   245                     if location.startswith("%"):
   246                         if base_type != values[2]:
   246                         if base_type != values[2]:
   247                             message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
   247                             message = _("Incompatible data types between \"%s\" and \"%s\"")%(values[2], variable_type)
   248                         else:
   248                         else:
   249                             self.ParentWindow.Table.SetValue(row, col, location)
   249                             self.ParentWindow.Table.SetValue(row, col, location)
   268                                     location = "%M" + location
   268                                     location = "%M" + location
   269                                 self.ParentWindow.Table.SetValue(row, col, location)
   269                                 self.ParentWindow.Table.SetValue(row, col, location)
   270                                 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
   270                                 self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
   271                                 self.ParentWindow.SaveValues()
   271                                 self.ParentWindow.SaveValues()
   272                             dialog.Destroy()
   272                             dialog.Destroy()
   273             if message is not None:
   273             elif (element_type not in ["config", "resource"] and values[1] == "Global" and self.ParentWindow.Filter in ["All", "Interface", "External"] or
   274                 wx.CallAfter(self.ShowMessage, message)
   274                   element_type in ["config", "resource"] and values[1] == "location"):
       
   275                 if values[1] == "location":
       
   276                     var_name = values[3]
       
   277                 else:
       
   278                     var_name = values[0]
       
   279                 tagname = self.ParentWindow.GetTagName()
       
   280                 if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
       
   281                     message = _("\"%s\" pou already exists!")%var_name
       
   282                 elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
       
   283                     var_infos = self.ParentWindow.DefaultValue.copy()
       
   284                     var_infos["Name"] = var_name
       
   285                     var_infos["Type"] = values[2]
       
   286                     if values[1] == "location":
       
   287                         var_infos["Class"] = "Global"
       
   288                         var_infos["Location"] = values[0]
       
   289                     else:
       
   290                         var_infos["Class"] = "External"
       
   291                     var_infos["Number"] = len(self.ParentWindow.Values)
       
   292                     self.ParentWindow.Values.append(var_infos)
       
   293                     self.ParentWindow.SaveValues()
       
   294                     self.ParentWindow.RefreshValues()
       
   295         
       
   296         if message is not None:
       
   297             wx.CallAfter(self.ShowMessage, message)
   275             
   298             
       
   299                 
   276     def ShowMessage(self, message):
   300     def ShowMessage(self, message):
   277         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   301         message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
   278         message.ShowModal()
   302         message.ShowModal()
   279         message.Destroy()
   303         message.Destroy()
   280 
   304 
   534     def __del__(self):
   558     def __del__(self):
   535         self.RefreshHighlightsTimer.Stop()
   559         self.RefreshHighlightsTimer.Stop()
   536     
   560     
   537     def SetTagName(self, tagname):
   561     def SetTagName(self, tagname):
   538         self.TagName = tagname
   562         self.TagName = tagname
       
   563     
       
   564     def GetTagName(self):
       
   565         return self.TagName
   539     
   566     
   540     def IsFunctionBlockType(self, name):
   567     def IsFunctionBlockType(self, name):
   541         bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   568         bodytype = self.Controler.GetEditedElementBodyType(self.TagName)
   542         pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   569         pouname, poutype = self.Controler.GetEditedElementType(self.TagName)
   543         if poutype != "function" and bodytype in ["ST", "IL"]:
   570         if poutype != "function" and bodytype in ["ST", "IL"]: