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