173 colname = self.GetColLabelValue(col, False) |
173 colname = self.GetColLabelValue(col, False) |
174 if self.Parent.Debug: |
174 if self.Parent.Debug: |
175 grid.SetReadOnly(row, col, True) |
175 grid.SetReadOnly(row, col, True) |
176 else: |
176 else: |
177 if colname == "Option": |
177 if colname == "Option": |
178 options = GetOptions(constant = var_class in ["Local", "External", "Global"], |
178 options = GetOptions(constant=var_class in ["Local", "External", "Global"], |
179 retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
179 retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
180 non_retain = self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
180 non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
181 if len(options) > 1: |
181 if len(options) > 1: |
182 editor = wx.grid.GridCellChoiceEditor() |
182 editor = wx.grid.GridCellChoiceEditor() |
183 editor.SetParameters(",".join(map(_, options))) |
183 editor.SetParameters(",".join(map(_, options))) |
184 else: |
184 else: |
185 grid.SetReadOnly(row, col, True) |
185 grid.SetReadOnly(row, col, True) |
277 |
277 |
278 if values[2] is not None: |
278 if values[2] is not None: |
279 base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
279 base_location_type = self.ParentWindow.Controler.GetBaseType(values[2]) |
280 if values[2] != variable_type and base_type != base_location_type: |
280 if values[2] != variable_type and base_type != base_location_type: |
281 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\ |
281 message = _("Incompatible data types between \"{a1}\" and \"{a2}\"").\ |
282 format(a1 = values[2], a2 = variable_type) |
282 format(a1=values[2], a2=variable_type) |
283 |
283 |
284 if message is None: |
284 if message is None: |
285 if not location.startswith("%"): |
285 if not location.startswith("%"): |
286 if location[0].isdigit() and base_type != "BOOL": |
286 if location[0].isdigit() and base_type != "BOOL": |
287 message = _("Incompatible size of data between \"%s\" and \"BOOL\"") % location |
287 message = _("Incompatible size of data between \"%s\" and \"BOOL\"") % location |
288 elif location[0] not in LOCATIONDATATYPES: |
288 elif location[0] not in LOCATIONDATATYPES: |
289 message = _("Unrecognized data size \"%s\"") % location[0] |
289 message = _("Unrecognized data size \"%s\"") % location[0] |
290 elif base_type not in LOCATIONDATATYPES[location[0]]: |
290 elif base_type not in LOCATIONDATATYPES[location[0]]: |
291 message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\ |
291 message = _("Incompatible size of data between \"{a1}\" and \"{a2}\"").\ |
292 format(a1 = location, a2 = variable_type) |
292 format(a1=location, a2=variable_type) |
293 else: |
293 else: |
294 dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
294 dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, |
295 _("Select a variable class:"), _("Variable class"), |
295 _("Select a variable class:"), _("Variable class"), |
296 [_("Input"), _("Output"), _("Memory")], |
296 [_("Input"), _("Output"), _("Memory")], |
297 wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
297 wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL) |
596 else: |
596 else: |
597 self.Values.append(row_content) |
597 self.Values.append(row_content) |
598 new_row = self.Table.GetNumberRows() |
598 new_row = self.Table.GetNumberRows() |
599 self.SaveValues() |
599 self.SaveValues() |
600 if self.ElementType == "resource": |
600 if self.ElementType == "resource": |
601 self.ParentWindow.RefreshView(variablepanel = False) |
601 self.ParentWindow.RefreshView(variablepanel=False) |
602 self.RefreshValues() |
602 self.RefreshValues() |
603 return new_row |
603 return new_row |
604 setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
604 setattr(self.VariablesGrid, "_AddRow", _AddVariable) |
605 |
605 |
606 def _DeleteVariable(row): |
606 def _DeleteVariable(row): |
607 if _GetRowEdit(row): |
607 if _GetRowEdit(row): |
608 self.Values.remove(self.Table.GetRow(row)) |
608 self.Values.remove(self.Table.GetRow(row)) |
609 self.SaveValues() |
609 self.SaveValues() |
610 if self.ElementType == "resource": |
610 if self.ElementType == "resource": |
611 self.ParentWindow.RefreshView(variablepanel = False) |
611 self.ParentWindow.RefreshView(variablepanel=False) |
612 self.RefreshValues() |
612 self.RefreshValues() |
613 setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
613 setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable) |
614 |
614 |
615 def _MoveVariable(row, move): |
615 def _MoveVariable(row, move): |
616 if self.Filter == "All": |
616 if self.Filter == "All": |
729 |
729 |
730 def OnReturnTypeChanged(self, event): |
730 def OnReturnTypeChanged(self, event): |
731 words = self.TagName.split("::") |
731 words = self.TagName.split("::") |
732 self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
732 self.Controler.SetPouInterfaceReturnType(words[1], self.ReturnType.GetStringSelection()) |
733 self.Controler.BufferProject() |
733 self.Controler.BufferProject() |
734 self.ParentWindow.RefreshView(variablepanel = False) |
734 self.ParentWindow.RefreshView(variablepanel=False) |
735 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
735 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
736 event.Skip() |
736 event.Skip() |
737 |
737 |
738 def OnDescriptionChanged(self, event): |
738 def OnDescriptionChanged(self, event): |
739 words = self.TagName.split("::") |
739 words = self.TagName.split("::") |
822 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
822 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
823 |
823 |
824 def BuildUserTypesMenu(self, type_menu): |
824 def BuildUserTypesMenu(self, type_menu): |
825 # build a submenu containing user-defined types |
825 # build a submenu containing user-defined types |
826 datatype_menu = wx.Menu(title='') |
826 datatype_menu = wx.Menu(title='') |
827 datatypes = self.Controler.GetDataTypes(basetypes = False, confnodetypes = False) |
827 datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False) |
828 for datatype in datatypes: |
828 for datatype in datatypes: |
829 new_id = wx.NewId() |
829 new_id = wx.NewId() |
830 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
830 datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
831 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
831 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
832 |
832 |
901 def VariableTypeFunction(event): |
901 def VariableTypeFunction(event): |
902 row = self.VariablesGrid.GetGridCursorRow() |
902 row = self.VariablesGrid.GetGridCursorRow() |
903 self.Table.SetValueByName(row, "Type", base_type) |
903 self.Table.SetValueByName(row, "Type", base_type) |
904 self.Table.ResetView(self.VariablesGrid) |
904 self.Table.ResetView(self.VariablesGrid) |
905 self.SaveValues(False) |
905 self.SaveValues(False) |
906 self.ParentWindow.RefreshView(variablepanel = False) |
906 self.ParentWindow.RefreshView(variablepanel=False) |
907 self.Controler.BufferProject() |
907 self.Controler.BufferProject() |
908 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
908 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
909 return VariableTypeFunction |
909 return VariableTypeFunction |
910 |
910 |
911 def VariableArrayTypeFunction(self, event): |
911 def VariableArrayTypeFunction(self, event): |
915 self.Table.GetValueByName(row, "Type")) |
915 self.Table.GetValueByName(row, "Type")) |
916 if dialog.ShowModal() == wx.ID_OK: |
916 if dialog.ShowModal() == wx.ID_OK: |
917 self.Table.SetValueByName(row, "Type", dialog.GetValue()) |
917 self.Table.SetValueByName(row, "Type", dialog.GetValue()) |
918 self.Table.ResetView(self.VariablesGrid) |
918 self.Table.ResetView(self.VariablesGrid) |
919 self.SaveValues(False) |
919 self.SaveValues(False) |
920 self.ParentWindow.RefreshView(variablepanel = False) |
920 self.ParentWindow.RefreshView(variablepanel=False) |
921 self.Controler.BufferProject() |
921 self.Controler.BufferProject() |
922 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
922 self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
923 dialog.Destroy() |
923 dialog.Destroy() |
924 |
924 |
925 def OnVariablesGridCellLeftClick(self, event): |
925 def OnVariablesGridCellLeftClick(self, event): |
941 variable.Number = num + 1 |
941 variable.Number = num + 1 |
942 data.append(variable) |
942 data.append(variable) |
943 self.Table.SetData(data) |
943 self.Table.SetData(data) |
944 self.Table.ResetView(self.VariablesGrid) |
944 self.Table.ResetView(self.VariablesGrid) |
945 |
945 |
946 def SaveValues(self, buffer = True): |
946 def SaveValues(self, buffer=True): |
947 words = self.TagName.split("::") |
947 words = self.TagName.split("::") |
948 if self.ElementType == "config": |
948 if self.ElementType == "config": |
949 self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
949 self.Controler.SetConfigurationGlobalVars(words[1], self.Values) |
950 elif self.ElementType == "resource": |
950 elif self.ElementType == "resource": |
951 self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |
951 self.Controler.SetConfigurationResourceGlobalVars(words[1], words[2], self.Values) |