andrej@1511: #!/usr/bin/env python andrej@1511: # -*- coding: utf-8 -*- andrej@1511: andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. andrej@1511: # andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD andrej@1511: # andrej@1511: # See COPYING file for copyrights details. andrej@1511: # andrej@1511: # This program is free software; you can redistribute it and/or andrej@1511: # modify it under the terms of the GNU General Public License andrej@1511: # as published by the Free Software Foundation; either version 2 andrej@1511: # of the License, or (at your option) any later version. andrej@1511: # andrej@1511: # This program is distributed in the hope that it will be useful, andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1511: # GNU General Public License for more details. andrej@1511: # andrej@1511: # You should have received a copy of the GNU General Public License andrej@1511: # along with this program; if not, write to the Free Software andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. smarteh-dev@680: andrej@1881: from __future__ import absolute_import smarteh-dev@680: import wx smarteh-dev@680: Laurent@1003: from networkeditortemplate import NetworkEditorTemplate Laurent@814: from editors.ConfTreeNodeEditor import ConfTreeNodeEditor smarteh-dev@680: andrej@1773: [ andrej@1773: ID_NETWORKEDITOR, smarteh-dev@680: ] = [wx.NewId() for _init_ctrls in range(1)] smarteh-dev@680: andrej@1773: [ andrej@1773: ID_NETWORKEDITORCONFNODEMENUADDSLAVE, andrej@1773: ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, andrej@1773: ID_NETWORKEDITORCONFNODEMENUMASTER, Edouard@717: ] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(3)] smarteh-dev@680: andrej@1773: [ andrej@1773: ID_NETWORKEDITORMASTERMENUNODEINFOS, ID_NETWORKEDITORMASTERMENUDS301PROFILE, andrej@1773: ID_NETWORKEDITORMASTERMENUDS302PROFILE, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE, andrej@1773: ID_NETWORKEDITORMASTERMENUADD, smarteh-dev@680: ] = [wx.NewId() for _init_coll_MasterMenu_Items in range(5)] smarteh-dev@680: andrej@1773: [ andrej@1773: ID_NETWORKEDITORADDMENUSDOSERVER, ID_NETWORKEDITORADDMENUSDOCLIENT, andrej@1773: ID_NETWORKEDITORADDMENUPDOTRANSMIT, ID_NETWORKEDITORADDMENUPDORECEIVE, andrej@1773: ID_NETWORKEDITORADDMENUMAPVARIABLE, ID_NETWORKEDITORADDMENUUSERTYPE, smarteh-dev@680: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] smarteh-dev@680: andrej@1736: laurent@762: class NetworkEditor(ConfTreeNodeEditor, NetworkEditorTemplate): andrej@1730: smarteh-dev@680: ID = ID_NETWORKEDITOR Laurent@920: CONFNODEEDITOR_TABS = [ Laurent@920: (_("CANOpen network"), "_create_NetworkEditor")] andrej@1730: Laurent@920: def _create_NetworkEditor(self, prnt): andrej@1768: self.NetworkEditor = wx.Panel( andrej@1768: id=-1, parent=prnt, pos=wx.Point(0, 0), andrej@1768: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) andrej@1730: Laurent@920: NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor) andrej@1730: Laurent@920: main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) Laurent@920: main_sizer.AddGrowableCol(0) Laurent@920: main_sizer.AddGrowableRow(0) andrej@1730: andrej@1745: main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW | wx.ALL) andrej@1730: Laurent@920: self.NetworkEditor.SetSizer(main_sizer) andrej@1730: Laurent@920: return self.NetworkEditor andrej@1730: smarteh-dev@680: def __init__(self, parent, controler, window): laurent@762: ConfTreeNodeEditor.__init__(self, parent, controler, window) smarteh-dev@680: NetworkEditorTemplate.__init__(self, controler, window, False) andrej@1730: smarteh-dev@680: self.RefreshNetworkNodes() smarteh-dev@680: self.RefreshBufferState() andrej@1730: smarteh-dev@680: def __del__(self): smarteh-dev@680: self.Controler.OnCloseEditor(self) andrej@1730: Edouard@717: def GetConfNodeMenuItems(self): smarteh-dev@680: add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_NETWORKEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('SDO Client'), ID_NETWORKEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_NETWORKEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('PDO Receive'), ID_NETWORKEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('Map Variable'), ID_NETWORKEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('User Type'), ID_NETWORKEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))] andrej@1730: smarteh-dev@680: profile = self.Manager.GetCurrentProfileName() smarteh-dev@680: if profile not in ("None", "DS-301"): smarteh-dev@680: other_profile_text = _("%s Profile") % profile smarteh-dev@680: add_menu.append((wx.ITEM_SEPARATOR, None)) andrej@1847: for text, _indexes in self.Manager.GetCurrentSpecificMenu(): smarteh-dev@680: add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text)))) smarteh-dev@680: else: smarteh-dev@680: other_profile_text = _('Other Profile') andrej@1730: laurent@845: master_menu = [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_NETWORKEDITORMASTERMENUDS301PROFILE, '', self.OnCommunicationMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_NETWORKEDITORMASTERMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)), smarteh-dev@680: (wx.ITEM_NORMAL, (other_profile_text, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)), smarteh-dev@680: (wx.ITEM_SEPARATOR, None), smarteh-dev@680: (add_menu, (_('Add'), ID_NETWORKEDITORMASTERMENUADD))] andrej@1730: Edouard@717: return [(wx.ITEM_NORMAL, (_('Add slave'), ID_NETWORKEDITORCONFNODEMENUADDSLAVE, '', self.OnAddSlaveMenu)), Edouard@717: (wx.ITEM_NORMAL, (_('Remove slave'), ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, '', self.OnRemoveSlaveMenu)), smarteh-dev@680: (wx.ITEM_SEPARATOR, None), Edouard@717: (master_menu, (_('Master'), ID_NETWORKEDITORCONFNODEMENUMASTER))] andrej@1730: smarteh-dev@680: def RefreshMainMenu(self): smarteh-dev@680: pass andrej@1730: Edouard@717: def RefreshConfNodeMenu(self, confnode_menu): Edouard@717: confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0) andrej@1730: smarteh-dev@680: def RefreshView(self): laurent@762: ConfTreeNodeEditor.RefreshView(self) smarteh-dev@680: self.RefreshCurrentIndexList() andrej@1730: smarteh-dev@680: def RefreshBufferState(self): smarteh-dev@680: NetworkEditorTemplate.RefreshBufferState(self) smarteh-dev@680: self.ParentWindow.RefreshTitle() smarteh-dev@680: self.ParentWindow.RefreshFileMenu() smarteh-dev@680: self.ParentWindow.RefreshEditMenu() smarteh-dev@680: self.ParentWindow.RefreshPageTitles() andrej@1730: smarteh-dev@680: def OnNodeSelectedChanged(self, event): smarteh-dev@680: NetworkEditorTemplate.OnNodeSelectedChanged(self, event) laurent@771: wx.CallAfter(self.ParentWindow.RefreshEditMenu)