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