author | greg |
Wed, 14 Oct 2009 16:37:37 +0200 | |
changeset 609 | c59dce78bbad |
parent 580 | 2ae92a99ac10 |
child 608 | daa1e1c3fba4 |
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() |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
397 |
event.Skip() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
398 |
|
205 | 399 |
def OnQuitMenu(self, event): |
400 |
self.Close() |
|
401 |
event.Skip() |
|
402 |
||
403 |
def OnAddSDOServerMenu(self, event): |
|
404 |
self.Manager.AddSDOServerToCurrent() |
|
405 |
self.RefreshBufferState() |
|
406 |
self.RefreshCurrentIndexList() |
|
407 |
event.Skip() |
|
408 |
||
409 |
def OnAddSDOClientMenu(self, event): |
|
410 |
self.Manager.AddSDOClientToCurrent() |
|
411 |
self.RefreshBufferState() |
|
412 |
self.RefreshCurrentIndexList() |
|
413 |
event.Skip() |
|
414 |
||
415 |
def OnAddPDOTransmitMenu(self, event): |
|
416 |
self.Manager.AddPDOTransmitToCurrent() |
|
417 |
self.RefreshBufferState() |
|
418 |
self.RefreshCurrentIndexList() |
|
419 |
event.Skip() |
|
420 |
||
421 |
def OnAddPDOReceiveMenu(self, event): |
|
422 |
self.Manager.AddPDOReceiveToCurrent() |
|
423 |
self.RefreshBufferState() |
|
424 |
self.RefreshCurrentIndexList() |
|
425 |
event.Skip() |
|
426 |
||
427 |
def OnAddMapVariableMenu(self, event): |
|
428 |
self.AddMapVariable() |
|
429 |
event.Skip() |
|
430 |
||
431 |
def OnAddUserTypeMenu(self, event): |
|
432 |
self.AddUserType() |
|
433 |
event.Skip() |
|
434 |
||
435 |
def OnNodeSelectedChanged(self, event): |
|
491 | 436 |
if not self.Closing: |
437 |
selected = event.GetSelection() |
|
438 |
# At init selected = -1 |
|
439 |
if selected >= 0: |
|
440 |
window = self.NetworkNodes.GetPage(selected) |
|
441 |
self.NodeList.SetCurrentSelected(window.GetIndex()) |
|
442 |
wx.CallAfter(self.RefreshMainMenu) |
|
443 |
wx.CallAfter(self.RefreshStatusBar) |
|
205 | 444 |
event.Skip() |
445 |
||
446 |
#------------------------------------------------------------------------------- |
|
447 |
# Load and Save Funtions |
|
448 |
#------------------------------------------------------------------------------- |
|
449 |
||
450 |
def OnNewProjectMenu(self, event): |
|
451 |
if self.NodeList: |
|
452 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
453 |
else: |
|
454 |
defaultpath = os.getcwd() |
|
580 | 455 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
456 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 457 |
projectpath = dialog.GetPath() |
206 | 458 |
if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: |
258 | 459 |
manager = NodeManager() |
205 | 460 |
nodelist = NodeList(manager) |
461 |
result = nodelist.LoadProject(projectpath) |
|
462 |
if not result: |
|
463 |
self.Manager = manager |
|
464 |
self.NodeList = nodelist |
|
465 |
self.NodeList.SetCurrentSelected(0) |
|
466 |
||
467 |
self.RefreshNetworkNodes() |
|
468 |
self.RefreshBufferState() |
|
469 |
self.RefreshTitle() |
|
470 |
self.RefreshProfileMenu() |
|
471 |
self.RefreshMainMenu() |
|
472 |
else: |
|
580 | 473 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 474 |
message.ShowModal() |
475 |
message.Destroy() |
|
476 |
event.Skip() |
|
477 |
||
478 |
def OnOpenProjectMenu(self, event): |
|
479 |
if self.NodeList: |
|
480 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
481 |
else: |
|
482 |
defaultpath = os.getcwd() |
|
580 | 483 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, 0) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
484 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 485 |
projectpath = dialog.GetPath() |
486 |
if os.path.isdir(projectpath): |
|
258 | 487 |
manager = NodeManager() |
205 | 488 |
nodelist = NodeList(manager) |
489 |
result = nodelist.LoadProject(projectpath) |
|
490 |
if not result: |
|
491 |
self.Manager = manager |
|
492 |
self.NodeList = nodelist |
|
493 |
self.NodeList.SetCurrentSelected(0) |
|
494 |
||
495 |
self.RefreshNetworkNodes() |
|
496 |
self.RefreshBufferState() |
|
497 |
self.RefreshTitle() |
|
498 |
self.RefreshProfileMenu() |
|
499 |
self.RefreshMainMenu() |
|
500 |
else: |
|
580 | 501 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 502 |
message.ShowModal() |
503 |
message.Destroy() |
|
504 |
dialog.Destroy() |
|
505 |
event.Skip() |
|
506 |
||
507 |
def OnSaveProjectMenu(self, event): |
|
271 | 508 |
if not self.ModeSolo and getattr(self, "_onsave", None) != None: |
509 |
self._onsave() |
|
510 |
else: |
|
511 |
result = self.NodeList.SaveProject() |
|
512 |
if result: |
|
580 | 513 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
271 | 514 |
message.ShowModal() |
515 |
message.Destroy() |
|
205 | 516 |
event.Skip() |
517 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
518 |
def OnCloseProjectMenu(self, event): |
238 | 519 |
if self.NodeList: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
520 |
if self.NodeList.HasChanged(): |
580 | 521 |
dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), _("Close Project"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
522 |
answer = dialog.ShowModal() |
238 | 523 |
dialog.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
524 |
if answer == wx.ID_YES: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
525 |
result = self.NodeList.SaveProject() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
526 |
if result: |
580 | 527 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
528 |
message.ShowModal() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
529 |
message.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
530 |
elif answer == wx.ID_NO: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
531 |
self.NodeList.ForceChanged(False) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
532 |
if not self.NodeList.HasChanged(): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
533 |
self.Manager = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
534 |
self.NodeList = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
535 |
self.RefreshNetworkNodes() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
536 |
self.RefreshTitle() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
537 |
self.RefreshMainMenu() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
538 |
event.Skip() |
238 | 539 |
|
205 | 540 |
#------------------------------------------------------------------------------- |
541 |
# Slave Nodes Management |
|
542 |
#------------------------------------------------------------------------------- |
|
543 |
||
544 |
def OnAddSlaveMenu(self, event): |
|
545 |
dialog = AddSlaveDialog(self) |
|
546 |
dialog.SetNodeList(self.NodeList) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
547 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 548 |
values = dialog.GetValues() |
549 |
result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"]) |
|
550 |
if not result: |
|
299 | 551 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) |
205 | 552 |
new_editingpanel.SetIndex(values["slaveNodeID"]) |
553 |
idx = self.NodeList.GetOrderNumber(values["slaveNodeID"]) |
|
554 |
self.NetworkNodes.InsertPage(idx, new_editingpanel, "") |
|
555 |
self.NodeList.SetCurrentSelected(idx) |
|
556 |
self.NetworkNodes.SetSelection(idx) |
|
557 |
self.RefreshBufferState() |
|
558 |
else: |
|
580 | 559 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 560 |
message.ShowModal() |
561 |
message.Destroy() |
|
562 |
dialog.Destroy() |
|
563 |
event.Skip() |
|
564 |
||
565 |
def OnRemoveSlaveMenu(self, event): |
|
566 |
slavenames = self.NodeList.GetSlaveNames() |
|
567 |
slaveids = self.NodeList.GetSlaveIDs() |
|
580 | 568 |
dialog = wx.SingleChoiceDialog(self, _("Choose a slave to remove"), _("Remove slave"), slavenames) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
569 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 570 |
choice = dialog.GetSelection() |
571 |
result = self.NodeList.RemoveSlaveNode(slaveids[choice]) |
|
572 |
if not result: |
|
573 |
slaveids.pop(choice) |
|
574 |
current = self.NetworkNodes.GetSelection() |
|
575 |
self.NetworkNodes.DeletePage(choice + 1) |
|
576 |
if self.NetworkNodes.GetPageCount() > 0: |
|
577 |
new_selection = min(current, self.NetworkNodes.GetPageCount() - 1) |
|
578 |
self.NetworkNodes.SetSelection(new_selection) |
|
579 |
if new_selection > 0: |
|
580 |
self.NodeList.SetCurrentSelected(slaveids[new_selection - 1]) |
|
581 |
self.RefreshBufferState() |
|
582 |
else: |
|
580 | 583 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 584 |
message.ShowModal() |
585 |
message.Destroy() |
|
586 |
event.Skip() |
|
587 |
||
588 |
#------------------------------------------------------------------------------- |
|
589 |
# Refresh Functions |
|
590 |
#------------------------------------------------------------------------------- |
|
591 |
||
592 |
def RefreshTitle(self): |
|
593 |
if self.NodeList != None: |
|
580 | 594 |
self.SetTitle(_("Networkedit - %s")%self.NodeList.GetNetworkName()) |
205 | 595 |
else: |
580 | 596 |
self.SetTitle(_("Networkedit")) |
205 | 597 |
|
598 |
def OnRefreshMenu(self, event): |
|
599 |
self.RefreshCurrentIndexList() |
|
600 |
event.Skip() |
|
601 |
||
602 |
def RefreshCurrentIndexList(self): |
|
603 |
selected = self.NetworkNodes.GetSelection() |
|
604 |
if selected == 0: |
|
605 |
window = self.NetworkNodes.GetPage(selected) |
|
606 |
window.RefreshIndexList() |
|
607 |
else: |
|
608 |
pass |
|
609 |
||
610 |
def RefreshNetworkNodes(self): |
|
611 |
if self.NetworkNodes.GetPageCount() > 0: |
|
612 |
self.NetworkNodes.DeleteAllPages() |
|
613 |
if self.NodeList: |
|
299 | 614 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager) |
205 | 615 |
new_editingpanel.SetIndex(0) |
616 |
self.NetworkNodes.AddPage(new_editingpanel, "") |
|
617 |
for idx in self.NodeList.GetSlaveIDs(): |
|
299 | 618 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) |
205 | 619 |
new_editingpanel.SetIndex(idx) |
620 |
self.NetworkNodes.AddPage(new_editingpanel, "") |
|
621 |
||
622 |
def RefreshStatusBar(self): |
|
491 | 623 |
selected = self.NetworkNodes.GetSelection() |
624 |
if self.HelpBar and selected >= 0: |
|
625 |
window = self.NetworkNodes.GetPage(selected) |
|
626 |
selection = window.GetSelection() |
|
627 |
if selection: |
|
628 |
index, subIndex = selection |
|
629 |
if self.NodeList.IsCurrentEntry(index): |
|
580 | 630 |
self.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0) |
631 |
self.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1) |
|
491 | 632 |
entryinfos = self.NodeList.GetEntryInfos(index) |
633 |
name = entryinfos["name"] |
|
580 | 634 |
category = _("Optional") |
491 | 635 |
if entryinfos["need"]: |
580 | 636 |
category = _("Mandatory") |
491 | 637 |
struct = "VAR" |
638 |
number = "" |
|
639 |
if entryinfos["struct"] & OD_IdenticalIndexes: |
|
580 | 640 |
number = _(" possibly defined %d times")%entryinfos["nbmax"] |
491 | 641 |
if entryinfos["struct"] & OD_IdenticalSubindexes: |
642 |
struct = "REC" |
|
643 |
elif entryinfos["struct"] & OD_MultipleSubindexes: |
|
644 |
struct = "ARRAY" |
|
580 | 645 |
text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number) |
491 | 646 |
self.HelpBar.SetStatusText(text, 2) |
205 | 647 |
else: |
648 |
for i in xrange(3): |
|
649 |
self.HelpBar.SetStatusText("", i) |
|
491 | 650 |
else: |
651 |
for i in xrange(3): |
|
652 |
self.HelpBar.SetStatusText("", i) |
|
205 | 653 |
|
654 |
def RefreshMainMenu(self): |
|
491 | 655 |
self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False) |
656 |
if self.NodeList == None: |
|
657 |
if self.ModeSolo: |
|
658 |
self.MenuBar.EnableTop(1, False) |
|
659 |
self.MenuBar.EnableTop(2, False) |
|
660 |
self.MenuBar.EnableTop(3, False) |
|
661 |
if self.FileMenu: |
|
662 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
663 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
664 |
else: |
|
665 |
self.MenuBar.EnableTop(0, False) |
|
666 |
self.MenuBar.EnableTop(1, False) |
|
667 |
self.MenuBar.EnableTop(2, False) |
|
668 |
else: |
|
669 |
if self.ModeSolo: |
|
670 |
self.MenuBar.EnableTop(1, True) |
|
671 |
if self.FileMenu: |
|
672 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
673 |
self.FileMenu.Enable(wx.ID_SAVE, True) |
|
674 |
if self.NetworkNodes.GetSelection() == 0: |
|
675 |
self.MenuBar.EnableTop(2, True) |
|
676 |
self.MenuBar.EnableTop(3, True) |
|
677 |
else: |
|
678 |
self.MenuBar.EnableTop(2, False) |
|
679 |
self.MenuBar.EnableTop(3, False) |
|
680 |
else: |
|
681 |
self.MenuBar.EnableTop(0, True) |
|
682 |
if self.NetworkNodes.GetSelection() == 0: |
|
683 |
self.MenuBar.EnableTop(1, True) |
|
684 |
self.MenuBar.EnableTop(2, True) |
|
685 |
else: |
|
686 |
self.MenuBar.EnableTop(1, False) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
687 |
self.MenuBar.EnableTop(2, False) |
205 | 688 |
|
689 |
def RefreshProfileMenu(self): |
|
491 | 690 |
profile = self.Manager.GetCurrentProfileName() |
691 |
edititem = self.EditMenu.FindItemById(ID_NETWORKEDITEDITMENUOTHERPROFILE) |
|
692 |
if edititem: |
|
693 |
length = self.AddMenu.GetMenuItemCount() |
|
694 |
for i in xrange(length-6): |
|
695 |
additem = self.AddMenu.FindItemByPosition(6) |
|
696 |
self.AddMenu.Delete(additem.GetId()) |
|
697 |
if profile not in ("None", "DS-301"): |
|
580 | 698 |
edititem.SetText(_("%s Profile")%profile) |
491 | 699 |
edititem.Enable(True) |
700 |
self.AddMenu.AppendSeparator() |
|
701 |
for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
|
702 |
new_id = wx.NewId() |
|
703 |
self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
|
704 |
self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) |
|
705 |
else: |
|
580 | 706 |
edititem.SetText(_("Other Profile")) |
491 | 707 |
edititem.Enable(False) |
205 | 708 |
|
273 | 709 |
def GetProfileCallBack(self, text): |
710 |
def ProfileCallBack(event): |
|
711 |
self.Manager.AddSpecificEntryToCurrent(text) |
|
712 |
self.RefreshBufferState() |
|
713 |
self.RefreshCurrentIndexList() |
|
714 |
event.Skip() |
|
715 |
return ProfileCallBack |
|
716 |
||
205 | 717 |
#------------------------------------------------------------------------------- |
718 |
# Buffer Functions |
|
719 |
#------------------------------------------------------------------------------- |
|
720 |
||
721 |
def RefreshBufferState(self): |
|
491 | 722 |
if self.NodeList is not None: |
205 | 723 |
nodeID = self.Manager.GetCurrentNodeID() |
724 |
if nodeID != None: |
|
725 |
nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName()) |
|
726 |
else: |
|
727 |
nodename = self.Manager.GetCurrentNodeName() |
|
728 |
self.NetworkNodes.SetPageText(0, nodename) |
|
729 |
for idx, name in enumerate(self.NodeList.GetSlaveNames()): |
|
730 |
self.NetworkNodes.SetPageText(idx + 1, name) |
|
731 |
self.RefreshTitle() |
|
732 |
||
733 |
def OnUndoMenu(self, event): |
|
734 |
self.Manager.LoadCurrentPrevious() |
|
735 |
self.RefreshCurrentIndexList() |
|
736 |
self.RefreshBufferState() |
|
737 |
event.Skip() |
|
738 |
||
739 |
def OnRedoMenu(self, event): |
|
740 |
self.Manager.LoadCurrentNext() |
|
741 |
self.RefreshCurrentIndexList() |
|
742 |
self.RefreshBufferState() |
|
743 |
event.Skip() |
|
744 |
||
745 |
#------------------------------------------------------------------------------- |
|
746 |
# Help Method |
|
747 |
#------------------------------------------------------------------------------- |
|
748 |
||
749 |
def OnHelpDS301Menu(self, event): |
|
750 |
find_index = False |
|
751 |
selected = self.NetworkNodes.GetSelection() |
|
752 |
if selected >= 0: |
|
753 |
window = self.NetworkNodes.GetPage(selected) |
|
754 |
result = window.GetSelection() |
|
755 |
if result: |
|
756 |
find_index = True |
|
757 |
index, subIndex = result |
|
758 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
|
512 | 759 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 760 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 761 |
message.ShowModal() |
762 |
message.Destroy() |
|
763 |
if not find_index: |
|
764 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
|
512 | 765 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 766 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 767 |
message.ShowModal() |
768 |
message.Destroy() |
|
769 |
event.Skip() |
|
770 |
||
771 |
def OnHelpCANFestivalMenu(self, event): |
|
772 |
#self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) |
|
386
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
773 |
if wx.Platform == '__WXMSW__': |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
774 |
readerpath = get_acroversion() |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
775 |
readerexepath = os.path.join(readerpath,"AcroRd32.exe") |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
776 |
if(os.path.isfile(readerexepath)): |
408
f85552acc2bf
fixed bug to open pdf with acrobat reader on Win32 in objdictedit and networkedit
greg
parents:
386
diff
changeset
|
777 |
os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%os.path.join(ScriptDirectory, "doc","manual_en.pdf")) |
386
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
778 |
else: |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
779 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
205 | 780 |
event.Skip() |
781 |
||
782 |
def OnAboutMenu(self, event): |
|
580 | 783 |
self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
205 | 784 |
event.Skip() |
785 |
||
786 |
def OpenHtmlFrame(self, title, file, size): |
|
787 |
if title not in self.HtmlFrameOpened: |
|
788 |
self.HtmlFrameOpened.append(title) |
|
789 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
790 |
window.SetTitle(title) |
|
791 |
window.SetHtmlPage(file) |
|
792 |
window.SetClientSize(size) |
|
793 |
window.Show() |
|
794 |
||
795 |
#------------------------------------------------------------------------------- |
|
796 |
# Editing Profiles functions |
|
797 |
#------------------------------------------------------------------------------- |
|
798 |
||
799 |
def OnCommunicationMenu(self, event): |
|
800 |
dictionary,current = self.Manager.GetCurrentCommunicationLists() |
|
580 | 801 |
self.EditProfile(_("Edit DS-301 Profile"), dictionary, current) |
205 | 802 |
event.Skip() |
803 |
||
804 |
def OnOtherCommunicationMenu(self, event): |
|
805 |
dictionary,current = self.Manager.GetCurrentDS302Lists() |
|
580 | 806 |
self.EditProfile(_("Edit DS-302 Profile"), dictionary, current) |
205 | 807 |
event.Skip() |
808 |
||
809 |
def OnEditProfileMenu(self, event): |
|
580 | 810 |
title = _("Edit %s Profile")%self.Manager.GetCurrentProfileName() |
205 | 811 |
dictionary,current = self.Manager.GetCurrentProfileLists() |
812 |
self.EditProfile(title, dictionary, current) |
|
813 |
event.Skip() |
|
814 |
||
815 |
def EditProfile(self, title, dictionary, current): |
|
816 |
dialog = CommunicationDialog(self) |
|
817 |
dialog.SetTitle(title) |
|
818 |
dialog.SetIndexDictionary(dictionary) |
|
819 |
dialog.SetCurrentList(current) |
|
820 |
dialog.RefreshLists() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
821 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 822 |
new_profile = dialog.GetCurrentList() |
823 |
addinglist = [] |
|
824 |
removinglist = [] |
|
825 |
for index in new_profile: |
|
826 |
if index not in current: |
|
827 |
addinglist.append(index) |
|
828 |
for index in current: |
|
829 |
if index not in new_profile: |
|
830 |
removinglist.append(index) |
|
831 |
self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) |
|
832 |
self.Manager.BufferCurrentNode() |
|
833 |
self.RefreshBufferState() |
|
834 |
self.RefreshCurrentIndexList() |
|
835 |
dialog.Destroy() |
|
836 |
||
837 |
#------------------------------------------------------------------------------- |
|
838 |
# Edit Node informations function |
|
839 |
#------------------------------------------------------------------------------- |
|
840 |
||
841 |
def OnNodeInfosMenu(self, event): |
|
842 |
dialog = NodeInfosDialog(self) |
|
843 |
name, id, type, description = self.Manager.GetCurrentNodeInfos() |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
844 |
defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
845 |
dialog.SetValues(name, id, type, description, defaultstringsize) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
846 |
if dialog.ShowModal() == wx.ID_OK: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
847 |
name, id, type, description, defaultstringsize = dialog.GetValues() |
205 | 848 |
self.Manager.SetCurrentNodeInfos(name, id, type, description) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
849 |
self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize) |
205 | 850 |
self.RefreshBufferState() |
851 |
self.RefreshProfileMenu() |
|
243 | 852 |
selected = self.NetworkNodes.GetSelection() |
205 | 853 |
if selected >= 0: |
243 | 854 |
window = self.NetworkNodes.GetPage(selected) |
205 | 855 |
window.RefreshTable() |
856 |
event.Skip() |
|
857 |
||
858 |
||
859 |
#------------------------------------------------------------------------------- |
|
860 |
# Add User Types and Variables |
|
861 |
#------------------------------------------------------------------------------- |
|
862 |
||
863 |
def AddMapVariable(self): |
|
864 |
index = self.Manager.GetCurrentNextMapIndex() |
|
865 |
if index: |
|
866 |
dialog = MapVariableDialog(self) |
|
867 |
dialog.SetIndex(index) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
868 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 869 |
index, name, struct, number = dialog.GetValues() |
870 |
result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) |
|
512 | 871 |
if not isinstance(result, (StringType, UnicodeType)): |
205 | 872 |
self.RefreshBufferState() |
873 |
self.RefreshCurrentIndexList() |
|
874 |
else: |
|
580 | 875 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 876 |
message.ShowModal() |
877 |
message.Destroy() |
|
878 |
dialog.Destroy() |
|
879 |
else: |
|
580 | 880 |
message = wx.MessageDialog(self, result, _("No map variable index left!"), wx.OK|wx.ICON_ERROR) |
205 | 881 |
message.ShowModal() |
882 |
message.Destroy() |
|
883 |
||
884 |
def AddUserType(self): |
|
885 |
dialog = UserTypeDialog(self) |
|
886 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
887 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 888 |
type, min, max, length = dialog.GetValues() |
889 |
result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
|
890 |
if not IsOfType(result, StringType): |
|
891 |
self.RefreshBufferState() |
|
892 |
self.RefreshCurrentIndexList() |
|
893 |
else: |
|
580 | 894 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 895 |
message.ShowModal() |
896 |
message.Destroy() |
|
897 |
dialog.Destroy() |
|
898 |
||
327 | 899 |
def OpenMasterDCFDialog(self, node_id): |
900 |
self.NetworkNodes.SetSelection(0) |
|
336 | 901 |
self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id) |
327 | 902 |
|
205 | 903 |
#------------------------------------------------------------------------------- |
904 |
# Exception Handler |
|
905 |
#------------------------------------------------------------------------------- |
|
906 |
||
907 |
Max_Traceback_List_Size = 20 |
|
908 |
||
909 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
910 |
trcbck_lst = [] |
|
911 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
580 | 912 |
trcbck = " " + str(i+1) + _(". ") |
205 | 913 |
if line[0].find(os.getcwd()) == -1: |
580 | 914 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
205 | 915 |
else: |
580 | 916 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
917 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
205 | 918 |
trcbck_lst.append(trcbck) |
919 |
||
920 |
# Allow clicking.... |
|
921 |
cap = wx.Window_GetCapture() |
|
922 |
if cap: |
|
923 |
cap.ReleaseMouse() |
|
924 |
||
925 |
dlg = wx.SingleChoiceDialog(None, |
|
580 | 926 |
_(""" |
205 | 927 |
An error happens. |
928 |
||
929 |
Click on OK for saving an error report. |
|
930 |
||
931 |
Please contact LOLITech at: |
|
548 | 932 |
+33 (0)3 29 57 60 42 |
205 | 933 |
bugs_networkedit@lolitech.fr |
934 |
||
935 |
||
936 |
Error: |
|
580 | 937 |
""") + |
938 |
str(e_type) + _(" : ") + str(e_value), |
|
939 |
_("Error"), |
|
205 | 940 |
trcbck_lst) |
941 |
try: |
|
942 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
943 |
finally: |
|
944 |
dlg.Destroy() |
|
945 |
||
946 |
return res |
|
947 |
||
948 |
def Display_Error_Dialog(e_value): |
|
580 | 949 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 950 |
message.ShowModal() |
951 |
message.Destroy() |
|
952 |
||
953 |
def get_last_traceback(tb): |
|
954 |
while tb.tb_next: |
|
955 |
tb = tb.tb_next |
|
956 |
return tb |
|
957 |
||
958 |
||
959 |
def format_namespace(d, indent=' '): |
|
960 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
961 |
||
962 |
||
963 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
964 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
965 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
205 | 966 |
|
967 |
def handle_exception(e_type, e_value, e_traceback): |
|
968 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
969 |
last_tb = get_last_traceback(e_traceback) |
|
970 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
971 |
if str(e_value).startswith("!!!"): |
|
972 |
Display_Error_Dialog(e_value) |
|
973 |
elif ex not in ignored_exceptions: |
|
974 |
ignored_exceptions.append(ex) |
|
975 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
976 |
if result: |
|
977 |
info = { |
|
978 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
979 |
'app-version' : app_version, |
|
980 |
'wx-version' : wx.VERSION_STRING, |
|
981 |
'wx-platform' : wx.Platform, |
|
982 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
983 |
'platform' : platform.platform(), |
|
984 |
'e-type' : e_type, |
|
985 |
'e-value' : e_value, |
|
986 |
'date' : time.ctime(), |
|
987 |
'cwd' : os.getcwd(), |
|
988 |
} |
|
989 |
if e_traceback: |
|
990 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
991 |
last_tb = get_last_traceback(e_traceback) |
|
992 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
993 |
info['locals'] = format_namespace(exception_locals) |
|
994 |
if 'self' in exception_locals: |
|
995 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
996 |
||
997 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
998 |
lst = info.keys() |
|
999 |
lst.sort() |
|
1000 |
for a in lst: |
|
1001 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
1002 |
||
1003 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
1004 |
sys.excepthook = handle_exception |
|
1005 |
||
1006 |
if __name__ == '__main__': |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
1007 |
wx.InitAllImageHandlers() |
205 | 1008 |
|
1009 |
# Install a exception handle for bug reports |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
1010 |
AddExceptHook(os.getcwd(),__version__) |
205 | 1011 |
|
276 | 1012 |
frame = networkedit(None, projectOpen=projectOpen) |
205 | 1013 |
|
1014 |
frame.Show() |
|
1015 |
app.MainLoop() |