388 self.TreeNoteBook = wx.aui.AuiNotebook(self) |
388 self.TreeNoteBook = wx.aui.AuiNotebook(self) |
389 self.AUIManager.AddPane(self.TreeNoteBook, wx.aui.AuiPaneInfo().Caption("Project").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False)) |
389 self.AUIManager.AddPane(self.TreeNoteBook, wx.aui.AuiPaneInfo().Caption("Project").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False)) |
390 |
390 |
391 typestreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER |
391 typestreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER |
392 if not self.Debug: |
392 if not self.Debug: |
393 typestreestyle |= wx.TR_HIDE_ROOT |
393 typestreestyle |= wx.TR_EDIT_LABELS |
394 self.TypesTree = wx.TreeCtrl(id=ID_PLCOPENEDITORTYPESTREE, |
394 self.TypesTree = wx.TreeCtrl(id=ID_PLCOPENEDITORTYPESTREE, |
395 name='TypesTree', parent=self.TreeNoteBook, |
395 name='TypesTree', parent=self.TreeNoteBook, |
396 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
396 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
397 style=typestreestyle) |
397 style=typestreestyle) |
398 self.TreeNoteBook.AddPage(self.TypesTree, "Types") |
|
399 |
|
400 if not self.Debug: |
398 if not self.Debug: |
401 if wx.Platform == '__WXMSW__': |
399 if wx.Platform == '__WXMSW__': |
402 self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnTypesTreeRightUp, |
400 self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnTypesTreeRightUp, |
403 id=ID_PLCOPENEDITORTYPESTREE) |
401 id=ID_PLCOPENEDITORTYPESTREE) |
404 self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTypesTreeItemSelected, |
402 self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTypesTreeItemSelected, |
423 |
421 |
424 self.InstancesTree = wx.TreeCtrl(id=ID_PLCOPENEDITORINSTANCESTREE, |
422 self.InstancesTree = wx.TreeCtrl(id=ID_PLCOPENEDITORINSTANCESTREE, |
425 name='InstancesTree', parent=self.TreeNoteBook, |
423 name='InstancesTree', parent=self.TreeNoteBook, |
426 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
424 pos=wx.Point(0, 0), size=wx.Size(0, 0), |
427 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
425 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER) |
428 self.TreeNoteBook.AddPage(self.InstancesTree, "Instances") |
|
429 |
|
430 if self.Debug: |
426 if self.Debug: |
431 self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnInstancesTreeBeginDrag, |
427 self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnInstancesTreeBeginDrag, |
432 id=ID_PLCOPENEDITORINSTANCESTREE) |
428 id=ID_PLCOPENEDITORINSTANCESTREE) |
433 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnInstancesTreeItemActivated, |
429 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnInstancesTreeItemActivated, |
434 id=ID_PLCOPENEDITORINSTANCESTREE) |
430 id=ID_PLCOPENEDITORINSTANCESTREE) |
|
431 |
|
432 self.TreeNoteBook.AddPage(self.InstancesTree, "Instances") |
|
433 self.TreeNoteBook.AddPage(self.TypesTree, "Types") |
435 |
434 |
436 if wx.VERSION < (2, 8, 0): |
435 if wx.VERSION < (2, 8, 0): |
437 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED, |
436 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED, |
438 name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0, |
437 name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0, |
439 0), size=wx.Size(0, 0), style=0) |
438 0), size=wx.Size(0, 0), style=0) |
449 self.TabsOpened = wx.aui.AuiNotebook(self) |
448 self.TabsOpened = wx.aui.AuiNotebook(self) |
450 self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, |
449 self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, |
451 self.OnPouSelectedChanged) |
450 self.OnPouSelectedChanged) |
452 self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane()) |
451 self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane()) |
453 else: |
452 else: |
|
453 self.TreeNoteBook.AddPage(self.TypesTree, "Types") |
|
454 self.TreeNoteBook.AddPage(self.InstancesTree, "Instances") |
|
455 |
454 if wx.VERSION < (2, 8, 0): |
456 if wx.VERSION < (2, 8, 0): |
455 self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, |
457 self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, |
456 ID_PLCOPENEDITORTOOLBAR, 'ToolBar') |
458 ID_PLCOPENEDITORTOOLBAR, 'ToolBar') |
457 self.ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
459 self.ToolBar.SetToolBitmapSize(wx.Size(25, 25)) |
458 self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
460 self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, |
649 |
651 |
650 def GetDrawingMode(self): |
652 def GetDrawingMode(self): |
651 return self.DrawingMode |
653 return self.DrawingMode |
652 |
654 |
653 def RefreshTitle(self): |
655 def RefreshTitle(self): |
|
656 name = "PLCOpenEditor" |
|
657 if self.Debug: |
|
658 name += " (Debug)" |
654 if self.Controler.HasOpenedProject() > 0: |
659 if self.Controler.HasOpenedProject() > 0: |
655 self.SetTitle("PLCOpenEditor - %s"%self.Controler.GetFilename()) |
660 self.SetTitle("%s - %s"%(name, self.Controler.GetFilename())) |
656 else: |
661 else: |
657 self.SetTitle("PLCOpenEditor") |
662 self.SetTitle(name) |
658 |
663 |
659 def ShowProperties(self): |
664 def ShowProperties(self): |
660 old_values = self.Controler.GetProjectProperties(self.Debug) |
665 old_values = self.Controler.GetProjectProperties(self.Debug) |
661 dialog = ProjectDialog(self) |
666 dialog = ProjectDialog(self) |
662 dialog.SetValues(old_values) |
667 dialog.SetValues(old_values) |
3641 grid.SetReadOnly(row, col, True) |
3646 grid.SetReadOnly(row, col, True) |
3642 else: |
3647 else: |
3643 editor = wx.grid.GridCellChoiceEditor() |
3648 editor = wx.grid.GridCellChoiceEditor() |
3644 excluded = [] |
3649 excluded = [] |
3645 if self.Parent.PouIsUsed: |
3650 if self.Parent.PouIsUsed: |
3646 excluded.extend(["Input","Output","InOut"]) |
3651 excluded.extend(["Input","Output","InOut"]) |
|
3652 if self.Parent.IsFunctionBlockType(self.data[row]["Type"]): |
|
3653 excluded.extend(["Local","Temp"]) |
3647 editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) |
3654 editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded])) |
3648 elif colname in ["Retain", "Constant"]: |
3655 elif colname in ["Retain", "Constant"]: |
3649 editor = wx.grid.GridCellChoiceEditor() |
3656 editor = wx.grid.GridCellChoiceEditor() |
3650 editor.SetParameters(self.Parent.OptionList) |
3657 editor.SetParameters(self.Parent.OptionList) |
3651 elif colname == "Type": |
3658 elif colname == "Type": |
3958 self.VariablesGrid.SetColSize(col, self.ColSizes[col]) |
3965 self.VariablesGrid.SetColSize(col, self.ColSizes[col]) |
3959 |
3966 |
3960 def SetTagName(self, tagname): |
3967 def SetTagName(self, tagname): |
3961 self.TagName = tagname |
3968 self.TagName = tagname |
3962 |
3969 |
|
3970 def IsFunctionBlockType(self, name): |
|
3971 bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug) |
|
3972 pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug) |
|
3973 if poutype != "function" and bodytype in ["ST", "IL"]: |
|
3974 return False |
|
3975 else: |
|
3976 return name in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug) |
|
3977 |
3963 def RefreshView(self): |
3978 def RefreshView(self): |
3964 self.PouNames = self.Controler.GetProjectPouNames(self.ParentWindow.Debug) |
3979 self.PouNames = self.Controler.GetProjectPouNames(self.ParentWindow.Debug) |
3965 |
3980 |
3966 words = self.TagName.split("::") |
3981 words = self.TagName.split("::") |
3967 if self.ElementType == "config": |
3982 if self.ElementType == "config": |
4097 self.ParentWindow.RefreshInstancesTree() |
4112 self.ParentWindow.RefreshInstancesTree() |
4098 event.Skip() |
4113 event.Skip() |
4099 |
4114 |
4100 def OnVariablesGridEditorShown(self, event): |
4115 def OnVariablesGridEditorShown(self, event): |
4101 row, col = event.GetRow(), event.GetCol() |
4116 row, col = event.GetRow(), event.GetCol() |
|
4117 classtype = self.Table.GetValueByName(row, "Class") |
4102 if self.Table.GetColLabelValue(col) == "Type": |
4118 if self.Table.GetColLabelValue(col) == "Type": |
4103 type_menu = wx.Menu(title='') |
4119 type_menu = wx.Menu(title='') |
4104 base_menu = wx.Menu(title='') |
4120 base_menu = wx.Menu(title='') |
4105 for base_type in self.Controler.GetBaseTypes(): |
4121 for base_type in self.Controler.GetBaseTypes(): |
4106 new_id = wx.NewId() |
4122 new_id = wx.NewId() |
4107 AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
4123 AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
4108 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
4124 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id) |
4109 type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu) |
4125 type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu) |
4110 datatype_menu = wx.Menu(title='') |
4126 datatype_menu = wx.Menu(title='') |
4111 for datatype in self.Controler.GetDataTypes(basetypes = False, debug = self.Debug): |
4127 for datatype in self.Controler.GetDataTypes(basetypes = False, debug = self.ParentWindow.Debug): |
4112 new_id = wx.NewId() |
4128 new_id = wx.NewId() |
4113 AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
4129 AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
4114 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
4130 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id) |
4115 type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu) |
4131 type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu) |
4116 functionblock_menu = wx.Menu(title='') |
4132 functionblock_menu = wx.Menu(title='') |
4117 for functionblock_type in self.Controler.GetFunctionBlockTypes(debug = self.Debug): |
4133 bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug) |
4118 new_id = wx.NewId() |
4134 pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug) |
4119 AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
4135 if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]: |
4120 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
4136 for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug): |
4121 type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu) |
4137 new_id = wx.NewId() |
|
4138 AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
|
4139 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
|
4140 type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu) |
4122 rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
4141 rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col)) |
4123 self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) |
4142 self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize()) |
4124 event.Veto() |
4143 event.Veto() |
4125 else: |
4144 else: |
4126 event.Skip() |
4145 event.Skip() |