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