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