198 if colname == "Option": |
198 if colname == "Option": |
199 options = GetOptions(constant=var_class in ["Local", "External", "Global"], |
199 options = GetOptions(constant=var_class in ["Local", "External", "Global"], |
200 retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
200 retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output", "Global"], |
201 non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
201 non_retain=self.Parent.ElementType != "function" and var_class in ["Local", "Input", "Output"]) |
202 if len(options) > 1: |
202 if len(options) > 1: |
203 editor = wx.grid.GridCellChoiceEditor() |
203 editor = wx.grid.GridCellChoiceEditor(map(_, options)) |
204 editor.SetParameters(",".join(map(_, options))) |
|
205 else: |
204 else: |
206 grid.SetReadOnly(row, col, True) |
205 grid.SetReadOnly(row, col, True) |
207 elif col != 0 and self._GetRowEdit(row): |
206 elif col != 0 and self._GetRowEdit(row): |
208 grid.SetReadOnly(row, col, False) |
207 grid.SetReadOnly(row, col, False) |
209 if colname == "Name": |
208 if colname == "Name": |
210 editor = wx.grid.GridCellTextEditor() |
209 editor = wx.grid.GridCellTextEditor() |
211 renderer = wx.grid.GridCellStringRenderer() |
210 renderer = wx.grid.GridCellStringRenderer() |
212 elif colname == "Initial Value": |
211 elif colname == "Initial Value": |
213 if var_class not in ["External", "InOut"]: |
212 if var_class not in ["External", "InOut"]: |
214 if self.Parent.Controler.IsEnumeratedType(var_type): |
213 if self.Parent.Controler.IsEnumeratedType(var_type): |
215 editor = wx.grid.GridCellChoiceEditor() |
214 editor = wx.grid.GridCellChoiceEditor([""] + self.Parent.Controler.GetEnumeratedDataValues(var_type)) |
216 editor.SetParameters(",".join([""] + self.Parent.Controler.GetEnumeratedDataValues(var_type))) |
|
217 else: |
215 else: |
218 editor = wx.grid.GridCellTextEditor() |
216 editor = wx.grid.GridCellTextEditor() |
219 renderer = wx.grid.GridCellStringRenderer() |
217 renderer = wx.grid.GridCellStringRenderer() |
220 else: |
218 else: |
221 grid.SetReadOnly(row, col, True) |
219 grid.SetReadOnly(row, col, True) |
227 grid.SetReadOnly(row, col, True) |
225 grid.SetReadOnly(row, col, True) |
228 elif colname == "Class": |
226 elif colname == "Class": |
229 if len(self.Parent.ClassList) == 1: |
227 if len(self.Parent.ClassList) == 1: |
230 grid.SetReadOnly(row, col, True) |
228 grid.SetReadOnly(row, col, True) |
231 else: |
229 else: |
232 editor = wx.grid.GridCellChoiceEditor() |
|
233 excluded = [] |
230 excluded = [] |
234 if self.Parent.IsFunctionBlockType(var_type): |
231 if self.Parent.IsFunctionBlockType(var_type): |
235 excluded.extend(["Local", "Temp"]) |
232 excluded.extend(["Local", "Temp"]) |
236 editor.SetParameters(",".join([_(choice) for choice in self.Parent.ClassList if choice not in excluded])) |
233 editor = wx.grid.GridCellChoiceEditor([_(choice) for choice in self.Parent.ClassList if choice not in excluded]) |
237 elif colname != "Documentation": |
234 elif colname != "Documentation": |
238 grid.SetReadOnly(row, col, True) |
235 grid.SetReadOnly(row, col, True) |
239 |
236 |
240 grid.SetCellEditor(row, col, editor) |
237 grid.SetCellEditor(row, col, editor) |
241 grid.SetCellRenderer(row, col, renderer) |
238 grid.SetCellRenderer(row, col, renderer) |
454 self.MainSizer.AddGrowableRow(1) |
451 self.MainSizer.AddGrowableRow(1) |
455 |
452 |
456 controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
453 controls_sizer = wx.FlexGridSizer(cols=10, hgap=5, rows=1, vgap=5) |
457 controls_sizer.AddGrowableCol(5) |
454 controls_sizer.AddGrowableCol(5) |
458 controls_sizer.AddGrowableRow(0) |
455 controls_sizer.AddGrowableRow(0) |
459 self.MainSizer.AddSizer(controls_sizer, border=5, flag=wx.GROW | wx.ALL) |
456 self.MainSizer.Add(controls_sizer, border=5, flag=wx.GROW | wx.ALL) |
460 |
457 |
461 self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
458 self.ReturnTypeLabel = wx.StaticText(self, label=_('Return Type:')) |
462 controls_sizer.AddWindow(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
459 controls_sizer.Add(self.ReturnTypeLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
463 |
460 |
464 self.ReturnType = wx.ComboBox(self, |
461 self.ReturnType = wx.ComboBox(self, |
465 size=wx.Size(145, -1), style=wx.CB_READONLY) |
462 size=wx.Size(145, -1), style=wx.CB_READONLY) |
466 self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
463 self.Bind(wx.EVT_COMBOBOX, self.OnReturnTypeChanged, self.ReturnType) |
467 controls_sizer.AddWindow(self.ReturnType) |
464 controls_sizer.Add(self.ReturnType) |
468 |
465 |
469 self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
466 self.DescriptionLabel = wx.StaticText(self, label=_('Description:')) |
470 controls_sizer.AddWindow(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
467 controls_sizer.Add(self.DescriptionLabel, flag=wx.ALIGN_CENTER_VERTICAL) |
471 |
468 |
472 self.Description = wx.TextCtrl(self, |
469 self.Description = wx.TextCtrl(self, |
473 size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
470 size=wx.Size(250, -1), style=wx.TE_PROCESS_ENTER) |
474 self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
471 self.Bind(wx.EVT_TEXT_ENTER, self.OnDescriptionChanged, self.Description) |
475 self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
472 self.Description.Bind(wx.EVT_KILL_FOCUS, self.OnDescriptionChanged) |
476 controls_sizer.AddWindow(self.Description) |
473 controls_sizer.Add(self.Description) |
477 |
474 |
478 class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
475 class_filter_label = wx.StaticText(self, label=_('Class Filter:')) |
479 controls_sizer.AddWindow(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
476 controls_sizer.Add(class_filter_label, flag=wx.ALIGN_CENTER_VERTICAL) |
480 |
477 |
481 self.ClassFilter = wx.ComboBox(self, |
478 self.ClassFilter = wx.ComboBox(self, |
482 size=wx.Size(145, -1), style=wx.CB_READONLY) |
479 size=wx.Size(145, -1), style=wx.CB_READONLY) |
483 self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
480 self.Bind(wx.EVT_COMBOBOX, self.OnClassFilter, self.ClassFilter) |
484 controls_sizer.AddWindow(self.ClassFilter) |
481 controls_sizer.Add(self.ClassFilter) |
485 |
482 |
486 for name, bitmap, help in [ |
483 for name, bitmap, help in [ |
487 ("AddButton", "add_element", _("Add variable")), |
484 ("AddButton", "add_element", _("Add variable")), |
488 ("DeleteButton", "remove_element", _("Remove variable")), |
485 ("DeleteButton", "remove_element", _("Remove variable")), |
489 ("UpButton", "up", _("Move variable up")), |
486 ("UpButton", "up", _("Move variable up")), |
490 ("DownButton", "down", _("Move variable down"))]: |
487 ("DownButton", "down", _("Move variable down"))]: |
491 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
488 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
492 size=wx.Size(28, 28), style=wx.NO_BORDER) |
489 size=wx.Size(28, 28), style=wx.NO_BORDER) |
493 button.SetToolTipString(help) |
490 button.SetToolTip(help) |
494 setattr(self, name, button) |
491 setattr(self, name, button) |
495 controls_sizer.AddWindow(button) |
492 controls_sizer.Add(button) |
496 |
493 |
497 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL) |
494 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL | wx.HSCROLL) |
498 self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
495 self.VariablesGrid.SetDropTarget(VariableDropTarget(self)) |
499 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
496 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGING, |
500 self.OnVariablesGridCellChange) |
497 self.OnVariablesGridCellChange) |
501 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
498 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, |
502 self.OnVariablesGridCellLeftClick) |
499 self.OnVariablesGridCellLeftClick) |
503 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
500 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, |
504 self.OnVariablesGridEditorShown) |
501 self.OnVariablesGridEditorShown) |
505 self.MainSizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
502 self.MainSizer.Add(self.VariablesGrid, flag=wx.GROW) |
506 |
503 |
507 self.SetSizer(self.MainSizer) |
504 self.SetSizer(self.MainSizer) |
508 |
505 |
509 self.ParentWindow = window |
506 self.ParentWindow = window |
510 self.Controler = controler |
507 self.Controler = controler |
846 |
843 |
847 def BuildStdIECTypesMenu(self, type_menu): |
844 def BuildStdIECTypesMenu(self, type_menu): |
848 # build a submenu containing standard IEC types |
845 # build a submenu containing standard IEC types |
849 base_menu = wx.Menu(title='') |
846 base_menu = wx.Menu(title='') |
850 for base_type in self.Controler.GetBaseTypes(): |
847 for base_type in self.Controler.GetBaseTypes(): |
851 item = base_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=base_type) |
848 item = base_menu.Append(wx.ID_ANY, helpString='', kind=wx.ITEM_NORMAL, item=base_type) |
852 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), item) |
849 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), item) |
853 |
850 |
854 type_menu.AppendMenu(wx.ID_ANY, _("Base Types"), base_menu) |
851 type_menu.AppendMenu(wx.ID_ANY, _("Base Types"), base_menu) |
855 |
852 |
856 def BuildUserTypesMenu(self, type_menu): |
853 def BuildUserTypesMenu(self, type_menu): |
857 # build a submenu containing user-defined types |
854 # build a submenu containing user-defined types |
858 datatype_menu = wx.Menu(title='') |
855 datatype_menu = wx.Menu(title='') |
859 datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False) |
856 datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False) |
860 for datatype in datatypes: |
857 for datatype in datatypes: |
861 item = datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype) |
858 item = datatype_menu.Append(wx.ID_ANY, helpString='', kind=wx.ITEM_NORMAL, item=datatype) |
862 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item) |
859 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item) |
863 |
860 |
864 type_menu.AppendMenu(wx.ID_ANY, _("User Data Types"), datatype_menu) |
861 type_menu.AppendMenu(wx.ID_ANY, _("User Data Types"), datatype_menu) |
865 |
862 |
866 def BuildLibsTypesMenu(self, type_menu): |
863 def BuildLibsTypesMenu(self, type_menu): |
867 for category in self.Controler.GetConfNodeDataTypes(): |
864 for category in self.Controler.GetConfNodeDataTypes(): |
868 if len(category["list"]) > 0: |
865 if len(category["list"]) > 0: |
869 # build a submenu containing confnode types |
866 # build a submenu containing confnode types |
870 confnode_datatype_menu = wx.Menu(title='') |
867 confnode_datatype_menu = wx.Menu(title='') |
871 for datatype in category["list"]: |
868 for datatype in category["list"]: |
872 item = confnode_datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype) |
869 item = confnode_datatype_menu.Append(wx.ID_ANY, helpString='', kind=wx.ITEM_NORMAL, item=datatype) |
873 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item) |
870 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item) |
874 |
871 |
875 type_menu.AppendMenu(wx.ID_ANY, category["name"], confnode_datatype_menu) |
872 type_menu.AppendMenu(wx.ID_ANY, category["name"], confnode_datatype_menu) |
876 |
873 |
877 def BuildProjectTypesMenu(self, type_menu, classtype): |
874 def BuildProjectTypesMenu(self, type_menu, classtype): |
881 if classtype in ["Input", "Output", "InOut", "External", "Global"] or \ |
878 if classtype in ["Input", "Output", "InOut", "External", "Global"] or \ |
882 poutype != "function" and bodytype in ["ST", "IL"]: |
879 poutype != "function" and bodytype in ["ST", "IL"]: |
883 functionblock_menu = wx.Menu(title='') |
880 functionblock_menu = wx.Menu(title='') |
884 fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName) |
881 fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName) |
885 for functionblock_type in fbtypes: |
882 for functionblock_type in fbtypes: |
886 item = functionblock_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=functionblock_type) |
883 item = functionblock_menu.Append(wx.ID_ANY, helpString='', kind=wx.ITEM_NORMAL, item=functionblock_type) |
887 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), item) |
884 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), item) |
888 |
885 |
889 type_menu.AppendMenu(wx.ID_ANY, _("Function Block Types"), functionblock_menu) |
886 type_menu.AppendMenu(wx.ID_ANY, _("Function Block Types"), functionblock_menu) |
890 |
887 |
891 def BuildArrayTypesMenu(self, type_menu): |
888 def BuildArrayTypesMenu(self, type_menu): |
892 item = type_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=_("Array")) |
889 item = type_menu.Append(wx.ID_ANY, helpString='', kind=wx.ITEM_NORMAL, item=_("Array")) |
893 self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, item) |
890 self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, item) |
894 |
891 |
895 def OnVariablesGridEditorShown(self, event): |
892 def OnVariablesGridEditorShown(self, event): |
896 row, col = event.GetRow(), event.GetCol() |
893 row, col = event.GetRow(), event.GetCol() |
897 |
894 |