canfestival/NetworkEditor.py
author Edouard Tisserant
Wed, 06 Mar 2013 17:05:56 +0900
changeset 964 e3edaf98a44a
parent 920 1499a4d225db
child 1003 de812e258213
permissions -rw-r--r--
merge
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     1
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     2
import wx
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     3
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     4
from subindextable import EditingPanel
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     5
from networkedit import NetworkEditorTemplate
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents: 771
diff changeset
     6
from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     7
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     8
[ID_NETWORKEDITOR, 
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
     9
] = [wx.NewId() for _init_ctrls in range(1)]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    10
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    11
[ID_NETWORKEDITORCONFNODEMENUADDSLAVE, ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, 
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    12
 ID_NETWORKEDITORCONFNODEMENUMASTER, 
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    13
] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(3)]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    14
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    15
[ID_NETWORKEDITORMASTERMENUNODEINFOS, ID_NETWORKEDITORMASTERMENUDS301PROFILE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    16
 ID_NETWORKEDITORMASTERMENUDS302PROFILE, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    17
 ID_NETWORKEDITORMASTERMENUADD, 
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    18
] = [wx.NewId() for _init_coll_MasterMenu_Items in range(5)]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    19
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    20
[ID_NETWORKEDITORADDMENUSDOSERVER, ID_NETWORKEDITORADDMENUSDOCLIENT,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    21
 ID_NETWORKEDITORADDMENUPDOTRANSMIT, ID_NETWORKEDITORADDMENUPDORECEIVE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    22
 ID_NETWORKEDITORADDMENUMAPVARIABLE, ID_NETWORKEDITORADDMENUUSERTYPE,
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    23
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    24
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 738
diff changeset
    25
class NetworkEditor(ConfTreeNodeEditor, NetworkEditorTemplate):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    26
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    27
    ID = ID_NETWORKEDITOR
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    28
    CONFNODEEDITOR_TABS = [
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    29
        (_("CANOpen network"), "_create_NetworkEditor")]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    30
    
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    31
    def _create_NetworkEditor(self, prnt):
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    32
        self.NetworkEditor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    33
                size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    34
        
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    35
        NetworkEditorTemplate._init_ctrls(self, self.NetworkEditor)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    36
        
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    37
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    38
        main_sizer.AddGrowableCol(0)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    39
        main_sizer.AddGrowableRow(0)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    40
        
920
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    41
        main_sizer.AddWindow(self.NetworkNodes, 0, border=5, flag=wx.GROW|wx.ALL)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    42
    
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    43
        self.NetworkEditor.SetSizer(main_sizer)
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    44
    
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    45
        return self.NetworkEditor
1499a4d225db Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents: 845
diff changeset
    46
    
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    47
    def __init__(self, parent, controler, window):
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 738
diff changeset
    48
        ConfTreeNodeEditor.__init__(self, parent, controler, window)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    49
        NetworkEditorTemplate.__init__(self, controler, window, False)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    50
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    51
        self.RefreshNetworkNodes()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    52
        self.RefreshBufferState()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    53
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    54
    def __del__(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    55
        self.Controler.OnCloseEditor(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    56
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    57
    def GetConfNodeMenuItems(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    58
        add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_NETWORKEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    59
                    (wx.ITEM_NORMAL, (_('SDO Client'), ID_NETWORKEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    60
                    (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_NETWORKEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    61
                    (wx.ITEM_NORMAL, (_('PDO Receive'), ID_NETWORKEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    62
                    (wx.ITEM_NORMAL, (_('Map Variable'), ID_NETWORKEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    63
                    (wx.ITEM_NORMAL, (_('User Type'), ID_NETWORKEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    64
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    65
        profile = self.Manager.GetCurrentProfileName()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    66
        if profile not in ("None", "DS-301"):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    67
            other_profile_text = _("%s Profile") % profile
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    68
            add_menu.append((wx.ITEM_SEPARATOR, None))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    69
            for text, indexes in self.Manager.GetCurrentSpecificMenu():
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    70
                add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    71
        else:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    72
            other_profile_text = _('Other Profile')
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    73
        
845
412a9f05070f Fixing CanFestival master and slave nodeid when generating code for PLC
laurent
parents: 814
diff changeset
    74
        master_menu = [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_NETWORKEDITORMASTERMENUDS301PROFILE, '', self.OnCommunicationMenu)),
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    75
                       (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_NETWORKEDITORMASTERMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    76
                       (wx.ITEM_NORMAL, (other_profile_text, ID_NETWORKEDITORMASTERMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    77
                       (wx.ITEM_SEPARATOR, None),
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    78
                       (add_menu, (_('Add'), ID_NETWORKEDITORMASTERMENUADD))]
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    79
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    80
        return [(wx.ITEM_NORMAL, (_('Add slave'), ID_NETWORKEDITORCONFNODEMENUADDSLAVE, '', self.OnAddSlaveMenu)),
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    81
                (wx.ITEM_NORMAL, (_('Remove slave'), ID_NETWORKEDITORCONFNODEMENUREMOVESLAVE, '', self.OnRemoveSlaveMenu)),
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    82
                (wx.ITEM_SEPARATOR, None),
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    83
                (master_menu, (_('Master'), ID_NETWORKEDITORCONFNODEMENUMASTER))]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    84
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    85
    def RefreshMainMenu(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    86
        pass
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    87
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    88
    def RefreshConfNodeMenu(self, confnode_menu):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 680
diff changeset
    89
        confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    90
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    91
    def RefreshView(self):
762
aaacc83aa86b Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents: 738
diff changeset
    92
        ConfTreeNodeEditor.RefreshView(self)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    93
        self.RefreshCurrentIndexList()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    94
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    95
    def RefreshBufferState(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    96
        NetworkEditorTemplate.RefreshBufferState(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    97
        self.ParentWindow.RefreshTitle()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    98
        self.ParentWindow.RefreshFileMenu()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
    99
        self.ParentWindow.RefreshEditMenu()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
   100
        self.ParentWindow.RefreshPageTitles()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
   101
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
   102
    def OnNodeSelectedChanged(self, event):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents:
diff changeset
   103
        NetworkEditorTemplate.OnNodeSelectedChanged(self, event)
771
85d33a130a5c Moving ConfNode specific menu to end of EditMenu
laurent
parents: 762
diff changeset
   104
        wx.CallAfter(self.ParentWindow.RefreshEditMenu)