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