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