controls/VariablePanel.py
changeset 600 7db729686416
parent 595 15df411e9463
child 604 5b42b4401e6b
equal deleted inserted replaced
599:4bb7b132e15d 600:7db729686416
   205             row_highlights = self.Highlights.get(row, {})
   205             row_highlights = self.Highlights.get(row, {})
   206             for col in range(self.GetNumberCols()):
   206             for col in range(self.GetNumberCols()):
   207                 editor = None
   207                 editor = None
   208                 renderer = None
   208                 renderer = None
   209                 colname = self.GetColLabelValue(col, False)
   209                 colname = self.GetColLabelValue(col, False)
   210                 if colname == "Option":
   210                 if self.Parent.Debug:
   211                     options = GetOptions(constant = var_class in ["Local", "External", "Global"],
   211                     grid.SetReadOnly(row, col, True)
   212                                          retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   212                 else:
   213                                          non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   213                     if colname == "Option":
   214                     if len(options) > 1:
   214                         options = GetOptions(constant = var_class in ["Local", "External", "Global"],
   215                         editor = wx.grid.GridCellChoiceEditor()
   215                                              retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"],
   216                         editor.SetParameters(",".join(map(_, options)))
   216                                              non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"])
   217                     else:
   217                         if len(options) > 1:
   218                         grid.SetReadOnly(row, col, True)
   218                             editor = wx.grid.GridCellChoiceEditor()
   219                 elif col != 0 and self.GetValueByName(row, "Edit"):
   219                             editor.SetParameters(",".join(map(_, options)))
   220                     grid.SetReadOnly(row, col, False)
   220                         else:
   221                     if colname == "Name":
       
   222                         if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
       
   223                             grid.SetReadOnly(row, col, True)
   221                             grid.SetReadOnly(row, col, True)
   224                         else:
   222                     elif col != 0 and self.GetValueByName(row, "Edit"):
   225                             editor = wx.grid.GridCellTextEditor()
   223                         grid.SetReadOnly(row, col, False)
   226                             renderer = wx.grid.GridCellStringRenderer()
   224                         if colname == "Name":
   227                     elif colname == "Initial Value":
   225                             if self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
   228                         if var_class != "External":
   226                                 grid.SetReadOnly(row, col, True)
   229                             if self.Parent.Controler.IsEnumeratedType(var_type):
       
   230                                 editor = wx.grid.GridCellChoiceEditor()
       
   231                                 editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type)))
       
   232                             else:
   227                             else:
   233                                 editor = wx.grid.GridCellTextEditor()
   228                                 editor = wx.grid.GridCellTextEditor()
   234                             renderer = wx.grid.GridCellStringRenderer()
   229                                 renderer = wx.grid.GridCellStringRenderer()
   235                         else:
   230                         elif colname == "Initial Value":
   236                             grid.SetReadOnly(row, col, True)
   231                             if var_class != "External":
   237                     elif colname == "Location":
   232                                 if self.Parent.Controler.IsEnumeratedType(var_type):
   238                         if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type):
   233                                     editor = wx.grid.GridCellChoiceEditor()
   239                             editor = LocationCellEditor(self, self.Parent.Controler)
   234                                     editor.SetParameters(",".join(self.Parent.Controler.GetEnumeratedDataValues(var_type)))
   240                             renderer = wx.grid.GridCellStringRenderer()
   235                                 else:
   241                         else:
   236                                     editor = wx.grid.GridCellTextEditor()
   242                             grid.SetReadOnly(row, col, True)
   237                                 renderer = wx.grid.GridCellStringRenderer()
   243                     elif colname == "Class":
   238                             else:
   244                         if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
   239                                 grid.SetReadOnly(row, col, True)
   245                             grid.SetReadOnly(row, col, True)
   240                         elif colname == "Location":
   246                         else:
   241                             if var_class in ["Local", "Global"] and self.Parent.Controler.IsLocatableType(var_type):
   247                             editor = wx.grid.GridCellChoiceEditor()
   242                                 editor = LocationCellEditor(self, self.Parent.Controler)
   248                             excluded = []
   243                                 renderer = wx.grid.GridCellStringRenderer()
   249                             if self.Parent.PouIsUsed:
   244                             else:
   250                                 excluded.extend(["Input","Output","InOut"])
   245                                 grid.SetReadOnly(row, col, True)
   251                             if self.Parent.IsFunctionBlockType(var_type):
   246                         elif colname == "Class":
   252                                 excluded.extend(["Local","Temp"])
   247                             if len(self.Parent.ClassList) == 1 or self.Parent.PouIsUsed and var_class in ["Input", "Output", "InOut"]:
   253                             editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
   248                                 grid.SetReadOnly(row, col, True)
   254                 elif colname != "Documentation":
   249                             else:
   255                     grid.SetReadOnly(row, col, True)
   250                                 editor = wx.grid.GridCellChoiceEditor()
       
   251                                 excluded = []
       
   252                                 if self.Parent.PouIsUsed:
       
   253                                     excluded.extend(["Input","Output","InOut"])
       
   254                                 if self.Parent.IsFunctionBlockType(var_type):
       
   255                                     excluded.extend(["Local","Temp"])
       
   256                                 editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
       
   257                     elif colname != "Documentation":
       
   258                         grid.SetReadOnly(row, col, True)
   256                 
   259                 
   257                 grid.SetCellEditor(row, col, editor)
   260                 grid.SetCellEditor(row, col, editor)
   258                 grid.SetCellRenderer(row, col, renderer)
   261                 grid.SetCellRenderer(row, col, renderer)
   259                 
   262                 
   260                 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
   263                 highlight_colours = row_highlights.get(colname.lower(), [(wx.WHITE, wx.BLACK)])[-1]
   500               name='DownButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
   503               name='DownButton', parent=self.ControlPanel, pos=wx.Point(0, 0),
   501               size=wx.Size(28, 28), style=0)
   504               size=wx.Size(28, 28), style=0)
   502         
   505         
   503         self._init_sizers()
   506         self._init_sizers()
   504 
   507 
   505     def __init__(self, parent, window, controler, element_type):
   508     def __init__(self, parent, window, controler, element_type, debug=False):
   506         self._init_ctrls(parent)
   509         self._init_ctrls(parent)
   507         self.ParentWindow = window
   510         self.ParentWindow = window
   508         self.Controler = controler
   511         self.Controler = controler
   509         self.ElementType = element_type
   512         self.ElementType = element_type
       
   513         self.Debug = debug
   510         
   514         
   511         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   515         self.RefreshHighlightsTimer = wx.Timer(self, -1)
   512         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
   516         self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
   513         
   517         
   514         self.Filter = "All"
   518         self.Filter = "All"
   578         self.VariablesGrid.SetTable(self.Table)
   582         self.VariablesGrid.SetTable(self.Table)
   579         self.VariablesGrid.SetButtons({"Add": self.AddButton,
   583         self.VariablesGrid.SetButtons({"Add": self.AddButton,
   580                                        "Delete": self.DeleteButton,
   584                                        "Delete": self.DeleteButton,
   581                                        "Up": self.UpButton,
   585                                        "Up": self.UpButton,
   582                                        "Down": self.DownButton})
   586                                        "Down": self.DownButton})
       
   587         self.VariablesGrid.SetEditable(not self.Debug)
   583         
   588         
   584         def _AddVariable(new_row):
   589         def _AddVariable(new_row):
   585             if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]:
   590             if not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]:
   586                 row_content = self.DefaultValue.copy()
   591                 row_content = self.DefaultValue.copy()
   587                 if self.Filter in self.DefaultTypes:
   592                 if self.Filter in self.DefaultTypes:
   627             if table_length > 0:
   632             if table_length > 0:
   628                 row = self.VariablesGrid.GetGridCursorRow()
   633                 row = self.VariablesGrid.GetGridCursorRow()
   629                 row_edit = self.Table.GetValueByName(row, "Edit")
   634                 row_edit = self.Table.GetValueByName(row, "Edit")
   630                 if self.PouIsUsed:
   635                 if self.PouIsUsed:
   631                     row_class = self.Table.GetValueByName(row, "Class")
   636                     row_class = self.Table.GetValueByName(row, "Class")
   632             self.AddButton.Enable(not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"])
   637             self.AddButton.Enable(not self.Debug and (not self.PouIsUsed or self.Filter not in ["Interface", "Input", "Output", "InOut"]))
   633             self.DeleteButton.Enable(table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"])
   638             self.DeleteButton.Enable(not self.Debug and (table_length > 0 and row_edit and row_class not in ["Input", "Output", "InOut"]))
   634             self.UpButton.Enable(table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
   639             self.UpButton.Enable(not self.Debug and (table_length > 0 and row > 0 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
   635             self.DownButton.Enable(table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"])
   640             self.DownButton.Enable(not self.Debug and (table_length > 0 and row < table_length - 1 and self.Filter == "All" and row_class not in ["Input", "Output", "InOut"]))
   636         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
   641         setattr(self.VariablesGrid, "RefreshButtons", _RefreshButtons)
   637         
   642         
   638         self.VariablesGrid.SetRowLabelSize(0)
   643         self.VariablesGrid.SetRowLabelSize(0)
   639         for col in range(self.Table.GetNumberCols()):
   644         for col in range(self.Table.GetNumberCols()):
   640             attr = wx.grid.GridCellAttr()
   645             attr = wx.grid.GridCellAttr()
   656             return False
   661             return False
   657         else:
   662         else:
   658             return name in self.Controler.GetFunctionBlockTypes(self.TagName)
   663             return name in self.Controler.GetFunctionBlockTypes(self.TagName)
   659     
   664     
   660     def RefreshView(self):
   665     def RefreshView(self):
   661         self.PouNames = self.Controler.GetProjectPouNames()
   666         self.PouNames = self.Controler.GetProjectPouNames(self.Debug)
   662         
   667         
   663         words = self.TagName.split("::")
   668         words = self.TagName.split("::")
   664         if self.ElementType == "config":
   669         if self.ElementType == "config":
   665             self.PouIsUsed = False
   670             self.PouIsUsed = False
   666             returnType = None
   671             returnType = None
   667             self.Values = self.Controler.GetConfigurationGlobalVars(words[1])
   672             self.Values = self.Controler.GetConfigurationGlobalVars(words[1], self.Debug)
   668         elif self.ElementType == "resource":
   673         elif self.ElementType == "resource":
   669             self.PouIsUsed = False
   674             self.PouIsUsed = False
   670             returnType = None
   675             returnType = None
   671             self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2])
   676             self.Values = self.Controler.GetConfigurationResourceGlobalVars(words[1], words[2], self.Debug)
   672         else:
   677         else:
   673             if self.ElementType == "function":
   678             if self.ElementType == "function":
   674                 self.ReturnType.Clear()
   679                 self.ReturnType.Clear()
   675                 for base_type in self.Controler.GetDataTypes(self.TagName, True):
   680                 for base_type in self.Controler.GetDataTypes(self.TagName, True, debug=self.Debug):
   676                     self.ReturnType.Append(base_type)
   681                     self.ReturnType.Append(base_type)
   677                 returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
   682                 returnType = self.Controler.GetEditedElementInterfaceReturnType(self.TagName)
   678             else:
   683             else:
   679                 returnType = None
   684                 returnType = None
   680             self.PouIsUsed = self.Controler.PouIsUsed(words[1])
   685             self.PouIsUsed = self.Controler.PouIsUsed(words[1])
   681             self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName)
   686             self.Values = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
   682         
   687         
   683         if returnType is not None:
   688         if returnType is not None:
   684             self.ReturnType.SetStringSelection(returnType)
   689             self.ReturnType.SetStringSelection(returnType)
   685             self.ReturnType.Enable(True)
   690             self.ReturnType.Enable(self.Debug)
   686             self.staticText1.Show()
   691             self.staticText1.Show()
   687             self.ReturnType.Show()
   692             self.ReturnType.Show()
   688         else:
   693         else:
   689             self.ReturnType.Enable(False)
   694             self.ReturnType.Enable(False)
   690             self.staticText1.Hide()
   695             self.staticText1.Hide()
   842             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
   847             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
   843         dialog.Destroy()
   848         dialog.Destroy()
   844     
   849     
   845     def OnVariablesGridCellLeftClick(self, event):
   850     def OnVariablesGridCellLeftClick(self, event):
   846         row = event.GetRow()
   851         row = event.GetRow()
   847         if event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit"):
   852         if not self.Debug and (event.GetCol() == 0 and self.Table.GetValueByName(row, "Edit")):
   848             row = event.GetRow()
   853             row = event.GetRow()
   849             var_name = self.Table.GetValueByName(row, "Name")
   854             var_name = self.Table.GetValueByName(row, "Name")
   850             var_class = self.Table.GetValueByName(row, "Class")
   855             var_class = self.Table.GetValueByName(row, "Class")
   851             var_type = self.Table.GetValueByName(row, "Type")
   856             var_type = self.Table.GetValueByName(row, "Type")
   852             data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
   857             data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))