objdictgen/networkedit.py
author leonid
Wed, 08 Aug 2007 18:40:47 +0200
changeset 257 4f3364846782
parent 254 f2b0acb54e65
child 258 8f7725451453
permissions -rw-r--r--
*** empty log message ***
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     3
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     5
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     7
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     8
#See COPYING file for copyrights details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
     9
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    14
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    18
#Lesser General Public License for more details.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    19
#
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    23
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    24
import wx
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    25
import wx.grid
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    26
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    27
from types import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    28
import os, re, platform, sys, time, traceback, getopt
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    29
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    30
__version__ = "$Revision$"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    31
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    32
from nodelist import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    33
from nodemanager import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    34
from subindextable import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    35
from commondialogs import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    36
from doc_index.DS301_index import *
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    37
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    38
def create(parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    39
    return networkedit(parent)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    40
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    41
def usage():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    42
    print "\nUsage of networkedit.py :"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    43
    print "\n   %s [Projectpath]\n"%sys.argv[0]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    44
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    45
try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    46
    opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    47
except getopt.GetoptError:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    48
    # print help information and exit:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    49
    usage()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    50
    sys.exit(2)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    51
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    52
for o, a in opts:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    53
    if o in ("-h", "--help"):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    54
        usage()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    55
        sys.exit()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    56
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    57
if len(args) == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    58
    projectOpen = None 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    59
elif len(args) == 1:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    60
    projectOpen = args[0]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    61
else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    62
    usage()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    63
    sys.exit(2)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
    64
ScriptDirectory = ""
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
    65
for path in sys.path:
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
    66
    if os.path.isfile(os.path.join(path, "networkedit.py")):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
    67
        ScriptDirectory = path
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    68
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    69
try:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    70
    import wx.html
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    71
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    72
    EVT_HTML_URL_CLICK = wx.NewId()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    73
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    74
    class HtmlWindowUrlClick(wx.PyEvent):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    75
        def __init__(self, linkinfo):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    76
            wx.PyEvent.__init__(self)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    77
            self.SetEventType(EVT_HTML_URL_CLICK)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    78
            self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    79
            
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    80
    class UrlClickHtmlWindow(wx.html.HtmlWindow):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    81
        """ HTML window that generates and OnLinkClicked event.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    82
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    83
        Use this to avoid having to override HTMLWindow
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    84
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    85
        def OnLinkClicked(self, linkinfo):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    86
            wx.PostEvent(self, HtmlWindowUrlClick(linkinfo))
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    87
        
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    88
        def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    89
            if event == HtmlWindowUrlClick:
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    90
                self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    91
            else:
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    92
                wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    93
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    94
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    95
#                                Html Frame
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    96
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    97
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
    98
    [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
    99
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   100
    class HtmlFrame(wx.Frame):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   101
        def _init_ctrls(self, prnt):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   102
            # generated method, don't edit
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   103
            wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   104
                  parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   105
                  style=wx.DEFAULT_FRAME_STYLE, title='')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   106
            self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_HTMLFRAME)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   107
            
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   108
            self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   109
                  name='HtmlContent', parent=self, pos=wx.Point(0, 0),
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   110
                  size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   111
            self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   112
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   113
        def __init__(self, parent, opened):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   114
            self._init_ctrls(parent)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   115
            self.HtmlFrameOpened = opened
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   116
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   117
        def SetHtmlCode(self, htmlcode):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   118
            self.HtmlContent.SetPage(htmlcode)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   119
            
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   120
        def SetHtmlPage(self, htmlpage):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   121
            self.HtmlContent.LoadPage(htmlpage)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   122
            
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   123
        def OnCloseFrame(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   124
            self.HtmlFrameOpened.remove(self.GetTitle())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   125
            event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   126
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   127
        def OnLinkClick(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   128
            url = event.linkinfo[0]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   129
            try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   130
                import webbrowser
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   131
            except ImportError:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   132
                wx.MessageBox('Please point your browser at: %s' % url)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   133
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   134
                webbrowser.open(url)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   135
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   136
    Html_Window = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   137
except:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   138
    Html_Window = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   139
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   140
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   141
[ID_NETWORKEDIT, ID_NETWORKEDITNETWORKNODES, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   142
 ID_NETWORKEDITHELPBAR,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   143
] = [wx.NewId() for _init_ctrls in range(3)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   144
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   145
[ID_NETWORKEDITADDMENUITEMS0, ID_NETWORKEDITADDMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   146
 ID_NETWORKEDITADDMENUITEMS2, ID_NETWORKEDITADDMENUITEMS3, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   147
 ID_NETWORKEDITADDMENUITEMS4, ID_NETWORKEDITADDMENUITEMS5, 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   148
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   149
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   150
[ID_NETWORKEDITFILEMENUITEMS0, ID_NETWORKEDITFILEMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   151
 ID_NETWORKEDITFILEMENUITEMS2, ID_NETWORKEDITFILEMENUITEMS4, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   152
 ID_NETWORKEDITFILEMENUITEMS5, ID_NETWORKEDITFILEMENUITEMS6,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   153
] = [wx.NewId() for _init_coll_FileMenu_Items in range(6)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   154
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   155
[ID_NETWORKEDITNETWORKMENUITEMS0, ID_NETWORKEDITNETWORKMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   156
 ID_NETWORKEDITNETWORKMENUITEMS3, 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   157
] = [wx.NewId() for _init_coll_AddMenu_Items in range(3)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   158
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   159
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   160
[ID_NETWORKEDITEDITMENUITEMS0, ID_NETWORKEDITEDITMENUITEMS1, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   161
 ID_NETWORKEDITEDITMENUITEMS2, ID_NETWORKEDITEDITMENUITEMS4, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   162
 ID_NETWORKEDITEDITMENUITEMS6, ID_NETWORKEDITEDITMENUITEMS7, 
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   163
 ID_NETWORKEDITEDITMENUITEMS8, 
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   164
] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   165
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   166
[ID_NETWORKEDITHELPMENUITEMS0, ID_NETWORKEDITHELPMENUITEMS1,
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   167
 ID_NETWORKEDITHELPMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   168
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   169
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   170
class networkedit(wx.Frame):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   171
    def _init_coll_menuBar1_Menus(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   172
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   173
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   174
        if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   175
            parent.Append(menu=self.FileMenu, title='File')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   176
        parent.Append(menu=self.NetworkMenu, title='Network')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   177
        parent.Append(menu=self.EditMenu, title='Edit')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   178
        parent.Append(menu=self.AddMenu, title='Add')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   179
        parent.Append(menu=self.HelpMenu, title='Help')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   180
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   181
    def _init_coll_EditMenu_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   182
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   183
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   184
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS4,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   185
              kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   186
        parent.AppendSeparator()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   187
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   188
              kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   189
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   190
              kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   191
        parent.AppendSeparator()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   192
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS6,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   193
              kind=wx.ITEM_NORMAL, text='Node infos')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   194
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   195
              kind=wx.ITEM_NORMAL, text='DS-301 Profile')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   196
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS8,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   197
              kind=wx.ITEM_NORMAL, text='DS-302 Profile')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   198
        parent.Append(help='', id=ID_NETWORKEDITEDITMENUITEMS7,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   199
              kind=wx.ITEM_NORMAL, text='Other Profile')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   200
        self.Bind(wx.EVT_MENU, self.OnUndoMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   201
              id=ID_NETWORKEDITEDITMENUITEMS1)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   202
        self.Bind(wx.EVT_MENU, self.OnRedoMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   203
              id=ID_NETWORKEDITEDITMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   204
        self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   205
              id=ID_NETWORKEDITEDITMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   206
        self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   207
              id=ID_NETWORKEDITEDITMENUITEMS4)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   208
        self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   209
              id=ID_NETWORKEDITEDITMENUITEMS6)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   210
        self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   211
              id=ID_NETWORKEDITEDITMENUITEMS7)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   212
        self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   213
              id=ID_NETWORKEDITEDITMENUITEMS8)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   214
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   215
    def _init_coll_HelpMenu_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   216
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   217
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   218
        parent.Append(help='', id=ID_NETWORKEDITHELPMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   219
              kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   220
        self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   221
              id=ID_NETWORKEDITHELPMENUITEMS0)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   222
        parent.Append(help='', id=ID_NETWORKEDITHELPMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   223
              kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   224
        self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   225
              id=ID_NETWORKEDITHELPMENUITEMS1)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   226
        if Html_Window and self.ModeSolo:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   227
            parent.Append(help='', id=ID_NETWORKEDITHELPMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   228
                  kind=wx.ITEM_NORMAL, text='About')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   229
            self.Bind(wx.EVT_MENU, self.OnAboutMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   230
                  id=ID_NETWORKEDITHELPMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   231
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   232
    def _init_coll_FileMenu_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   233
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   234
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   235
        parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS5,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   236
              kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   237
        parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   238
              kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   239
        parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   240
              kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   241
        parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   242
              kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   243
        parent.AppendSeparator()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   244
        parent.Append(help='', id=ID_NETWORKEDITFILEMENUITEMS4,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   245
              kind=wx.ITEM_NORMAL, text='Exit')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   246
        self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   247
              id=ID_NETWORKEDITFILEMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   248
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   249
              id=ID_NETWORKEDITFILEMENUITEMS1)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   250
        self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   251
              id=ID_NETWORKEDITFILEMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   252
        self.Bind(wx.EVT_MENU, self.OnQuitMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   253
              id=ID_NETWORKEDITFILEMENUITEMS4)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   254
        self.Bind(wx.EVT_MENU, self.OnNewProjectMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   255
              id=ID_NETWORKEDITFILEMENUITEMS5)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   256
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   257
    def _init_coll_NetworkMenu_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   258
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   259
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   260
        parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   261
              kind=wx.ITEM_NORMAL, text='Add Slave Node')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   262
        parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   263
              kind=wx.ITEM_NORMAL, text='Remove Slave Node')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   264
        parent.AppendSeparator()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   265
        parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUITEMS3,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   266
              kind=wx.ITEM_NORMAL, text='Build Master Dictionary')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   267
        self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   268
              id=ID_NETWORKEDITNETWORKMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   269
        self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   270
              id=ID_NETWORKEDITNETWORKMENUITEMS1)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   271
##        self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   272
##              id=ID_NETWORKEDITNETWORKMENUITEMS3)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   273
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   274
    def _init_coll_AddMenu_Items(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   275
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   276
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   277
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS0,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   278
              kind=wx.ITEM_NORMAL, text='SDO Server')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   279
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS1,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   280
              kind=wx.ITEM_NORMAL, text='SDO Client')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   281
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS2,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   282
              kind=wx.ITEM_NORMAL, text='PDO Transmit')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   283
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS3,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   284
              kind=wx.ITEM_NORMAL, text='PDO Receive')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   285
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS4,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   286
              kind=wx.ITEM_NORMAL, text='Map Variable')
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   287
        parent.Append(help='', id=ID_NETWORKEDITADDMENUITEMS5,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   288
              kind=wx.ITEM_NORMAL, text='User Type')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   289
        self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   290
              id=ID_NETWORKEDITADDMENUITEMS0)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   291
        self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   292
              id=ID_NETWORKEDITADDMENUITEMS1)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   293
        self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   294
              id=ID_NETWORKEDITADDMENUITEMS2)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   295
        self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   296
              id=ID_NETWORKEDITADDMENUITEMS3)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   297
        self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   298
              id=ID_NETWORKEDITADDMENUITEMS4)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   299
        self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   300
              id=ID_NETWORKEDITADDMENUITEMS5)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   301
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   302
    def _init_coll_HelpBar_Fields(self, parent):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   303
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   304
        parent.SetFieldsCount(3)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   305
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   306
        parent.SetStatusText(number=0, text='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   307
        parent.SetStatusText(number=1, text='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   308
        parent.SetStatusText(number=2, text='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   309
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   310
        parent.SetStatusWidths([100, 110, -1])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   311
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   312
    def _init_utils(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   313
        # generated method, don't edit
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   314
        self.menuBar1 = wx.MenuBar()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   315
        self.menuBar1.SetEvtHandlerEnabled(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   316
        
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   317
        if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   318
            self.FileMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   319
        self.NetworkMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   320
        self.EditMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   321
        self.AddMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   322
        self.HelpMenu = wx.Menu(title='')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   323
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   324
        self._init_coll_menuBar1_Menus(self.menuBar1)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   325
        if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   326
            self._init_coll_FileMenu_Items(self.FileMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   327
        self._init_coll_NetworkMenu_Items(self.NetworkMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   328
        self._init_coll_EditMenu_Items(self.EditMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   329
        self._init_coll_AddMenu_Items(self.AddMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   330
        self._init_coll_HelpMenu_Items(self.HelpMenu)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   331
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   332
    def _init_ctrls(self, prnt):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   333
        # generated method, don't edit
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   334
        wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit',
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   335
              parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   336
              style=wx.DEFAULT_FRAME_STYLE, title='Networkedit')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   337
        self._init_utils()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   338
        self.SetClientSize(wx.Size(1000, 700))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   339
        self.SetMenuBar(self.menuBar1)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   340
        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_NETWORKEDIT)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   341
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   342
        self.NetworkNodes = wx.Notebook(id=ID_NETWORKEDITNETWORKNODES,
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   343
              name='NetworkNodes', parent=self, pos=wx.Point(0, 0),
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   344
              size=wx.Size(0, 0), style=wx.NB_LEFT)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   345
        self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   346
              self.OnNodeSelectedChanged, id=ID_NETWORKEDITNETWORKNODES)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   347
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   348
        self.HelpBar = wx.StatusBar(id=ID_NETWORKEDITHELPBAR, name='HelpBar',
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   349
              parent=self, style=wx.ST_SIZEGRIP)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   350
        self._init_coll_HelpBar_Fields(self.HelpBar)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   351
        self.SetStatusBar(self.HelpBar)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   352
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   353
    def __init__(self, parent, nodelist = None):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   354
        self.ModeSolo = nodelist == None
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   355
        self._init_ctrls(parent)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   356
        self.Parent = parent
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   357
        self.HtmlFrameOpened = []
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   358
        self.BusId = None
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   359
        
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   360
        if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   361
            self.Manager = NodeManager(ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   362
            if projectOpen:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   363
                self.NodeList = NodeList(self.Manager)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   364
                result = self.NodeList.LoadProject(projectOpen)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   365
                if not result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   366
                    self.RefreshNetworkNodes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   367
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   368
                self.NodeList = None
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   369
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   370
            self.NodeList = nodelist
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   371
            self.Manager = self.NodeList.GetManager()
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   372
            self.NodeList.SetCurrentSelected(0)
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   373
            self.RefreshNetworkNodes()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   374
            self.RefreshProfileMenu()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   375
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   376
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   377
        self.RefreshTitle()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   378
        self.RefreshMainMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   379
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   380
    def SetBusId(self, bus_id):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   381
        self.BusId = bus_id
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   382
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   383
    def GetBusId(self):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   384
        return self.BusId
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   385
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   386
    def GetCurrentNodeId(self):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   387
        selected = self.NetworkNodes.GetSelection()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   388
        # At init selected = -1
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   389
        if selected > 0:
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   390
            window = self.NetworkNodes.GetPage(selected)
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   391
            return window.GetIndex()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   392
        else:
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   393
            return 0
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   394
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   395
    def OnCloseFrame(self, event):
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   396
        if not self.ModeSolo:
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   397
            self.Parent.CloseEditor(self.BusId)
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   398
        event.Skip()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   399
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   400
    def GetNoteBook(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   401
        return self.NetworkNodes
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   402
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   403
    def OnQuitMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   404
        self.Close()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   405
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   406
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   407
    def OnAddSDOServerMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   408
        self.Manager.AddSDOServerToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   409
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   410
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   411
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   412
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   413
    def OnAddSDOClientMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   414
        self.Manager.AddSDOClientToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   415
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   416
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   417
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   418
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   419
    def OnAddPDOTransmitMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   420
        self.Manager.AddPDOTransmitToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   421
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   422
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   423
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   424
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   425
    def OnAddPDOReceiveMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   426
        self.Manager.AddPDOReceiveToCurrent()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   427
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   428
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   429
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   430
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   431
    def OnAddMapVariableMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   432
        self.AddMapVariable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   433
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   434
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   435
    def OnAddUserTypeMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   436
        self.AddUserType()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   437
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   438
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   439
    def OnNodeSelectedChanged(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   440
        selected = event.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   441
        # At init selected = -1
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   442
        if selected > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   443
            window = self.NetworkNodes.GetPage(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   444
            self.NodeList.SetCurrentSelected(window.GetIndex())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   445
        self.RefreshMainMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   446
        self.RefreshStatusBar()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   447
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   448
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   449
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   450
#                         Load and Save Funtions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   451
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   452
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   453
    def OnNewProjectMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   454
        if self.NodeList:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   455
            defaultpath = os.path.dirname(self.NodeList.GetRoot())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   456
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   457
            defaultpath = os.getcwd()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   458
        dialog = wx.DirDialog(self , "Choose a project", defaultpath, wx.DD_NEW_DIR_BUTTON)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   459
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   460
            projectpath = dialog.GetPath()
206
6787754b251b Bugs corrected on objdictedit and networkdict
greg
parents: 205
diff changeset
   461
            if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   462
                os.mkdir(os.path.join(projectpath, "eds"))
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   463
                manager = NodeManager(ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   464
                nodelist = NodeList(manager)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   465
                result = nodelist.LoadProject(projectpath)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   466
                if not result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   467
                    self.Manager = manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   468
                    self.NodeList = nodelist
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   469
                    self.NodeList.SetCurrentSelected(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   470
                                        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   471
                    self.RefreshNetworkNodes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   472
                    self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   473
                    self.RefreshTitle()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   474
                    self.RefreshProfileMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   475
                    self.RefreshMainMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   476
                else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   477
                    message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   478
                    message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   479
                    message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   480
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   481
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   482
    def OnOpenProjectMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   483
        if self.NodeList:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   484
            defaultpath = os.path.dirname(self.NodeList.GetRoot())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   485
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   486
            defaultpath = os.getcwd()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   487
        dialog = wx.DirDialog(self , "Choose a project", defaultpath, 0)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   488
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   489
            projectpath = dialog.GetPath()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   490
            if os.path.isdir(projectpath):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   491
                manager = NodeManager(ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   492
                nodelist = NodeList(manager)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   493
                result = nodelist.LoadProject(projectpath)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   494
                if not result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   495
                    self.Manager = manager
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   496
                    self.NodeList = nodelist
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   497
                    self.NodeList.SetCurrentSelected(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   498
                    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   499
                    self.RefreshNetworkNodes()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   500
                    self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   501
                    self.RefreshTitle()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   502
                    self.RefreshProfileMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   503
                    self.RefreshMainMenu()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   504
                else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   505
                    message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   506
                    message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   507
                    message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   508
        dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   509
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   510
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   511
    def OnSaveProjectMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   512
        result = self.NodeList.SaveProject()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   513
        if result:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   514
            message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   515
            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   516
            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   517
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   518
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   519
    def OnCloseProjectMenu(self, event):
238
be485a93e3f7 add profile callback
greg
parents: 206
diff changeset
   520
        if self.NodeList:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   521
            if self.NodeList.HasChanged():
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   522
                dialog = wx.MessageDialog(self, "There are changes, do you want to save?",  "Close Project", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   523
                answer = dialog.ShowModal()
238
be485a93e3f7 add profile callback
greg
parents: 206
diff changeset
   524
                dialog.Destroy()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   525
                if answer == wx.ID_YES:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   526
                    result = self.NodeList.SaveProject()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   527
                    if result:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   528
                        message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   529
                        message.ShowModal()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   530
                        message.Destroy()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   531
                elif answer == wx.ID_NO:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   532
                    self.NodeList.ForceChanged(False)
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   533
            if not self.NodeList.HasChanged():
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   534
                self.Manager = None
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   535
                self.NodeList = None
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   536
                self.RefreshNetworkNodes()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   537
                self.RefreshTitle()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   538
                self.RefreshMainMenu()
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   539
        event.Skip()
238
be485a93e3f7 add profile callback
greg
parents: 206
diff changeset
   540
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   541
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   542
#                             Slave Nodes Management
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   543
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   544
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   545
    def OnAddSlaveMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   546
        dialog = AddSlaveDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   547
        dialog.SetNodeList(self.NodeList)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   548
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   549
            values = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   550
            result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   551
            if not result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   552
                new_editingpanel = EditingPanel(self, self.NodeList, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   553
                new_editingpanel.SetIndex(values["slaveNodeID"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   554
                idx = self.NodeList.GetOrderNumber(values["slaveNodeID"])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   555
                self.NetworkNodes.InsertPage(idx, new_editingpanel, "")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   556
                self.NodeList.SetCurrentSelected(idx)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   557
                self.NetworkNodes.SetSelection(idx)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   558
                self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   559
            else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   560
                message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   561
                message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   562
                message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   563
        dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   564
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   565
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   566
    def OnRemoveSlaveMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   567
        slavenames = self.NodeList.GetSlaveNames()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   568
        slaveids = self.NodeList.GetSlaveIDs()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   569
        dialog = wx.SingleChoiceDialog(self, "Choose a slave to remove", "Remove slave", slavenames)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   570
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   571
            choice = dialog.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   572
            result = self.NodeList.RemoveSlaveNode(slaveids[choice])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   573
            if not result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   574
                slaveids.pop(choice)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   575
                current = self.NetworkNodes.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   576
                self.NetworkNodes.DeletePage(choice + 1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   577
                if self.NetworkNodes.GetPageCount() > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   578
                    new_selection = min(current, self.NetworkNodes.GetPageCount() - 1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   579
                    self.NetworkNodes.SetSelection(new_selection)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   580
                    if new_selection > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   581
                        self.NodeList.SetCurrentSelected(slaveids[new_selection - 1])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   582
                    self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   583
            else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   584
                message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   585
                message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   586
                message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   587
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   588
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   589
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   590
#                             Refresh Functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   591
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   592
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   593
    def RefreshTitle(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   594
        if self.NodeList != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   595
            self.SetTitle("Networkedit - %s"%self.NodeList.GetNetworkName())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   596
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   597
            self.SetTitle("Networkedit")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   598
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   599
    def OnRefreshMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   600
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   601
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   602
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   603
    def RefreshCurrentIndexList(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   604
        selected = self.NetworkNodes.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   605
        if selected == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   606
            window = self.NetworkNodes.GetPage(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   607
            window.RefreshIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   608
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   609
            pass
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   610
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   611
    def RefreshNetworkNodes(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   612
        if self.NetworkNodes.GetPageCount() > 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   613
            self.NetworkNodes.DeleteAllPages()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   614
        if self.NodeList:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   615
            new_editingpanel = EditingPanel(self, self.Manager)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   616
            new_editingpanel.SetIndex(0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   617
            self.NetworkNodes.AddPage(new_editingpanel, "")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   618
            for idx in self.NodeList.GetSlaveIDs():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   619
                new_editingpanel = EditingPanel(self, self.NodeList, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   620
                new_editingpanel.SetIndex(idx)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   621
                self.NetworkNodes.AddPage(new_editingpanel, "")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   622
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   623
    def RefreshStatusBar(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   624
        if self.HelpBar:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   625
            window = self.NetworkNodes.GetPage(self.NetworkNodes.GetSelection())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   626
            selection = window.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   627
            if selection:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   628
                index, subIndex = selection
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   629
                if self.NodeList.IsCurrentEntry(index):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   630
                    self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   631
                    self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   632
                    entryinfos = self.NodeList.GetEntryInfos(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   633
                    name = entryinfos["name"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   634
                    category = "Optional"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   635
                    if entryinfos["need"]:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   636
                        category = "Mandatory"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   637
                    struct = "VAR"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   638
                    number = ""
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   639
                    if entryinfos["struct"] & OD_IdenticalIndexes:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   640
                        number = " possibly defined %d times"%entryinfos["nbmax"]
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   641
                    if entryinfos["struct"] & OD_IdenticalSubindexes:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   642
                        struct = "REC"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   643
                    elif entryinfos["struct"] & OD_MultipleSubindexes:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   644
                        struct = "ARRAY"
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   645
                    text = "%s: %s entry of struct %s%s."%(name,category,struct,number)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   646
                    self.HelpBar.SetStatusText(text, 2)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   647
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   648
                    for i in xrange(3):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   649
                        self.HelpBar.SetStatusText("", i)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   650
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   651
                for i in xrange(3):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   652
                    self.HelpBar.SetStatusText("", i)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   653
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   654
    def RefreshMainMenu(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   655
        if self.menuBar1:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   656
            self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUITEMS3, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   657
            if self.NodeList == None:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   658
                if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   659
                    self.menuBar1.EnableTop(1, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   660
                    self.menuBar1.EnableTop(2, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   661
                    self.menuBar1.EnableTop(3, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   662
                    if self.FileMenu:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   663
                        self.FileMenu.Enable(ID_NETWORKEDITFILEMENUITEMS1, False)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   664
                        self.FileMenu.Enable(ID_NETWORKEDITFILEMENUITEMS2, False)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   665
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   666
                    self.menuBar1.EnableTop(0, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   667
                    self.menuBar1.EnableTop(1, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   668
                    self.menuBar1.EnableTop(2, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   669
            else:
242
4864f7f01e1d Changes in networkedit for integration with beremiz
lbessard
parents: 238
diff changeset
   670
                if self.ModeSolo:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   671
                    self.menuBar1.EnableTop(1, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   672
                    if self.FileMenu:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   673
                        self.FileMenu.Enable(ID_NETWORKEDITFILEMENUITEMS1, True)
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   674
                        self.FileMenu.Enable(ID_NETWORKEDITFILEMENUITEMS2, True)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   675
                    if self.NetworkNodes.GetSelection() == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   676
                        self.menuBar1.EnableTop(2, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   677
                        self.menuBar1.EnableTop(3, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   678
                    else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   679
                        self.menuBar1.EnableTop(2, False)      
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   680
                        self.menuBar1.EnableTop(3, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   681
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   682
                    self.menuBar1.EnableTop(0, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   683
                    if self.NetworkNodes.GetSelection() == 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   684
                        self.menuBar1.EnableTop(1, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   685
                        self.menuBar1.EnableTop(2, True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   686
                    else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   687
                        self.menuBar1.EnableTop(1, False)      
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   688
                        self.menuBar1.EnableTop(2, False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   689
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   690
    def RefreshProfileMenu(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   691
        if self.EditMenu:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   692
            profile = self.Manager.GetCurrentProfileName()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   693
            edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUITEMS7)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   694
            if edititem:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   695
                length = self.AddMenu.GetMenuItemCount()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   696
                for i in xrange(length-6):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   697
                    additem = self.AddMenu.FindItemByPosition(6)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   698
                    self.AddMenu.Delete(additem.GetId())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   699
                if profile not in ("None", "DS-301"):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   700
                    edititem.SetText("%s Profile"%profile)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   701
                    edititem.Enable(True)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   702
                    self.AddMenu.AppendSeparator()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   703
                    for text, indexes in self.Manager.GetCurrentSpecificMenu():
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   704
                        new_id = wx.NewId()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   705
                        self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   706
                        self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   707
                else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   708
                    edititem.SetText("Other Profile")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   709
                    edititem.Enable(False)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   710
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   711
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   712
#                              Buffer Functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   713
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   714
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   715
    def RefreshBufferState(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   716
        if self.NodeList:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   717
            nodeID = self.Manager.GetCurrentNodeID()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   718
            if nodeID != None:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   719
                nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName())
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   720
            else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   721
                nodename = self.Manager.GetCurrentNodeName()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   722
            self.NetworkNodes.SetPageText(0, nodename)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   723
            for idx, name in enumerate(self.NodeList.GetSlaveNames()):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   724
                self.NetworkNodes.SetPageText(idx + 1, name)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   725
            self.RefreshTitle()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   726
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   727
    def OnUndoMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   728
        self.Manager.LoadCurrentPrevious()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   729
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   730
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   731
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   732
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   733
    def OnRedoMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   734
        self.Manager.LoadCurrentNext()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   735
        self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   736
        self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   737
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   738
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   739
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   740
#                                Help Method
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   741
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   742
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   743
    def OnHelpDS301Menu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   744
        find_index = False
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   745
        selected = self.NetworkNodes.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   746
        if selected >= 0:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   747
            window = self.NetworkNodes.GetPage(selected)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   748
            result = window.GetSelection()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   749
            if result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   750
                find_index = True
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   751
                index, subIndex = result
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   752
                result = OpenPDFDocIndex(index, ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   753
                if type(result) == StringType:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   754
                    message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   755
                    message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   756
                    message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   757
        if not find_index:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   758
            result = OpenPDFDocIndex(None, ScriptDirectory)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   759
            if type(result) == StringType:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   760
                message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   761
                message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   762
                message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   763
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   764
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   765
    def OnHelpCANFestivalMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   766
        #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   767
        os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   768
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   769
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   770
    def OnAboutMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   771
        self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450))
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   772
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   773
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   774
    def OpenHtmlFrame(self, title, file, size):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   775
        if title not in self.HtmlFrameOpened:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   776
            self.HtmlFrameOpened.append(title)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   777
            window = HtmlFrame(self, self.HtmlFrameOpened)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   778
            window.SetTitle(title)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   779
            window.SetHtmlPage(file)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   780
            window.SetClientSize(size)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   781
            window.Show()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   782
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   783
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   784
#                          Editing Profiles functions
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   785
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   786
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   787
    def OnCommunicationMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   788
        dictionary,current = self.Manager.GetCurrentCommunicationLists()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   789
        self.EditProfile("Edit DS-301 Profile", dictionary, current)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   790
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   791
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   792
    def OnOtherCommunicationMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   793
        dictionary,current = self.Manager.GetCurrentDS302Lists()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   794
        self.EditProfile("Edit DS-301 Profile", dictionary, current)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   795
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   796
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   797
    def OnEditProfileMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   798
        title = "Edit %s Profile"%self.Manager.GetCurrentProfileName()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   799
        dictionary,current = self.Manager.GetCurrentProfileLists()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   800
        self.EditProfile(title, dictionary, current)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   801
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   802
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   803
    def EditProfile(self, title, dictionary, current):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   804
        dialog = CommunicationDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   805
        dialog.SetTitle(title)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   806
        dialog.SetIndexDictionary(dictionary)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   807
        dialog.SetCurrentList(current)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   808
        dialog.RefreshLists()
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   809
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   810
            new_profile = dialog.GetCurrentList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   811
            addinglist = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   812
            removinglist = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   813
            for index in new_profile:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   814
                if index not in current:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   815
                    addinglist.append(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   816
            for index in current:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   817
                if index not in new_profile:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   818
                    removinglist.append(index)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   819
            self.Manager.ManageEntriesOfCurrent(addinglist, removinglist)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   820
            self.Manager.GenerateMapList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   821
            self.Manager.BufferCurrentNode()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   822
            self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   823
            self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   824
        dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   825
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   826
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   827
#                         Edit Node informations function
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   828
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   829
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   830
    def OnNodeInfosMenu(self, event):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   831
        dialog = NodeInfosDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   832
        name, id, type, description = self.Manager.GetCurrentNodeInfos()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   833
        dialog.SetValues(name, id, type, description)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   834
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   835
            name, id, type, description = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   836
            self.Manager.SetCurrentNodeInfos(name, id, type, description)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   837
            self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   838
            self.RefreshProfileMenu()
243
7fcc129a06ce Some bugs fixed
lbessard
parents: 242
diff changeset
   839
            selected = self.NetworkNodes.GetSelection()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   840
            if selected >= 0:
243
7fcc129a06ce Some bugs fixed
lbessard
parents: 242
diff changeset
   841
                window = self.NetworkNodes.GetPage(selected)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   842
                window.RefreshTable()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   843
        event.Skip()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   844
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   845
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   846
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   847
#                           Add User Types and Variables
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   848
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   849
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   850
    def AddMapVariable(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   851
        index = self.Manager.GetCurrentNextMapIndex()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   852
        if index:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   853
            dialog = MapVariableDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   854
            dialog.SetIndex(index)
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   855
            if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   856
                index, name, struct, number = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   857
                result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   858
                if type(result) != StringType:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   859
                    self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   860
                    self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   861
                else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   862
                    message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   863
                    message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   864
                    message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   865
            dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   866
        else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   867
            message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   868
            message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   869
            message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   870
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   871
    def AddUserType(self):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   872
        dialog = UserTypeDialog(self)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   873
        dialog.SetTypeList(self.Manager.GetCustomisableTypes())
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   874
        if dialog.ShowModal() == wx.ID_OK:
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   875
            type, min, max, length = dialog.GetValues()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   876
            result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   877
            if not IsOfType(result, StringType):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   878
                self.RefreshBufferState()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   879
                self.RefreshCurrentIndexList()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   880
            else:
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   881
                message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   882
                message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   883
                message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   884
        dialog.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   885
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   886
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   887
#                               Exception Handler
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   888
#-------------------------------------------------------------------------------
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   889
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   890
Max_Traceback_List_Size = 20
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   891
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   892
def Display_Exception_Dialog(e_type,e_value,e_tb):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   893
    trcbck_lst = []
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   894
    for i,line in enumerate(traceback.extract_tb(e_tb)):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   895
        trcbck = " " + str(i+1) + ". "
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   896
        if line[0].find(os.getcwd()) == -1:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   897
            trcbck += "file : " + str(line[0]) + ",   "
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   898
        else:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   899
            trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ",   "
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   900
        trcbck += "line : " + str(line[1]) + ",   " + "function : " + str(line[2])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   901
        trcbck_lst.append(trcbck)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   902
        
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   903
    # Allow clicking....
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   904
    cap = wx.Window_GetCapture()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   905
    if cap:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   906
        cap.ReleaseMouse()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   907
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   908
    dlg = wx.SingleChoiceDialog(None, 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   909
        """
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   910
An error happens.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   911
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   912
Click on OK for saving an error report.
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   913
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   914
Please contact LOLITech at:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   915
+33 (0)3 29 52 95 67
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   916
bugs_networkedit@lolitech.fr
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   917
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   918
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   919
Error:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   920
""" +
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   921
        str(e_type) + " : " + str(e_value), 
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   922
        "Error",
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   923
        trcbck_lst)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   924
    try:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   925
        res = (dlg.ShowModal() == wx.ID_OK)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   926
    finally:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   927
        dlg.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   928
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   929
    return res
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   930
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   931
def Display_Error_Dialog(e_value):
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   932
    message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   933
    message.ShowModal()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   934
    message.Destroy()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   935
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   936
def get_last_traceback(tb):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   937
    while tb.tb_next:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   938
        tb = tb.tb_next
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   939
    return tb
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   940
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   941
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   942
def format_namespace(d, indent='    '):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   943
    return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   944
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   945
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   946
ignored_exceptions = [] # a problem with a line in a module is only reported once per session
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   947
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   948
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   949
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   950
    def handle_exception(e_type, e_value, e_traceback):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   951
        traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   952
        last_tb = get_last_traceback(e_traceback)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   953
        ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   954
        if str(e_value).startswith("!!!"):
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   955
            Display_Error_Dialog(e_value)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   956
        elif ex not in ignored_exceptions:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   957
            ignored_exceptions.append(ex)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   958
            result = Display_Exception_Dialog(e_type,e_value,e_traceback)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   959
            if result:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   960
                info = {
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   961
                    'app-title' : wx.GetApp().GetAppName(), # app_title
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   962
                    'app-version' : app_version,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   963
                    'wx-version' : wx.VERSION_STRING,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   964
                    'wx-platform' : wx.Platform,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   965
                    'python-version' : platform.python_version(), #sys.version.split()[0],
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   966
                    'platform' : platform.platform(),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   967
                    'e-type' : e_type,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   968
                    'e-value' : e_value,
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   969
                    'date' : time.ctime(),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   970
                    'cwd' : os.getcwd(),
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   971
                    }
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   972
                if e_traceback:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   973
                    info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   974
                    last_tb = get_last_traceback(e_traceback)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   975
                    exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   976
                    info['locals'] = format_namespace(exception_locals)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   977
                    if 'self' in exception_locals:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   978
                        info['self'] = format_namespace(exception_locals['self'].__dict__)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   979
                
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   980
                output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w')
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   981
                lst = info.keys()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   982
                lst.sort()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   983
                for a in lst:
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   984
                    output.write(a+":\n"+str(info[a])+"\n\n")
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   985
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   986
    #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   987
    sys.excepthook = handle_exception
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   988
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   989
if __name__ == '__main__':
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   990
    app = wx.PySimpleApp()
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   991
    wx.InitAllImageHandlers()
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   992
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   993
    # Install a exception handle for bug reports
254
f2b0acb54e65 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 243
diff changeset
   994
    AddExceptHook(os.getcwd(),__version__)
205
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   995
    
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   996
    frame = networkedit(None)
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   997
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   998
    frame.Show()
dac0f9b4e3f8 Adding program for network management
lbessard
parents:
diff changeset
   999
    app.MainLoop()