author | Edouard Tisserant |
Wed, 06 Mar 2013 11:39:35 +0900 | |
changeset 772 | 7cb6e71d6331 |
parent 748 | 18ed0f3b030a |
child 778 | 9edaa9d21cf9 |
permissions | -rw-r--r-- |
205 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU Lesser General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#Lesser General Public License for more details. |
|
19 |
# |
|
20 |
#You should have received a copy of the GNU Lesser General Public |
|
21 |
#License along with this library; if not, write to the Free Software |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
24 |
import wx |
|
25 |
import wx.grid |
|
26 |
||
27 |
from types import * |
|
28 |
import os, re, platform, sys, time, traceback, getopt |
|
29 |
||
580 | 30 |
__version__ = "$Revision: 1.27 $" |
31 |
||
32 |
if __name__ == '__main__': |
|
33 |
def usage(): |
|
34 |
print _("\nUsage of networkedit.py :") |
|
35 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
|
36 |
||
37 |
try: |
|
38 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
39 |
except getopt.GetoptError: |
|
40 |
# print help information and exit: |
|
41 |
usage() |
|
42 |
sys.exit(2) |
|
43 |
||
44 |
for o, a in opts: |
|
45 |
if o in ("-h", "--help"): |
|
46 |
usage() |
|
47 |
sys.exit() |
|
48 |
||
49 |
if len(args) == 0: |
|
50 |
projectOpen = None |
|
51 |
elif len(args) == 1: |
|
52 |
projectOpen = args[0] |
|
53 |
else: |
|
54 |
usage() |
|
55 |
sys.exit(2) |
|
56 |
||
57 |
app = wx.PySimpleApp() |
|
58 |
||
59 |
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
|
60 |
||
61 |
# Import module for internationalization |
|
62 |
import gettext |
|
63 |
import __builtin__ |
|
64 |
||
65 |
# Get folder containing translation files |
|
66 |
localedir = os.path.join(ScriptDirectory,"locale") |
|
67 |
# Get the default language |
|
68 |
langid = wx.LANGUAGE_DEFAULT |
|
69 |
# Define translation domain (name of translation files) |
|
70 |
domain = "objdictgen" |
|
71 |
||
72 |
# Define locale for wx |
|
73 |
loc = __builtin__.__dict__.get('loc', None) |
|
74 |
if loc is None: |
|
75 |
loc = wx.Locale(langid) |
|
76 |
__builtin__.__dict__['loc'] = loc |
|
77 |
# Define location for searching translation files |
|
78 |
loc.AddCatalogLookupPathPrefix(localedir) |
|
79 |
# Define locale domain |
|
80 |
loc.AddCatalog(domain) |
|
81 |
||
82 |
if __name__ == '__main__': |
|
83 |
__builtin__.__dict__['_'] = wx.GetTranslation |
|
205 | 84 |
|
85 |
from nodelist import * |
|
86 |
from nodemanager import * |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
87 |
from nodeeditor import NodeEditorTemplate |
205 | 88 |
from subindextable import * |
89 |
from commondialogs import * |
|
90 |
from doc_index.DS301_index import * |
|
91 |
||
92 |
try: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
93 |
import wx.html |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
94 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
95 |
EVT_HTML_URL_CLICK = wx.NewId() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
96 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
97 |
class HtmlWindowUrlClick(wx.PyEvent): |
205 | 98 |
def __init__(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
99 |
wx.PyEvent.__init__(self) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
100 |
self.SetEventType(EVT_HTML_URL_CLICK) |
205 | 101 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
102 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
103 |
class UrlClickHtmlWindow(wx.html.HtmlWindow): |
205 | 104 |
""" HTML window that generates and OnLinkClicked event. |
105 |
||
106 |
Use this to avoid having to override HTMLWindow |
|
107 |
""" |
|
108 |
def OnLinkClicked(self, linkinfo): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
109 |
wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
110 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
111 |
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
|
112 |
if event == HtmlWindowUrlClick: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
113 |
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
|
114 |
else: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
115 |
wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
205 | 116 |
|
117 |
#------------------------------------------------------------------------------- |
|
118 |
# Html Frame |
|
119 |
#------------------------------------------------------------------------------- |
|
120 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
121 |
[ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
205 | 122 |
|
123 |
class HtmlFrame(wx.Frame): |
|
124 |
def _init_ctrls(self, prnt): |
|
125 |
# generated method, don't edit |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
126 |
wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
205 | 127 |
parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
128 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
|
273 | 129 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
205 | 130 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
131 |
self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
205 | 132 |
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
|
133 |
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
|
134 |
self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
205 | 135 |
|
136 |
def __init__(self, parent, opened): |
|
137 |
self._init_ctrls(parent) |
|
138 |
self.HtmlFrameOpened = opened |
|
139 |
||
140 |
def SetHtmlCode(self, htmlcode): |
|
141 |
self.HtmlContent.SetPage(htmlcode) |
|
142 |
||
143 |
def SetHtmlPage(self, htmlpage): |
|
144 |
self.HtmlContent.LoadPage(htmlpage) |
|
145 |
||
146 |
def OnCloseFrame(self, event): |
|
147 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
|
148 |
event.Skip() |
|
149 |
||
150 |
def OnLinkClick(self, event): |
|
151 |
url = event.linkinfo[0] |
|
152 |
try: |
|
153 |
import webbrowser |
|
154 |
except ImportError: |
|
580 | 155 |
wx.MessageBox(_('Please point your browser at: %s') % url) |
205 | 156 |
else: |
157 |
webbrowser.open(url) |
|
158 |
||
159 |
Html_Window = True |
|
160 |
except: |
|
161 |
Html_Window = False |
|
162 |
||
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
163 |
[ID_NETWORKEDITORNETWORKNODES, |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
164 |
] = [wx.NewId() for _init_ctrls in range(1)] |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
165 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
166 |
class NetworkEditorTemplate(NodeEditorTemplate): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
167 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
168 |
def _init_ctrls(self, prnt): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
169 |
self.NetworkNodes = wx.Notebook(id=ID_NETWORKEDITNETWORKNODES, |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
170 |
name='NetworkNodes', parent=prnt, pos=wx.Point(0, 0), |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
171 |
size=wx.Size(0, 0), style=wx.NB_LEFT) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
172 |
self.NetworkNodes.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
173 |
self.OnNodeSelectedChanged, id=ID_NETWORKEDITNETWORKNODES) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
174 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
175 |
def __init__(self, manager, frame, mode_solo): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
176 |
self.NodeList = manager |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
177 |
NodeEditorTemplate.__init__(self, self.NodeList.GetManager(), frame, mode_solo) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
178 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
179 |
def GetCurrentNodeId(self): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
180 |
selected = self.NetworkNodes.GetSelection() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
181 |
# At init selected = -1 |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
182 |
if selected > 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
183 |
window = self.NetworkNodes.GetPage(selected) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
184 |
return window.GetIndex() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
185 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
186 |
return 0 |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
187 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
188 |
def RefreshCurrentIndexList(self): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
189 |
selected = self.NetworkNodes.GetSelection() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
190 |
if selected == 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
191 |
window = self.NetworkNodes.GetPage(selected) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
192 |
window.RefreshIndexList() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
193 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
194 |
pass |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
195 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
196 |
def RefreshNetworkNodes(self): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
197 |
if self.NetworkNodes.GetPageCount() > 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
198 |
self.NetworkNodes.DeleteAllPages() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
199 |
if self.NodeList: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
200 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.Manager) |
748
18ed0f3b030a
Fixing networkedit to deal with non-null master nodeid
Laurent Bessard
parents:
744
diff
changeset
|
201 |
new_editingpanel.SetIndex(self.Manager.GetCurrentNodeID()) |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
202 |
self.NetworkNodes.AddPage(new_editingpanel, "") |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
203 |
for idx in self.NodeList.GetSlaveIDs(): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
204 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
205 |
new_editingpanel.SetIndex(idx) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
206 |
self.NetworkNodes.AddPage(new_editingpanel, "") |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
207 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
208 |
def OnNodeSelectedChanged(self, event): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
209 |
if not self.Closing: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
210 |
selected = event.GetSelection() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
211 |
# At init selected = -1 |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
212 |
if selected >= 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
213 |
window = self.NetworkNodes.GetPage(selected) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
214 |
self.NodeList.SetCurrentSelected(window.GetIndex()) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
215 |
wx.CallAfter(self.RefreshMainMenu) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
216 |
wx.CallAfter(self.RefreshStatusBar) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
217 |
event.Skip() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
218 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
219 |
#------------------------------------------------------------------------------- |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
220 |
# Buffer Functions |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
221 |
#------------------------------------------------------------------------------- |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
222 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
223 |
def RefreshBufferState(self): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
224 |
if self.NodeList is not None: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
225 |
nodeID = self.Manager.GetCurrentNodeID() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
226 |
if nodeID != None: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
227 |
nodename = "0x%2.2X %s"%(nodeID, self.Manager.GetCurrentNodeName()) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
228 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
229 |
nodename = self.Manager.GetCurrentNodeName() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
230 |
self.NetworkNodes.SetPageText(0, nodename) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
231 |
for idx, name in enumerate(self.NodeList.GetSlaveNames()): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
232 |
self.NetworkNodes.SetPageText(idx + 1, name) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
233 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
234 |
#------------------------------------------------------------------------------- |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
235 |
# Slave Nodes Management |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
236 |
#------------------------------------------------------------------------------- |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
237 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
238 |
def OnAddSlaveMenu(self, event): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
239 |
dialog = AddSlaveDialog(self.Frame) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
240 |
dialog.SetNodeList(self.NodeList) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
241 |
if dialog.ShowModal() == wx.ID_OK: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
242 |
values = dialog.GetValues() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
243 |
result = self.NodeList.AddSlaveNode(values["slaveName"], values["slaveNodeID"], values["edsFile"]) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
244 |
if not result: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
245 |
new_editingpanel = EditingPanel(self.NetworkNodes, self, self.NodeList, False) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
246 |
new_editingpanel.SetIndex(values["slaveNodeID"]) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
247 |
idx = self.NodeList.GetOrderNumber(values["slaveNodeID"]) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
248 |
self.NetworkNodes.InsertPage(idx, new_editingpanel, "") |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
249 |
self.NodeList.SetCurrentSelected(idx) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
250 |
self.NetworkNodes.SetSelection(idx) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
251 |
self.RefreshBufferState() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
252 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
253 |
self.ShowErrorMessage(result) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
254 |
dialog.Destroy() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
255 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
256 |
def OnRemoveSlaveMenu(self, event): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
257 |
slavenames = self.NodeList.GetSlaveNames() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
258 |
slaveids = self.NodeList.GetSlaveIDs() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
259 |
dialog = wx.SingleChoiceDialog(self.Frame, _("Choose a slave to remove"), _("Remove slave"), slavenames) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
260 |
if dialog.ShowModal() == wx.ID_OK: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
261 |
choice = dialog.GetSelection() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
262 |
result = self.NodeList.RemoveSlaveNode(slaveids[choice]) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
263 |
if not result: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
264 |
slaveids.pop(choice) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
265 |
current = self.NetworkNodes.GetSelection() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
266 |
self.NetworkNodes.DeletePage(choice + 1) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
267 |
if self.NetworkNodes.GetPageCount() > 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
268 |
new_selection = min(current, self.NetworkNodes.GetPageCount() - 1) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
269 |
self.NetworkNodes.SetSelection(new_selection) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
270 |
if new_selection > 0: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
271 |
self.NodeList.SetCurrentSelected(slaveids[new_selection - 1]) |
744
bc1bbbb5ef71
Fix bug with 'not saved' state for network when removing a slave
Laurent Bessard
parents:
715
diff
changeset
|
272 |
self.RefreshBufferState() |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
273 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
274 |
self.ShowErrorMessage(result) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
275 |
dialog.Destroy() |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
276 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
277 |
def OpenMasterDCFDialog(self, node_id): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
278 |
self.NetworkNodes.SetSelection(0) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
279 |
self.NetworkNodes.GetPage(0).OpenDCFDialog(node_id) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
280 |
|
205 | 281 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
282 |
[ID_NETWORKEDIT, ID_NETWORKEDITNETWORKNODES, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
283 |
ID_NETWORKEDITHELPBAR, |
205 | 284 |
] = [wx.NewId() for _init_ctrls in range(3)] |
285 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
286 |
[ID_NETWORKEDITNETWORKMENUBUILDMASTER, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
287 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(1)] |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
288 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
289 |
[ID_NETWORKEDITEDITMENUNODEINFOS, ID_NETWORKEDITEDITMENUDS301PROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
290 |
ID_NETWORKEDITEDITMENUDS302PROFILE, ID_NETWORKEDITEDITMENUOTHERPROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
291 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(4)] |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
292 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
293 |
[ID_NETWORKEDITADDMENUSDOSERVER, ID_NETWORKEDITADDMENUSDOCLIENT, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
294 |
ID_NETWORKEDITADDMENUPDOTRANSMIT, ID_NETWORKEDITADDMENUPDORECEIVE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
295 |
ID_NETWORKEDITADDMENUMAPVARIABLE, ID_NETWORKEDITADDMENUUSERTYPE, |
205 | 296 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
297 |
||
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
298 |
class networkedit(wx.Frame, NetworkEditorTemplate): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
299 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
300 |
EDITMENU_ID = ID_NETWORKEDITEDITMENUOTHERPROFILE |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
301 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
302 |
def _init_coll_MenuBar_Menus(self, parent): |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
303 |
if self.ModeSolo: |
580 | 304 |
parent.Append(menu=self.FileMenu, title=_('File')) |
305 |
parent.Append(menu=self.NetworkMenu, title=_('Network')) |
|
306 |
parent.Append(menu=self.EditMenu, title=_('Edit')) |
|
307 |
parent.Append(menu=self.AddMenu, title=_('Add')) |
|
308 |
parent.Append(menu=self.HelpMenu, title=_('Help')) |
|
205 | 309 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
310 |
def _init_coll_FileMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
311 |
parent.Append(help='', id=wx.ID_NEW, |
580 | 312 |
kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
313 |
parent.Append(help='', id=wx.ID_OPEN, |
580 | 314 |
kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
315 |
parent.Append(help='', id=wx.ID_CLOSE, |
580 | 316 |
kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
317 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
318 |
parent.Append(help='', id=wx.ID_SAVE, |
580 | 319 |
kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
320 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
321 |
parent.Append(help='', id=wx.ID_EXIT, |
580 | 322 |
kind=wx.ITEM_NORMAL, text=_('Exit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
323 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
324 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
325 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
326 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
327 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
328 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
329 |
def _init_coll_NetworkMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
330 |
parent.Append(help='', id=wx.ID_ADD, |
580 | 331 |
kind=wx.ITEM_NORMAL, text=_('Add Slave Node')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
332 |
parent.Append(help='', id=wx.ID_DELETE, |
580 | 333 |
kind=wx.ITEM_NORMAL, text=_('Remove Slave Node')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
334 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
335 |
parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER, |
580 | 336 |
kind=wx.ITEM_NORMAL, text=_('Build Master Dictionary')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
337 |
self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
338 |
self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
339 |
## self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
340 |
## id=ID_NETWORKEDITNETWORKMENUBUILDMASTER) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
341 |
|
205 | 342 |
def _init_coll_EditMenu_Items(self, parent): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
343 |
parent.Append(help='', id=wx.ID_REFRESH, |
580 | 344 |
kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R')) |
205 | 345 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
346 |
parent.Append(help='', id=wx.ID_UNDO, |
580 | 347 |
kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
348 |
parent.Append(help='', id=wx.ID_REDO, |
580 | 349 |
kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y')) |
205 | 350 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
351 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS, |
580 | 352 |
kind=wx.ITEM_NORMAL, text=_('Node infos')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
353 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE, |
580 | 354 |
kind=wx.ITEM_NORMAL, text=_('DS-301 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
355 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE, |
580 | 356 |
kind=wx.ITEM_NORMAL, text=_('DS-302 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
357 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE, |
580 | 358 |
kind=wx.ITEM_NORMAL, text=_('Other Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
359 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
360 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
361 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
362 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
363 |
id=ID_NETWORKEDITEDITMENUNODEINFOS) |
205 | 364 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
365 |
id=ID_NETWORKEDITEDITMENUDS301PROFILE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
366 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
367 |
id=ID_NETWORKEDITEDITMENUDS302PROFILE) |
205 | 368 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
369 |
id=ID_NETWORKEDITEDITMENUOTHERPROFILE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
370 |
|
205 | 371 |
def _init_coll_AddMenu_Items(self, parent): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
372 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER, |
580 | 373 |
kind=wx.ITEM_NORMAL, text=_('SDO Server')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
374 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT, |
580 | 375 |
kind=wx.ITEM_NORMAL, text=_('SDO Client')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
376 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT, |
580 | 377 |
kind=wx.ITEM_NORMAL, text=_('PDO Transmit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
378 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE, |
580 | 379 |
kind=wx.ITEM_NORMAL, text=_('PDO Receive')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
380 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE, |
580 | 381 |
kind=wx.ITEM_NORMAL, text=_('Map Variable')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
382 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE, |
580 | 383 |
kind=wx.ITEM_NORMAL, text=_('User Type')) |
205 | 384 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
385 |
id=ID_NETWORKEDITADDMENUSDOSERVER) |
205 | 386 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
387 |
id=ID_NETWORKEDITADDMENUSDOCLIENT) |
205 | 388 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
389 |
id=ID_NETWORKEDITADDMENUPDOTRANSMIT) |
205 | 390 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
391 |
id=ID_NETWORKEDITADDMENUPDORECEIVE) |
205 | 392 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
393 |
id=ID_NETWORKEDITADDMENUMAPVARIABLE) |
205 | 394 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
395 |
id=ID_NETWORKEDITADDMENUUSERTYPE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
396 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
397 |
def _init_coll_HelpMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
398 |
parent.Append(help='', id=wx.ID_HELP, |
580 | 399 |
kind=wx.ITEM_NORMAL, text=_('DS-301 Standard\tF1')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
400 |
self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
401 |
parent.Append(help='', id=wx.ID_HELP_CONTEXT, |
580 | 402 |
kind=wx.ITEM_NORMAL, text=_('CAN Festival Docs\tF2')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
403 |
self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
404 |
if Html_Window and self.ModeSolo: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
405 |
parent.Append(help='', id=wx.ID_ABOUT, |
580 | 406 |
kind=wx.ITEM_NORMAL, text=_('About')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
407 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
205 | 408 |
|
409 |
def _init_coll_HelpBar_Fields(self, parent): |
|
410 |
parent.SetFieldsCount(3) |
|
411 |
||
412 |
parent.SetStatusText(number=0, text='') |
|
413 |
parent.SetStatusText(number=1, text='') |
|
414 |
parent.SetStatusText(number=2, text='') |
|
415 |
||
416 |
parent.SetStatusWidths([100, 110, -1]) |
|
417 |
||
418 |
def _init_utils(self): |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
419 |
self.MenuBar = wx.MenuBar() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
420 |
self.MenuBar.SetEvtHandlerEnabled(True) |
205 | 421 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
422 |
if self.ModeSolo: |
205 | 423 |
self.FileMenu = wx.Menu(title='') |
424 |
self.NetworkMenu = wx.Menu(title='') |
|
425 |
self.EditMenu = wx.Menu(title='') |
|
426 |
self.AddMenu = wx.Menu(title='') |
|
427 |
self.HelpMenu = wx.Menu(title='') |
|
428 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
429 |
self._init_coll_MenuBar_Menus(self.MenuBar) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
430 |
if self.ModeSolo: |
205 | 431 |
self._init_coll_FileMenu_Items(self.FileMenu) |
432 |
self._init_coll_NetworkMenu_Items(self.NetworkMenu) |
|
433 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
434 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
435 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
436 |
||
437 |
def _init_ctrls(self, prnt): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
438 |
wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit', |
205 | 439 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
580 | 440 |
style=wx.DEFAULT_FRAME_STYLE, title=_('Networkedit')) |
205 | 441 |
self._init_utils() |
442 |
self.SetClientSize(wx.Size(1000, 700)) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
443 |
self.SetMenuBar(self.MenuBar) |
273 | 444 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
271 | 445 |
if not self.ModeSolo: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
446 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
447 |
accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)]) |
271 | 448 |
self.SetAcceleratorTable(accel) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
449 |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
450 |
NetworkEditorTemplate._init_ctrls(self, self) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
451 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
452 |
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
|
453 |
parent=self, style=wx.ST_SIZEGRIP) |
205 | 454 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
455 |
self.SetStatusBar(self.HelpBar) |
|
456 |
||
276 | 457 |
def __init__(self, parent, nodelist = None, projectOpen = None): |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
458 |
if nodelist is None: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
459 |
NetworkEditorTemplate.__init__(self, NodeList(NodeManager()), self, True) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
460 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
461 |
NetworkEditorTemplate.__init__(self, nodelist, self, False) |
205 | 462 |
self._init_ctrls(parent) |
463 |
self.HtmlFrameOpened = [] |
|
464 |
||
410 | 465 |
icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO) |
409 | 466 |
self.SetIcon(icon) |
410 | 467 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
468 |
if self.ModeSolo: |
205 | 469 |
if projectOpen: |
470 |
result = self.NodeList.LoadProject(projectOpen) |
|
471 |
if not result: |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
472 |
self.NodeList.SetCurrentSelected(0) |
205 | 473 |
self.RefreshNetworkNodes() |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
474 |
self.RefreshProfileMenu() |
205 | 475 |
else: |
476 |
self.NodeList = None |
|
477 |
else: |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
478 |
self.NodeList.SetCurrentSelected(0) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
479 |
self.RefreshNetworkNodes() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
480 |
self.RefreshProfileMenu() |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
481 |
self.NetworkNodes.SetFocus() |
205 | 482 |
|
483 |
self.RefreshBufferState() |
|
484 |
self.RefreshTitle() |
|
485 |
self.RefreshMainMenu() |
|
486 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
487 |
def OnCloseFrame(self, event): |
491 | 488 |
self.Closing = True |
271 | 489 |
if not self.ModeSolo and getattr(self, "_onclose", None) != None: |
490 |
self._onclose() |
|
491 |
event.Skip() |
|
492 |
||
493 |
def OnChar(self, event): |
|
494 |
if event.ControlDown() and event.GetKeyCode() == 83 and getattr(self, "_onsave", None) != None: |
|
495 |
self._onsave() |
|
612 | 496 |
#event.Skip() |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
497 |
|
205 | 498 |
def OnQuitMenu(self, event): |
499 |
self.Close() |
|
500 |
||
501 |
#------------------------------------------------------------------------------- |
|
502 |
# Load and Save Funtions |
|
503 |
#------------------------------------------------------------------------------- |
|
504 |
||
505 |
def OnNewProjectMenu(self, event): |
|
506 |
if self.NodeList: |
|
507 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
508 |
else: |
|
509 |
defaultpath = os.getcwd() |
|
580 | 510 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, wx.DD_NEW_DIR_BUTTON) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
511 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 512 |
projectpath = dialog.GetPath() |
206 | 513 |
if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: |
258 | 514 |
manager = NodeManager() |
205 | 515 |
nodelist = NodeList(manager) |
516 |
result = nodelist.LoadProject(projectpath) |
|
517 |
if not result: |
|
518 |
self.Manager = manager |
|
519 |
self.NodeList = nodelist |
|
520 |
self.NodeList.SetCurrentSelected(0) |
|
521 |
||
522 |
self.RefreshNetworkNodes() |
|
523 |
self.RefreshBufferState() |
|
524 |
self.RefreshTitle() |
|
525 |
self.RefreshProfileMenu() |
|
526 |
self.RefreshMainMenu() |
|
527 |
else: |
|
580 | 528 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 529 |
message.ShowModal() |
530 |
message.Destroy() |
|
608 | 531 |
|
205 | 532 |
def OnOpenProjectMenu(self, event): |
533 |
if self.NodeList: |
|
534 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
535 |
else: |
|
536 |
defaultpath = os.getcwd() |
|
580 | 537 |
dialog = wx.DirDialog(self , _("Choose a project"), defaultpath, 0) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
538 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 539 |
projectpath = dialog.GetPath() |
540 |
if os.path.isdir(projectpath): |
|
258 | 541 |
manager = NodeManager() |
205 | 542 |
nodelist = NodeList(manager) |
543 |
result = nodelist.LoadProject(projectpath) |
|
544 |
if not result: |
|
545 |
self.Manager = manager |
|
546 |
self.NodeList = nodelist |
|
547 |
self.NodeList.SetCurrentSelected(0) |
|
548 |
||
549 |
self.RefreshNetworkNodes() |
|
550 |
self.RefreshBufferState() |
|
551 |
self.RefreshTitle() |
|
552 |
self.RefreshProfileMenu() |
|
553 |
self.RefreshMainMenu() |
|
554 |
else: |
|
580 | 555 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 556 |
message.ShowModal() |
557 |
message.Destroy() |
|
558 |
dialog.Destroy() |
|
608 | 559 |
|
205 | 560 |
def OnSaveProjectMenu(self, event): |
271 | 561 |
if not self.ModeSolo and getattr(self, "_onsave", None) != None: |
562 |
self._onsave() |
|
563 |
else: |
|
564 |
result = self.NodeList.SaveProject() |
|
565 |
if result: |
|
580 | 566 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
271 | 567 |
message.ShowModal() |
568 |
message.Destroy() |
|
608 | 569 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
570 |
def OnCloseProjectMenu(self, event): |
238 | 571 |
if self.NodeList: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
572 |
if self.NodeList.HasChanged(): |
580 | 573 |
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
|
574 |
answer = dialog.ShowModal() |
238 | 575 |
dialog.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
576 |
if answer == wx.ID_YES: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
577 |
result = self.NodeList.SaveProject() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
578 |
if result: |
580 | 579 |
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
|
580 |
message.ShowModal() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
581 |
message.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
582 |
elif answer == wx.ID_NO: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
583 |
self.NodeList.ForceChanged(False) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
584 |
if not self.NodeList.HasChanged(): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
585 |
self.Manager = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
586 |
self.NodeList = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
587 |
self.RefreshNetworkNodes() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
588 |
self.RefreshTitle() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
589 |
self.RefreshMainMenu() |
608 | 590 |
|
591 |
||
205 | 592 |
#------------------------------------------------------------------------------- |
593 |
# Refresh Functions |
|
594 |
#------------------------------------------------------------------------------- |
|
595 |
||
596 |
def RefreshTitle(self): |
|
597 |
if self.NodeList != None: |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
598 |
self.SetTitle(_("Networkedit - %s") % self.NodeList.GetNetworkName()) |
205 | 599 |
else: |
580 | 600 |
self.SetTitle(_("Networkedit")) |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
601 |
|
205 | 602 |
def RefreshStatusBar(self): |
491 | 603 |
selected = self.NetworkNodes.GetSelection() |
604 |
if self.HelpBar and selected >= 0: |
|
605 |
window = self.NetworkNodes.GetPage(selected) |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
606 |
self.SetStatusBarText(window.GetSelection(), self.NodeList) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
607 |
|
205 | 608 |
def RefreshMainMenu(self): |
491 | 609 |
self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False) |
610 |
if self.NodeList == None: |
|
611 |
if self.ModeSolo: |
|
612 |
self.MenuBar.EnableTop(1, False) |
|
613 |
self.MenuBar.EnableTop(2, False) |
|
614 |
self.MenuBar.EnableTop(3, False) |
|
615 |
if self.FileMenu: |
|
616 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
617 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
618 |
else: |
|
619 |
self.MenuBar.EnableTop(0, False) |
|
620 |
self.MenuBar.EnableTop(1, False) |
|
621 |
self.MenuBar.EnableTop(2, False) |
|
622 |
else: |
|
623 |
if self.ModeSolo: |
|
624 |
self.MenuBar.EnableTop(1, True) |
|
625 |
if self.FileMenu: |
|
626 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
627 |
self.FileMenu.Enable(wx.ID_SAVE, True) |
|
628 |
if self.NetworkNodes.GetSelection() == 0: |
|
629 |
self.MenuBar.EnableTop(2, True) |
|
630 |
self.MenuBar.EnableTop(3, True) |
|
631 |
else: |
|
632 |
self.MenuBar.EnableTop(2, False) |
|
633 |
self.MenuBar.EnableTop(3, False) |
|
634 |
else: |
|
635 |
self.MenuBar.EnableTop(0, True) |
|
636 |
if self.NetworkNodes.GetSelection() == 0: |
|
637 |
self.MenuBar.EnableTop(1, True) |
|
638 |
self.MenuBar.EnableTop(2, True) |
|
639 |
else: |
|
640 |
self.MenuBar.EnableTop(1, False) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
641 |
self.MenuBar.EnableTop(2, False) |
205 | 642 |
|
643 |
#------------------------------------------------------------------------------- |
|
644 |
# Buffer Functions |
|
645 |
#------------------------------------------------------------------------------- |
|
646 |
||
647 |
def RefreshBufferState(self): |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
648 |
NetworkEditorTemplate.RefreshBufferState(self) |
491 | 649 |
if self.NodeList is not None: |
205 | 650 |
self.RefreshTitle() |
651 |
||
652 |
#------------------------------------------------------------------------------- |
|
653 |
# Help Method |
|
654 |
#------------------------------------------------------------------------------- |
|
655 |
||
656 |
def OnHelpDS301Menu(self, event): |
|
657 |
find_index = False |
|
658 |
selected = self.NetworkNodes.GetSelection() |
|
659 |
if selected >= 0: |
|
660 |
window = self.NetworkNodes.GetPage(selected) |
|
661 |
result = window.GetSelection() |
|
662 |
if result: |
|
663 |
find_index = True |
|
664 |
index, subIndex = result |
|
665 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
|
512 | 666 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 667 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 668 |
message.ShowModal() |
669 |
message.Destroy() |
|
670 |
if not find_index: |
|
671 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
|
512 | 672 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 673 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 674 |
message.ShowModal() |
675 |
message.Destroy() |
|
676 |
||
677 |
def OnHelpCANFestivalMenu(self, event): |
|
678 |
#self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) |
|
386
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
679 |
if wx.Platform == '__WXMSW__': |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
680 |
readerpath = get_acroversion() |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
681 |
readerexepath = os.path.join(readerpath,"AcroRd32.exe") |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
682 |
if(os.path.isfile(readerexepath)): |
408
f85552acc2bf
fixed bug to open pdf with acrobat reader on Win32 in objdictedit and networkedit
greg
parents:
386
diff
changeset
|
683 |
os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%os.path.join(ScriptDirectory, "doc","manual_en.pdf")) |
386
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
684 |
else: |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
685 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
205 | 686 |
|
687 |
def OnAboutMenu(self, event): |
|
580 | 688 |
self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
205 | 689 |
|
690 |
def OpenHtmlFrame(self, title, file, size): |
|
691 |
if title not in self.HtmlFrameOpened: |
|
692 |
self.HtmlFrameOpened.append(title) |
|
693 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
694 |
window.SetTitle(title) |
|
695 |
window.SetHtmlPage(file) |
|
696 |
window.SetClientSize(size) |
|
697 |
window.Show() |
|
698 |
||
699 |
#------------------------------------------------------------------------------- |
|
700 |
# Exception Handler |
|
701 |
#------------------------------------------------------------------------------- |
|
702 |
||
703 |
Max_Traceback_List_Size = 20 |
|
704 |
||
705 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
706 |
trcbck_lst = [] |
|
707 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
580 | 708 |
trcbck = " " + str(i+1) + _(". ") |
205 | 709 |
if line[0].find(os.getcwd()) == -1: |
580 | 710 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
205 | 711 |
else: |
580 | 712 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
713 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
205 | 714 |
trcbck_lst.append(trcbck) |
715 |
||
716 |
# Allow clicking.... |
|
717 |
cap = wx.Window_GetCapture() |
|
718 |
if cap: |
|
719 |
cap.ReleaseMouse() |
|
720 |
||
721 |
dlg = wx.SingleChoiceDialog(None, |
|
580 | 722 |
_(""" |
205 | 723 |
An error happens. |
724 |
||
725 |
Click on OK for saving an error report. |
|
726 |
||
614 | 727 |
Please be kind enough to send this file to: |
728 |
edouard.tisserant@gmail.com |
|
205 | 729 |
|
730 |
||
731 |
Error: |
|
580 | 732 |
""") + |
733 |
str(e_type) + _(" : ") + str(e_value), |
|
734 |
_("Error"), |
|
205 | 735 |
trcbck_lst) |
736 |
try: |
|
737 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
738 |
finally: |
|
739 |
dlg.Destroy() |
|
740 |
||
741 |
return res |
|
742 |
||
743 |
def Display_Error_Dialog(e_value): |
|
580 | 744 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 745 |
message.ShowModal() |
746 |
message.Destroy() |
|
747 |
||
748 |
def get_last_traceback(tb): |
|
749 |
while tb.tb_next: |
|
750 |
tb = tb.tb_next |
|
751 |
return tb |
|
752 |
||
753 |
||
754 |
def format_namespace(d, indent=' '): |
|
755 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
756 |
||
757 |
||
758 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
759 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
760 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
205 | 761 |
|
762 |
def handle_exception(e_type, e_value, e_traceback): |
|
763 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
764 |
last_tb = get_last_traceback(e_traceback) |
|
765 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
766 |
if str(e_value).startswith("!!!"): |
|
767 |
Display_Error_Dialog(e_value) |
|
768 |
elif ex not in ignored_exceptions: |
|
769 |
ignored_exceptions.append(ex) |
|
770 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
771 |
if result: |
|
772 |
info = { |
|
773 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
774 |
'app-version' : app_version, |
|
775 |
'wx-version' : wx.VERSION_STRING, |
|
776 |
'wx-platform' : wx.Platform, |
|
777 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
778 |
'platform' : platform.platform(), |
|
779 |
'e-type' : e_type, |
|
780 |
'e-value' : e_value, |
|
781 |
'date' : time.ctime(), |
|
782 |
'cwd' : os.getcwd(), |
|
783 |
} |
|
784 |
if e_traceback: |
|
785 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
786 |
last_tb = get_last_traceback(e_traceback) |
|
787 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
788 |
info['locals'] = format_namespace(exception_locals) |
|
789 |
if 'self' in exception_locals: |
|
790 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
791 |
||
792 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
793 |
lst = info.keys() |
|
794 |
lst.sort() |
|
795 |
for a in lst: |
|
796 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
797 |
||
798 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
799 |
sys.excepthook = handle_exception |
|
800 |
||
801 |
if __name__ == '__main__': |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
802 |
wx.InitAllImageHandlers() |
205 | 803 |
|
804 |
# Install a exception handle for bug reports |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
805 |
AddExceptHook(os.getcwd(),__version__) |
205 | 806 |
|
276 | 807 |
frame = networkedit(None, projectOpen=projectOpen) |
205 | 808 |
|
809 |
frame.Show() |
|
810 |
app.MainLoop() |