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