VariablePanel.py
changeset 483 779a519f78f2
parent 449 19720ee1051c
child 484 acef952101a5
equal deleted inserted replaced
482:4edbbab206a3 483:779a519f78f2
    47 #-------------------------------------------------------------------------------
    47 #-------------------------------------------------------------------------------
    48 
    48 
    49 def GetVariableTableColnames(location):
    49 def GetVariableTableColnames(location):
    50     _ = lambda x : x
    50     _ = lambda x : x
    51     if location:
    51     if location:
    52     	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
    52     	return ["#", _("Name"), _("Class"), _("Type"), _("Location"), _("Initial Value"), _("Option"), _("Documentation")]
    53     return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Retain"), _("Constant"), _("Documentation")]
    53     return ["#", _("Name"), _("Class"), _("Type"), _("Initial Value"), _("Option"), _("Documentation")]
    54 
    54 
    55 def GetAlternativeOptions():
    55 def GetOptions():
    56     _ = lambda x : x
    56     _ = lambda x : x
    57     return [_("Yes"), _("No")]
    57     return ["", _("Constant"), _("Retain"), _("Non-Retain")]
    58 ALTERNATIVE_OPTIONS_DICT = dict([(_(option), option) for option in GetAlternativeOptions()])
    58 OPTIONS_DICT = dict([(_(option), option) for option in GetOptions()])
    59 
    59 
    60 def GetFilterChoiceTransfer():
    60 def GetFilterChoiceTransfer():
    61     _ = lambda x : x
    61     _ = lambda x : x
    62     return {_("All"): _("All"), _("Interface"): _("Interface"), 
    62     return {_("All"): _("All"), _("Interface"): _("Interface"), 
    63             _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
    63             _("   Input"): _("Input"), _("   Output"): _("Output"), _("   InOut"): _("InOut"), 
   103         if row < self.GetNumberRows():
   103         if row < self.GetNumberRows():
   104             if col == 0:
   104             if col == 0:
   105                 return self.data[row]["Number"]
   105                 return self.data[row]["Number"]
   106             colname = self.GetColLabelValue(col, False)
   106             colname = self.GetColLabelValue(col, False)
   107             value = str(self.data[row].get(colname, ""))
   107             value = str(self.data[row].get(colname, ""))
   108             if colname in ["Class", "Retain", "Constant"]:
   108             if colname in ["Class", "Option"]:
   109                 return _(value)
   109                 return _(value)
   110             return value
   110             return value
   111     
   111     
   112     def SetValue(self, row, col, value):
   112     def SetValue(self, row, col, value):
   113         if col < len(self.colnames):
   113         if col < len(self.colnames):
   114             colname = self.GetColLabelValue(col, False)
   114             colname = self.GetColLabelValue(col, False)
   115             if colname == "Name":
   115             if colname == "Name":
   116                 self.old_value = self.data[row][colname]
   116                 self.old_value = self.data[row][colname]
   117             elif colname == "Class":
   117             elif colname == "Class":
   118                 value = VARIABLE_CLASSES_DICT[value]
   118                 value = VARIABLE_CLASSES_DICT[value]
   119             elif colname in ["Retain", "Constant"]:
   119             elif colname == "Option":
   120                 value = ALTERNATIVE_OPTIONS_DICT[value]
   120                 value = OPTIONS_DICT[value]
   121             self.data[row][colname] = value
   121             self.data[row][colname] = value
   122     
   122     
   123     def GetValueByName(self, row, colname):
   123     def GetValueByName(self, row, colname):
   124         if row < self.GetNumberRows():
   124         if row < self.GetNumberRows():
   125             return self.data[row].get(colname)
   125             return self.data[row].get(colname)
   175         for row in range(self.GetNumberRows()):
   175         for row in range(self.GetNumberRows()):
   176             for col in range(self.GetNumberCols()):
   176             for col in range(self.GetNumberCols()):
   177                 editor = None
   177                 editor = None
   178                 renderer = None
   178                 renderer = None
   179                 colname = self.GetColLabelValue(col, False)
   179                 colname = self.GetColLabelValue(col, False)
   180                 if col != 0 and self.GetValueByName(row, "Edit"):
   180                 if colname == "Option":
       
   181                     editor = wx.grid.GridCellChoiceEditor()
       
   182                     editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
       
   183                 elif col != 0 and self.GetValueByName(row, "Edit"):
   181                     grid.SetReadOnly(row, col, False)
   184                     grid.SetReadOnly(row, col, False)
   182                     if colname == "Name":
   185                     if colname == "Name":
   183                         if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
   186                         if self.Parent.PouIsUsed and self.GetValueByName(row, "Class") in ["Input", "Output", "InOut"]:
   184                             grid.SetReadOnly(row, col, True)
   187                             grid.SetReadOnly(row, col, True)
   185                         else:
   188                         else:
   203                             if self.Parent.PouIsUsed:
   206                             if self.Parent.PouIsUsed:
   204                                 excluded.extend(["Input","Output","InOut"])
   207                                 excluded.extend(["Input","Output","InOut"])
   205                             if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
   208                             if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
   206                                 excluded.extend(["Local","Temp"])
   209                                 excluded.extend(["Local","Temp"])
   207                             editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
   210                             editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded]))
   208                     elif colname in ["Retain", "Constant"]:
   211                 elif colname != "Documentation":
   209                         editor = wx.grid.GridCellChoiceEditor()
       
   210                         editor.SetParameters(",".join(map(_, self.Parent.OptionList)))
       
   211                     elif colname == "Type":
       
   212                         editor = wx.grid.GridCellTextEditor()
       
   213                 else:
       
   214                     grid.SetReadOnly(row, col, True)
   212                     grid.SetReadOnly(row, col, True)
   215                 
   213                 
   216                 grid.SetCellEditor(row, col, editor)
   214                 grid.SetCellEditor(row, col, editor)
   217                 grid.SetCellRenderer(row, col, renderer)
   215                 grid.SetCellRenderer(row, col, renderer)
   218                 
   216                 
   484         self.Filter = "All"
   482         self.Filter = "All"
   485         self.FilterChoices = []
   483         self.FilterChoices = []
   486         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   484         self.FilterChoiceTransfer = GetFilterChoiceTransfer()
   487         
   485         
   488         self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
   486         self.DefaultValue = {   "Name" : "", "Class" : "", "Type" : "INT", "Location" : "",
   489                                 "Initial Value" : "", "Retain" : "No", "Constant" : "No",
   487                                 "Initial Value" : "", "Option" : "",
   490                                 "Documentation" : "", "Edit" : True
   488                                 "Documentation" : "", "Edit" : True
   491                             }
   489                             }
   492 
   490 
   493         if element_type in ["config", "resource"]:
   491         if element_type in ["config", "resource"]:
   494             self.DefaultTypes = {"All" : "Global"}
   492             self.DefaultTypes = {"All" : "Global"}
   509 
   507 
   510             # these condense the ColAlignements list
   508             # these condense the ColAlignements list
   511             l = wx.ALIGN_LEFT
   509             l = wx.ALIGN_LEFT
   512             c = wx.ALIGN_CENTER 
   510             c = wx.ALIGN_CENTER 
   513 
   511 
   514             #                      Num  Name    Class   Type    Loc     Init    Retain  Const   Doc
   512             #                      Num  Name    Class   Type    Loc     Init    Option   Doc
   515             self.ColSizes       = [40,  80,     70,     80,     80,     80,     60,     70,     80]
   513             self.ColSizes       = [40,  80,     70,     80,     80,     80,     100,     80]
   516             self.ColAlignements = [c,   l,      l,      l,      l,      l,      c,      c,      l]
   514             self.ColAlignements = [c,   l,      l,      l,      l,      l,      l,       l]
   517 
   515 
   518         else:
   516         else:
   519             # this is an element that cannot have located variables
   517             # this is an element that cannot have located variables
   520             self.Table = VariableTable(self, [], GetVariableTableColnames(False))
   518             self.Table = VariableTable(self, [], GetVariableTableColnames(False))
   521 
   519 
   530 
   528 
   531             # these condense the ColAlignements list
   529             # these condense the ColAlignements list
   532             l = wx.ALIGN_LEFT
   530             l = wx.ALIGN_LEFT
   533             c = wx.ALIGN_CENTER 
   531             c = wx.ALIGN_CENTER 
   534 
   532 
   535             #                      Num  Name    Class   Type    Init    Retain  Const   Doc
   533             #                      Num  Name    Class   Type    Init    Option   Doc
   536             self.ColSizes       = [40,  80,     70,     80,     80,     60,     70,     160]
   534             self.ColSizes       = [40,  80,     70,     80,     80,     100,     160]
   537             self.ColAlignements = [c,   l,      l,      l,      l,      c,      c,      l]
   535             self.ColAlignements = [c,   l,      l,      l,      l,      l,       l]
   538 
   536 
   539         for choice in self.FilterChoices:
   537         for choice in self.FilterChoices:
   540             self.ClassFilter.Append(_(choice))
   538             self.ClassFilter.Append(_(choice))
   541 
   539 
   542         reverse_transfer = {}
   540         reverse_transfer = {}
   543         for filter, choice in self.FilterChoiceTransfer.items():
   541         for filter, choice in self.FilterChoiceTransfer.items():
   544             reverse_transfer[choice] = filter
   542             reverse_transfer[choice] = filter
   545         self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
   543         self.ClassFilter.SetStringSelection(_(reverse_transfer[self.Filter]))
   546         self.RefreshTypeList()
   544         self.RefreshTypeList()
   547 
   545 
   548         self.OptionList = GetAlternativeOptions()
   546         self.OptionList = GetOptions()
   549         
   547         
   550         if element_type == "function":
   548         if element_type == "function":
   551             for base_type in self.Controler.GetBaseTypes():
   549             for base_type in self.Controler.GetBaseTypes():
   552                 self.ReturnType.Append(base_type)
   550                 self.ReturnType.Append(base_type)
   553             self.ReturnType.Enable(True)
   551             self.ReturnType.Enable(True)
   705                 old_value = self.Table.GetOldValue()
   703                 old_value = self.Table.GetOldValue()
   706                 if old_value != "":
   704                 if old_value != "":
   707                     self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
   705                     self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
   708                 self.Controler.BufferProject()
   706                 self.Controler.BufferProject()
   709                 self.ParentWindow.RefreshEditor(variablepanel = False)
   707                 self.ParentWindow.RefreshEditor(variablepanel = False)
   710                 self.ParentWindow._Refresh(TITLE, EDITMENU, INSTANCESTREE, LIBRARYTREE)            
   708                 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, INSTANCESTREE, LIBRARYTREE)
   711                 event.Skip()
   709                 event.Skip()
   712         else:
   710         else:
   713             self.SaveValues()
   711             self.SaveValues()
   714             if colname == "Class":
   712             if colname == "Class":
   715                 self.Table.ResetView(self.VariablesGrid)
   713                 self.Table.ResetView(self.VariablesGrid)
       
   714             self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU)
   716             event.Skip()
   715             event.Skip()
   717     
   716     
   718     def OnVariablesGridEditorShown(self, event):
   717     def OnVariablesGridEditorShown(self, event):
   719         row, col = event.GetRow(), event.GetCol() 
   718         row, col = event.GetRow(), event.GetCol() 
   720 
   719