canfestival/NetworkEditor.py
changeset 1784 64beb9e9c749
parent 1773 38fde37c3766
child 1847 6198190bc121
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    26 
    26 
    27 from subindextable import EditingPanel
    27 from subindextable import EditingPanel
    28 from networkeditortemplate import NetworkEditorTemplate
    28 from networkeditortemplate import NetworkEditorTemplate
    29 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    29 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    30 
    30 
    31 [ID_NETWORKEDITOR, 
    31 [
       
    32     ID_NETWORKEDITOR,
    32 ] = [wx.NewId() for _init_ctrls in range(1)]
    33 ] = [wx.NewId() for _init_ctrls in range(1)]
    33 
    34 
    34 [ID_NETWORKEDITORCONFNODEMENUADDSLAVE, ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, 
    35 [
    35  ID_NETWORKEDITORCONFNODEMENUMASTER, 
    36     ID_NETWORKEDITORCONFNODEMENUADDSLAVE,
       
    37     ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE,
       
    38     ID_NETWORKEDITORCONFNODEMENUMASTER,
    36 ] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(3)]
    39 ] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(3)]
    37 
    40 
    38 [ID_NETWORKEDITORMASTERMENUNODEINFOS, ID_NETWORKEDITORMASTERMENUDS301PROFILE,
    41 [
    39  ID_NETWORKEDITORMASTERMENUDS302PROFILE, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE,
    42     ID_NETWORKEDITORMASTERMENUNODEINFOS, ID_NETWORKEDITORMASTERMENUDS301PROFILE,
    40  ID_NETWORKEDITORMASTERMENUADD, 
    43     ID_NETWORKEDITORMASTERMENUDS302PROFILE, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE,
       
    44     ID_NETWORKEDITORMASTERMENUADD,
    41 ] = [wx.NewId() for _init_coll_MasterMenu_Items in range(5)]
    45 ] = [wx.NewId() for _init_coll_MasterMenu_Items in range(5)]
    42 
    46 
    43 [ID_NETWORKEDITORADDMENUSDOSERVER, ID_NETWORKEDITORADDMENUSDOCLIENT,
    47 [
    44  ID_NETWORKEDITORADDMENUPDOTRANSMIT, ID_NETWORKEDITORADDMENUPDORECEIVE,
    48     ID_NETWORKEDITORADDMENUSDOSERVER, ID_NETWORKEDITORADDMENUSDOCLIENT,
    45  ID_NETWORKEDITORADDMENUMAPVARIABLE, ID_NETWORKEDITORADDMENUUSERTYPE,
    49     ID_NETWORKEDITORADDMENUPDOTRANSMIT, ID_NETWORKEDITORADDMENUPDORECEIVE,
       
    50     ID_NETWORKEDITORADDMENUMAPVARIABLE, ID_NETWORKEDITORADDMENUUSERTYPE,
    46 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
    51 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
    47 
    52 
       
    53 
    48 class NetworkEditor(ConfTreeNodeEditor, NetworkEditorTemplate):
    54 class NetworkEditor(ConfTreeNodeEditor, NetworkEditorTemplate):
    49     
    55 
    50     ID = ID_NETWORKEDITOR
    56     ID = ID_NETWORKEDITOR
    51     CONFNODEEDITOR_TABS = [
    57     CONFNODEEDITOR_TABS = [
    52         (_("CANOpen network"), "_create_NetworkEditor")]
    58         (_("CANOpen network"), "_create_NetworkEditor")]
    53     
    59 
    54     def _create_NetworkEditor(self, prnt):
    60     def _create_NetworkEditor(self, prnt):
    55         self.NetworkEditor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
    61         self.NetworkEditor = wx.Panel(
    56                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
    62             id=-1, parent=prnt, pos=wx.Point(0, 0),
    57         
    63             size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
       
    64 
    58         NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor)
    65         NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor)
    59         
    66 
    60         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
    67         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
    61         main_sizer.AddGrowableCol(0)
    68         main_sizer.AddGrowableCol(0)
    62         main_sizer.AddGrowableRow(0)
    69         main_sizer.AddGrowableRow(0)
    63         
    70 
    64         main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW|wx.ALL)
    71         main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW | wx.ALL)
    65     
    72 
    66         self.NetworkEditor.SetSizer(main_sizer)
    73         self.NetworkEditor.SetSizer(main_sizer)
    67     
    74 
    68         return self.NetworkEditor
    75         return self.NetworkEditor
    69     
    76 
    70     def __init__(self, parent, controler, window):
    77     def __init__(self, parent, controler, window):
    71         ConfTreeNodeEditor.__init__(self, parent, controler, window)
    78         ConfTreeNodeEditor.__init__(self, parent, controler, window)
    72         NetworkEditorTemplate.__init__(self, controler, window, False)
    79         NetworkEditorTemplate.__init__(self, controler, window, False)
    73     
    80 
    74         self.RefreshNetworkNodes()
    81         self.RefreshNetworkNodes()
    75         self.RefreshBufferState()
    82         self.RefreshBufferState()
    76     
    83 
    77     def __del__(self):
    84     def __del__(self):
    78         self.Controler.OnCloseEditor(self)
    85         self.Controler.OnCloseEditor(self)
    79     
    86 
    80     def GetConfNodeMenuItems(self):
    87     def GetConfNodeMenuItems(self):
    81         add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_NETWORKEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
    88         add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_NETWORKEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
    82                     (wx.ITEM_NORMAL, (_('SDO Client'), ID_NETWORKEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
    89                     (wx.ITEM_NORMAL, (_('SDO Client'), ID_NETWORKEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
    83                     (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_NETWORKEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
    90                     (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_NETWORKEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
    84                     (wx.ITEM_NORMAL, (_('PDO Receive'), ID_NETWORKEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
    91                     (wx.ITEM_NORMAL, (_('PDO Receive'), ID_NETWORKEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
    85                     (wx.ITEM_NORMAL, (_('Map Variable'), ID_NETWORKEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
    92                     (wx.ITEM_NORMAL, (_('Map Variable'), ID_NETWORKEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
    86                     (wx.ITEM_NORMAL, (_('User Type'), ID_NETWORKEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
    93                     (wx.ITEM_NORMAL, (_('User Type'), ID_NETWORKEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
    87         
    94 
    88         profile = self.Manager.GetCurrentProfileName()
    95         profile = self.Manager.GetCurrentProfileName()
    89         if profile not in ("None", "DS-301"):
    96         if profile not in ("None", "DS-301"):
    90             other_profile_text = _("%s Profile") % profile
    97             other_profile_text = _("%s Profile") % profile
    91             add_menu.append((wx.ITEM_SEPARATOR, None))
    98             add_menu.append((wx.ITEM_SEPARATOR, None))
    92             for text, indexes in self.Manager.GetCurrentSpecificMenu():
    99             for text, indexes in self.Manager.GetCurrentSpecificMenu():
    93                 add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
   100                 add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
    94         else:
   101         else:
    95             other_profile_text = _('Other Profile')
   102             other_profile_text = _('Other Profile')
    96         
   103 
    97         master_menu = [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_NETWORKEDITORMASTERMENUDS301PROFILE, '', self.OnCommunicationMenu)),
   104         master_menu = [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_NETWORKEDITORMASTERMENUDS301PROFILE, '', self.OnCommunicationMenu)),
    98                        (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_NETWORKEDITORMASTERMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
   105                        (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_NETWORKEDITORMASTERMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
    99                        (wx.ITEM_NORMAL, (other_profile_text, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
   106                        (wx.ITEM_NORMAL, (other_profile_text, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
   100                        (wx.ITEM_SEPARATOR, None),
   107                        (wx.ITEM_SEPARATOR, None),
   101                        (add_menu, (_('Add'), ID_NETWORKEDITORMASTERMENUADD))]
   108                        (add_menu, (_('Add'), ID_NETWORKEDITORMASTERMENUADD))]
   102         
   109 
   103         return [(wx.ITEM_NORMAL, (_('Add slave'), ID_NETWORKEDITORCONFNODEMENUADDSLAVE, '', self.OnAddSlaveMenu)),
   110         return [(wx.ITEM_NORMAL, (_('Add slave'), ID_NETWORKEDITORCONFNODEMENUADDSLAVE, '', self.OnAddSlaveMenu)),
   104                 (wx.ITEM_NORMAL, (_('Remove slave'), ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, '', self.OnRemoveSlaveMenu)),
   111                 (wx.ITEM_NORMAL, (_('Remove slave'), ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, '', self.OnRemoveSlaveMenu)),
   105                 (wx.ITEM_SEPARATOR, None),
   112                 (wx.ITEM_SEPARATOR, None),
   106                 (master_menu, (_('Master'), ID_NETWORKEDITORCONFNODEMENUMASTER))]
   113                 (master_menu, (_('Master'), ID_NETWORKEDITORCONFNODEMENUMASTER))]
   107     
   114 
   108     def RefreshMainMenu(self):
   115     def RefreshMainMenu(self):
   109         pass
   116         pass
   110     
   117 
   111     def RefreshConfNodeMenu(self, confnode_menu):
   118     def RefreshConfNodeMenu(self, confnode_menu):
   112         confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0)
   119         confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0)
   113     
   120 
   114     def RefreshView(self):
   121     def RefreshView(self):
   115         ConfTreeNodeEditor.RefreshView(self)
   122         ConfTreeNodeEditor.RefreshView(self)
   116         self.RefreshCurrentIndexList()
   123         self.RefreshCurrentIndexList()
   117     
   124 
   118     def RefreshBufferState(self):
   125     def RefreshBufferState(self):
   119         NetworkEditorTemplate.RefreshBufferState(self)
   126         NetworkEditorTemplate.RefreshBufferState(self)
   120         self.ParentWindow.RefreshTitle()
   127         self.ParentWindow.RefreshTitle()
   121         self.ParentWindow.RefreshFileMenu()
   128         self.ParentWindow.RefreshFileMenu()
   122         self.ParentWindow.RefreshEditMenu()
   129         self.ParentWindow.RefreshEditMenu()
   123         self.ParentWindow.RefreshPageTitles()
   130         self.ParentWindow.RefreshPageTitles()
   124     
   131 
   125     def OnNodeSelectedChanged(self, event):
   132     def OnNodeSelectedChanged(self, event):
   126         NetworkEditorTemplate.OnNodeSelectedChanged(self, event)
   133         NetworkEditorTemplate.OnNodeSelectedChanged(self, event)
   127         wx.CallAfter(self.ParentWindow.RefreshEditMenu)
   134         wx.CallAfter(self.ParentWindow.RefreshEditMenu)