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