author | Edouard Tisserant |
Mon, 23 Apr 2018 12:32:03 +0200 | |
changeset 805 | 570e3a444023 |
parent 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 |
||
26 |
from types import * |
|
27 |
import os, re, platform, sys, time, traceback, getopt |
|
28 |
||
580 | 29 |
__version__ = "$Revision: 1.27 $" |
30 |
||
31 |
if __name__ == '__main__': |
|
32 |
def usage(): |
|
33 |
print _("\nUsage of networkedit.py :") |
|
34 |
print "\n %s [Projectpath]\n"%sys.argv[0] |
|
35 |
||
36 |
try: |
|
37 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
38 |
except getopt.GetoptError: |
|
39 |
# print help information and exit: |
|
40 |
usage() |
|
41 |
sys.exit(2) |
|
42 |
||
43 |
for o, a in opts: |
|
44 |
if o in ("-h", "--help"): |
|
45 |
usage() |
|
46 |
sys.exit() |
|
47 |
||
48 |
if len(args) == 0: |
|
49 |
projectOpen = None |
|
50 |
elif len(args) == 1: |
|
51 |
projectOpen = args[0] |
|
52 |
else: |
|
53 |
usage() |
|
54 |
sys.exit(2) |
|
55 |
||
56 |
app = wx.PySimpleApp() |
|
57 |
||
58 |
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
|
59 |
||
60 |
# Import module for internationalization |
|
61 |
import gettext |
|
62 |
import __builtin__ |
|
63 |
||
64 |
# Get folder containing translation files |
|
65 |
localedir = os.path.join(ScriptDirectory,"locale") |
|
66 |
# Get the default language |
|
67 |
langid = wx.LANGUAGE_DEFAULT |
|
68 |
# Define translation domain (name of translation files) |
|
69 |
domain = "objdictgen" |
|
70 |
||
71 |
# Define locale for wx |
|
72 |
loc = __builtin__.__dict__.get('loc', None) |
|
73 |
if loc is None: |
|
74 |
loc = wx.Locale(langid) |
|
75 |
__builtin__.__dict__['loc'] = loc |
|
76 |
# Define location for searching translation files |
|
77 |
loc.AddCatalogLookupPathPrefix(localedir) |
|
78 |
# Define locale domain |
|
79 |
loc.AddCatalog(domain) |
|
80 |
||
81 |
if __name__ == '__main__': |
|
82 |
__builtin__.__dict__['_'] = wx.GetTranslation |
|
205 | 83 |
|
84 |
from nodelist import * |
|
85 |
from nodemanager import * |
|
778
9edaa9d21cf9
Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
748
diff
changeset
|
86 |
from networkeditortemplate import NetworkEditorTemplate |
205 | 87 |
from doc_index.DS301_index import * |
88 |
||
89 |
try: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
90 |
import wx.html |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
91 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
92 |
EVT_HTML_URL_CLICK = wx.NewId() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
93 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
94 |
class HtmlWindowUrlClick(wx.PyEvent): |
205 | 95 |
def __init__(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
96 |
wx.PyEvent.__init__(self) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
97 |
self.SetEventType(EVT_HTML_URL_CLICK) |
205 | 98 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
99 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
100 |
class UrlClickHtmlWindow(wx.html.HtmlWindow): |
205 | 101 |
""" HTML window that generates and OnLinkClicked event. |
102 |
||
103 |
Use this to avoid having to override HTMLWindow |
|
104 |
""" |
|
105 |
def OnLinkClicked(self, linkinfo): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
106 |
wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
107 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
108 |
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
|
109 |
if event == HtmlWindowUrlClick: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
110 |
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
|
111 |
else: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
112 |
wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
205 | 113 |
|
114 |
#------------------------------------------------------------------------------- |
|
115 |
# Html Frame |
|
116 |
#------------------------------------------------------------------------------- |
|
117 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
118 |
[ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
205 | 119 |
|
120 |
class HtmlFrame(wx.Frame): |
|
121 |
def _init_ctrls(self, prnt): |
|
122 |
# generated method, don't edit |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
123 |
wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
205 | 124 |
parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
125 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
|
273 | 126 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
205 | 127 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
128 |
self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
205 | 129 |
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
|
130 |
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
|
131 |
self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
205 | 132 |
|
133 |
def __init__(self, parent, opened): |
|
134 |
self._init_ctrls(parent) |
|
135 |
self.HtmlFrameOpened = opened |
|
136 |
||
137 |
def SetHtmlCode(self, htmlcode): |
|
138 |
self.HtmlContent.SetPage(htmlcode) |
|
139 |
||
140 |
def SetHtmlPage(self, htmlpage): |
|
141 |
self.HtmlContent.LoadPage(htmlpage) |
|
142 |
||
143 |
def OnCloseFrame(self, event): |
|
144 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
|
145 |
event.Skip() |
|
146 |
||
147 |
def OnLinkClick(self, event): |
|
148 |
url = event.linkinfo[0] |
|
149 |
try: |
|
150 |
import webbrowser |
|
151 |
except ImportError: |
|
580 | 152 |
wx.MessageBox(_('Please point your browser at: %s') % url) |
205 | 153 |
else: |
154 |
webbrowser.open(url) |
|
155 |
||
156 |
Html_Window = True |
|
157 |
except: |
|
158 |
Html_Window = False |
|
159 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
160 |
[ID_NETWORKEDIT, ID_NETWORKEDITNETWORKNODES, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
161 |
ID_NETWORKEDITHELPBAR, |
205 | 162 |
] = [wx.NewId() for _init_ctrls in range(3)] |
163 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
164 |
[ID_NETWORKEDITNETWORKMENUBUILDMASTER, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
165 |
] = [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
|
166 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
167 |
[ID_NETWORKEDITEDITMENUNODEINFOS, ID_NETWORKEDITEDITMENUDS301PROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
168 |
ID_NETWORKEDITEDITMENUDS302PROFILE, ID_NETWORKEDITEDITMENUOTHERPROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
169 |
] = [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
|
170 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
171 |
[ID_NETWORKEDITADDMENUSDOSERVER, ID_NETWORKEDITADDMENUSDOCLIENT, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
172 |
ID_NETWORKEDITADDMENUPDOTRANSMIT, ID_NETWORKEDITADDMENUPDORECEIVE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
173 |
ID_NETWORKEDITADDMENUMAPVARIABLE, ID_NETWORKEDITADDMENUUSERTYPE, |
205 | 174 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
175 |
||
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
176 |
class networkedit(wx.Frame, NetworkEditorTemplate): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
177 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
178 |
EDITMENU_ID = ID_NETWORKEDITEDITMENUOTHERPROFILE |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
179 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
180 |
def _init_coll_MenuBar_Menus(self, parent): |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
181 |
if self.ModeSolo: |
580 | 182 |
parent.Append(menu=self.FileMenu, title=_('File')) |
183 |
parent.Append(menu=self.NetworkMenu, title=_('Network')) |
|
184 |
parent.Append(menu=self.EditMenu, title=_('Edit')) |
|
185 |
parent.Append(menu=self.AddMenu, title=_('Add')) |
|
186 |
parent.Append(menu=self.HelpMenu, title=_('Help')) |
|
205 | 187 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
188 |
def _init_coll_FileMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
189 |
parent.Append(help='', id=wx.ID_NEW, |
580 | 190 |
kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
191 |
parent.Append(help='', id=wx.ID_OPEN, |
580 | 192 |
kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
193 |
parent.Append(help='', id=wx.ID_CLOSE, |
580 | 194 |
kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
195 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
196 |
parent.Append(help='', id=wx.ID_SAVE, |
580 | 197 |
kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
198 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
199 |
parent.Append(help='', id=wx.ID_EXIT, |
580 | 200 |
kind=wx.ITEM_NORMAL, text=_('Exit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
201 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
202 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
203 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
204 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
205 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
206 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
207 |
def _init_coll_NetworkMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
208 |
parent.Append(help='', id=wx.ID_ADD, |
580 | 209 |
kind=wx.ITEM_NORMAL, text=_('Add Slave Node')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
210 |
parent.Append(help='', id=wx.ID_DELETE, |
580 | 211 |
kind=wx.ITEM_NORMAL, text=_('Remove Slave Node')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
212 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
213 |
parent.Append(help='', id=ID_NETWORKEDITNETWORKMENUBUILDMASTER, |
580 | 214 |
kind=wx.ITEM_NORMAL, text=_('Build Master Dictionary')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
215 |
self.Bind(wx.EVT_MENU, self.OnAddSlaveMenu, id=wx.ID_ADD) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
216 |
self.Bind(wx.EVT_MENU, self.OnRemoveSlaveMenu, id=wx.ID_DELETE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
217 |
## self.Bind(wx.EVT_MENU, self.OnBuildMasterMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
218 |
## id=ID_NETWORKEDITNETWORKMENUBUILDMASTER) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
219 |
|
205 | 220 |
def _init_coll_EditMenu_Items(self, parent): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
221 |
parent.Append(help='', id=wx.ID_REFRESH, |
580 | 222 |
kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R')) |
205 | 223 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
224 |
parent.Append(help='', id=wx.ID_UNDO, |
580 | 225 |
kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
226 |
parent.Append(help='', id=wx.ID_REDO, |
580 | 227 |
kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y')) |
205 | 228 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
229 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUNODEINFOS, |
580 | 230 |
kind=wx.ITEM_NORMAL, text=_('Node infos')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
231 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS301PROFILE, |
580 | 232 |
kind=wx.ITEM_NORMAL, text=_('DS-301 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
233 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUDS302PROFILE, |
580 | 234 |
kind=wx.ITEM_NORMAL, text=_('DS-302 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
235 |
parent.Append(help='', id=ID_NETWORKEDITEDITMENUOTHERPROFILE, |
580 | 236 |
kind=wx.ITEM_NORMAL, text=_('Other Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
237 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
238 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
239 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
240 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
241 |
id=ID_NETWORKEDITEDITMENUNODEINFOS) |
205 | 242 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
243 |
id=ID_NETWORKEDITEDITMENUDS301PROFILE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
244 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
245 |
id=ID_NETWORKEDITEDITMENUDS302PROFILE) |
205 | 246 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
247 |
id=ID_NETWORKEDITEDITMENUOTHERPROFILE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
248 |
|
205 | 249 |
def _init_coll_AddMenu_Items(self, parent): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
250 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOSERVER, |
580 | 251 |
kind=wx.ITEM_NORMAL, text=_('SDO Server')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
252 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUSDOCLIENT, |
580 | 253 |
kind=wx.ITEM_NORMAL, text=_('SDO Client')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
254 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUPDOTRANSMIT, |
580 | 255 |
kind=wx.ITEM_NORMAL, text=_('PDO Transmit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
256 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUPDORECEIVE, |
580 | 257 |
kind=wx.ITEM_NORMAL, text=_('PDO Receive')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
258 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUMAPVARIABLE, |
580 | 259 |
kind=wx.ITEM_NORMAL, text=_('Map Variable')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
260 |
parent.Append(help='', id=ID_NETWORKEDITADDMENUUSERTYPE, |
580 | 261 |
kind=wx.ITEM_NORMAL, text=_('User Type')) |
205 | 262 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
263 |
id=ID_NETWORKEDITADDMENUSDOSERVER) |
205 | 264 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
265 |
id=ID_NETWORKEDITADDMENUSDOCLIENT) |
205 | 266 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
267 |
id=ID_NETWORKEDITADDMENUPDOTRANSMIT) |
205 | 268 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
269 |
id=ID_NETWORKEDITADDMENUPDORECEIVE) |
205 | 270 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
271 |
id=ID_NETWORKEDITADDMENUMAPVARIABLE) |
205 | 272 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
273 |
id=ID_NETWORKEDITADDMENUUSERTYPE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
274 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
275 |
def _init_coll_HelpMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
276 |
parent.Append(help='', id=wx.ID_HELP, |
580 | 277 |
kind=wx.ITEM_NORMAL, text=_('DS-301 Standard\tF1')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
278 |
self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, id=wx.ID_HELP) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
279 |
parent.Append(help='', id=wx.ID_HELP_CONTEXT, |
580 | 280 |
kind=wx.ITEM_NORMAL, text=_('CAN Festival Docs\tF2')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
281 |
self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, id=wx.ID_HELP_CONTEXT) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
282 |
if Html_Window and self.ModeSolo: |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
283 |
parent.Append(help='', id=wx.ID_ABOUT, |
580 | 284 |
kind=wx.ITEM_NORMAL, text=_('About')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
285 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
205 | 286 |
|
287 |
def _init_coll_HelpBar_Fields(self, parent): |
|
288 |
parent.SetFieldsCount(3) |
|
289 |
||
290 |
parent.SetStatusText(number=0, text='') |
|
291 |
parent.SetStatusText(number=1, text='') |
|
292 |
parent.SetStatusText(number=2, text='') |
|
293 |
||
294 |
parent.SetStatusWidths([100, 110, -1]) |
|
295 |
||
296 |
def _init_utils(self): |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
297 |
self.MenuBar = wx.MenuBar() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
298 |
self.MenuBar.SetEvtHandlerEnabled(True) |
205 | 299 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
300 |
if self.ModeSolo: |
205 | 301 |
self.FileMenu = wx.Menu(title='') |
302 |
self.NetworkMenu = wx.Menu(title='') |
|
303 |
self.EditMenu = wx.Menu(title='') |
|
304 |
self.AddMenu = wx.Menu(title='') |
|
305 |
self.HelpMenu = wx.Menu(title='') |
|
306 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
307 |
self._init_coll_MenuBar_Menus(self.MenuBar) |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
308 |
if self.ModeSolo: |
205 | 309 |
self._init_coll_FileMenu_Items(self.FileMenu) |
310 |
self._init_coll_NetworkMenu_Items(self.NetworkMenu) |
|
311 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
312 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
313 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
314 |
||
315 |
def _init_ctrls(self, prnt): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
316 |
wx.Frame.__init__(self, id=ID_NETWORKEDIT, name='networkedit', |
205 | 317 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
580 | 318 |
style=wx.DEFAULT_FRAME_STYLE, title=_('Networkedit')) |
205 | 319 |
self._init_utils() |
320 |
self.SetClientSize(wx.Size(1000, 700)) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
321 |
self.SetMenuBar(self.MenuBar) |
273 | 322 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
271 | 323 |
if not self.ModeSolo: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
324 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
325 |
accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, wx.ID_SAVE)]) |
271 | 326 |
self.SetAcceleratorTable(accel) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
327 |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
328 |
NetworkEditorTemplate._init_ctrls(self, self) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
329 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
330 |
self.HelpBar = wx.StatusBar(id=ID_NETWORKEDITHELPBAR, name='HelpBar', |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
331 |
parent=self, style=wx.ST_SIZEGRIP) |
205 | 332 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
333 |
self.SetStatusBar(self.HelpBar) |
|
334 |
||
276 | 335 |
def __init__(self, parent, nodelist = None, projectOpen = None): |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
336 |
if nodelist is None: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
337 |
NetworkEditorTemplate.__init__(self, NodeList(NodeManager()), self, True) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
338 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
339 |
NetworkEditorTemplate.__init__(self, nodelist, self, False) |
205 | 340 |
self._init_ctrls(parent) |
341 |
self.HtmlFrameOpened = [] |
|
342 |
||
410 | 343 |
icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO) |
409 | 344 |
self.SetIcon(icon) |
410 | 345 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
346 |
if self.ModeSolo: |
205 | 347 |
if projectOpen: |
348 |
result = self.NodeList.LoadProject(projectOpen) |
|
349 |
if not result: |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
350 |
self.NodeList.SetCurrentSelected(0) |
205 | 351 |
self.RefreshNetworkNodes() |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
352 |
self.RefreshProfileMenu() |
205 | 353 |
else: |
354 |
self.NodeList = None |
|
355 |
else: |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
356 |
self.NodeList.SetCurrentSelected(0) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
357 |
self.RefreshNetworkNodes() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
358 |
self.RefreshProfileMenu() |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
359 |
self.NetworkNodes.SetFocus() |
205 | 360 |
|
361 |
self.RefreshBufferState() |
|
362 |
self.RefreshTitle() |
|
363 |
self.RefreshMainMenu() |
|
364 |
||
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
365 |
def OnCloseFrame(self, event): |
491 | 366 |
self.Closing = True |
271 | 367 |
if not self.ModeSolo and getattr(self, "_onclose", None) != None: |
368 |
self._onclose() |
|
369 |
event.Skip() |
|
370 |
||
371 |
def OnChar(self, event): |
|
372 |
if event.ControlDown() and event.GetKeyCode() == 83 and getattr(self, "_onsave", None) != None: |
|
373 |
self._onsave() |
|
612 | 374 |
#event.Skip() |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
375 |
|
205 | 376 |
def OnQuitMenu(self, event): |
377 |
self.Close() |
|
378 |
||
379 |
#------------------------------------------------------------------------------- |
|
380 |
# Load and Save Funtions |
|
381 |
#------------------------------------------------------------------------------- |
|
382 |
||
383 |
def OnNewProjectMenu(self, event): |
|
384 |
if self.NodeList: |
|
385 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
386 |
else: |
|
387 |
defaultpath = os.getcwd() |
|
580 | 388 |
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
|
389 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 390 |
projectpath = dialog.GetPath() |
206 | 391 |
if os.path.isdir(projectpath) and len(os.listdir(projectpath)) == 0: |
258 | 392 |
manager = NodeManager() |
205 | 393 |
nodelist = NodeList(manager) |
394 |
result = nodelist.LoadProject(projectpath) |
|
395 |
if not result: |
|
396 |
self.Manager = manager |
|
397 |
self.NodeList = nodelist |
|
398 |
self.NodeList.SetCurrentSelected(0) |
|
399 |
||
400 |
self.RefreshNetworkNodes() |
|
401 |
self.RefreshBufferState() |
|
402 |
self.RefreshTitle() |
|
403 |
self.RefreshProfileMenu() |
|
404 |
self.RefreshMainMenu() |
|
405 |
else: |
|
580 | 406 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 407 |
message.ShowModal() |
408 |
message.Destroy() |
|
608 | 409 |
|
205 | 410 |
def OnOpenProjectMenu(self, event): |
411 |
if self.NodeList: |
|
412 |
defaultpath = os.path.dirname(self.NodeList.GetRoot()) |
|
413 |
else: |
|
414 |
defaultpath = os.getcwd() |
|
580 | 415 |
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
|
416 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 417 |
projectpath = dialog.GetPath() |
418 |
if os.path.isdir(projectpath): |
|
258 | 419 |
manager = NodeManager() |
205 | 420 |
nodelist = NodeList(manager) |
421 |
result = nodelist.LoadProject(projectpath) |
|
422 |
if not result: |
|
423 |
self.Manager = manager |
|
424 |
self.NodeList = nodelist |
|
425 |
self.NodeList.SetCurrentSelected(0) |
|
426 |
||
427 |
self.RefreshNetworkNodes() |
|
428 |
self.RefreshBufferState() |
|
429 |
self.RefreshTitle() |
|
430 |
self.RefreshProfileMenu() |
|
431 |
self.RefreshMainMenu() |
|
432 |
else: |
|
580 | 433 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 434 |
message.ShowModal() |
435 |
message.Destroy() |
|
436 |
dialog.Destroy() |
|
608 | 437 |
|
205 | 438 |
def OnSaveProjectMenu(self, event): |
271 | 439 |
if not self.ModeSolo and getattr(self, "_onsave", None) != None: |
440 |
self._onsave() |
|
441 |
else: |
|
442 |
result = self.NodeList.SaveProject() |
|
443 |
if result: |
|
580 | 444 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
271 | 445 |
message.ShowModal() |
446 |
message.Destroy() |
|
608 | 447 |
|
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
448 |
def OnCloseProjectMenu(self, event): |
238 | 449 |
if self.NodeList: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
450 |
if self.NodeList.HasChanged(): |
580 | 451 |
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
|
452 |
answer = dialog.ShowModal() |
238 | 453 |
dialog.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
454 |
if answer == wx.ID_YES: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
455 |
result = self.NodeList.SaveProject() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
456 |
if result: |
580 | 457 |
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
|
458 |
message.ShowModal() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
459 |
message.Destroy() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
460 |
elif answer == wx.ID_NO: |
242
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
461 |
self.NodeList.ForceChanged(False) |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
462 |
if not self.NodeList.HasChanged(): |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
463 |
self.Manager = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
464 |
self.NodeList = None |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
465 |
self.RefreshNetworkNodes() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
466 |
self.RefreshTitle() |
4864f7f01e1d
Changes in networkedit for integration with beremiz
lbessard
parents:
238
diff
changeset
|
467 |
self.RefreshMainMenu() |
608 | 468 |
|
469 |
||
205 | 470 |
#------------------------------------------------------------------------------- |
471 |
# Refresh Functions |
|
472 |
#------------------------------------------------------------------------------- |
|
473 |
||
474 |
def RefreshTitle(self): |
|
475 |
if self.NodeList != None: |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
476 |
self.SetTitle(_("Networkedit - %s") % self.NodeList.GetNetworkName()) |
205 | 477 |
else: |
580 | 478 |
self.SetTitle(_("Networkedit")) |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
479 |
|
205 | 480 |
def RefreshStatusBar(self): |
491 | 481 |
selected = self.NetworkNodes.GetSelection() |
482 |
if self.HelpBar and selected >= 0: |
|
483 |
window = self.NetworkNodes.GetPage(selected) |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
484 |
self.SetStatusBarText(window.GetSelection(), self.NodeList) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
485 |
|
205 | 486 |
def RefreshMainMenu(self): |
491 | 487 |
self.NetworkMenu.Enable(ID_NETWORKEDITNETWORKMENUBUILDMASTER, False) |
488 |
if self.NodeList == None: |
|
489 |
if self.ModeSolo: |
|
490 |
self.MenuBar.EnableTop(1, False) |
|
491 |
self.MenuBar.EnableTop(2, False) |
|
492 |
self.MenuBar.EnableTop(3, False) |
|
493 |
if self.FileMenu: |
|
494 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
495 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
496 |
else: |
|
497 |
self.MenuBar.EnableTop(0, False) |
|
498 |
self.MenuBar.EnableTop(1, False) |
|
499 |
self.MenuBar.EnableTop(2, False) |
|
500 |
else: |
|
501 |
if self.ModeSolo: |
|
502 |
self.MenuBar.EnableTop(1, True) |
|
503 |
if self.FileMenu: |
|
504 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
505 |
self.FileMenu.Enable(wx.ID_SAVE, True) |
|
506 |
if self.NetworkNodes.GetSelection() == 0: |
|
507 |
self.MenuBar.EnableTop(2, True) |
|
508 |
self.MenuBar.EnableTop(3, True) |
|
509 |
else: |
|
510 |
self.MenuBar.EnableTop(2, False) |
|
511 |
self.MenuBar.EnableTop(3, False) |
|
512 |
else: |
|
513 |
self.MenuBar.EnableTop(0, True) |
|
514 |
if self.NetworkNodes.GetSelection() == 0: |
|
515 |
self.MenuBar.EnableTop(1, True) |
|
516 |
self.MenuBar.EnableTop(2, True) |
|
517 |
else: |
|
518 |
self.MenuBar.EnableTop(1, False) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
519 |
self.MenuBar.EnableTop(2, False) |
205 | 520 |
|
521 |
#------------------------------------------------------------------------------- |
|
522 |
# Buffer Functions |
|
523 |
#------------------------------------------------------------------------------- |
|
524 |
||
525 |
def RefreshBufferState(self): |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
526 |
NetworkEditorTemplate.RefreshBufferState(self) |
491 | 527 |
if self.NodeList is not None: |
205 | 528 |
self.RefreshTitle() |
529 |
||
530 |
#------------------------------------------------------------------------------- |
|
531 |
# Help Method |
|
532 |
#------------------------------------------------------------------------------- |
|
533 |
||
534 |
def OnHelpDS301Menu(self, event): |
|
535 |
find_index = False |
|
536 |
selected = self.NetworkNodes.GetSelection() |
|
537 |
if selected >= 0: |
|
538 |
window = self.NetworkNodes.GetPage(selected) |
|
539 |
result = window.GetSelection() |
|
540 |
if result: |
|
541 |
find_index = True |
|
542 |
index, subIndex = result |
|
543 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
|
512 | 544 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 545 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 546 |
message.ShowModal() |
547 |
message.Destroy() |
|
548 |
if not find_index: |
|
549 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
|
512 | 550 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 551 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
205 | 552 |
message.ShowModal() |
553 |
message.Destroy() |
|
554 |
||
555 |
def OnHelpCANFestivalMenu(self, event): |
|
556 |
#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
|
557 |
if wx.Platform == '__WXMSW__': |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
558 |
readerpath = get_acroversion() |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
else: |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
339
diff
changeset
|
563 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
205 | 564 |
|
565 |
def OnAboutMenu(self, event): |
|
580 | 566 |
self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
205 | 567 |
|
568 |
def OpenHtmlFrame(self, title, file, size): |
|
569 |
if title not in self.HtmlFrameOpened: |
|
570 |
self.HtmlFrameOpened.append(title) |
|
571 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
572 |
window.SetTitle(title) |
|
573 |
window.SetHtmlPage(file) |
|
574 |
window.SetClientSize(size) |
|
575 |
window.Show() |
|
576 |
||
577 |
#------------------------------------------------------------------------------- |
|
578 |
# Exception Handler |
|
579 |
#------------------------------------------------------------------------------- |
|
580 |
||
581 |
Max_Traceback_List_Size = 20 |
|
582 |
||
583 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
584 |
trcbck_lst = [] |
|
585 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
580 | 586 |
trcbck = " " + str(i+1) + _(". ") |
205 | 587 |
if line[0].find(os.getcwd()) == -1: |
580 | 588 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
205 | 589 |
else: |
580 | 590 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
591 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
205 | 592 |
trcbck_lst.append(trcbck) |
593 |
||
594 |
# Allow clicking.... |
|
595 |
cap = wx.Window_GetCapture() |
|
596 |
if cap: |
|
597 |
cap.ReleaseMouse() |
|
598 |
||
599 |
dlg = wx.SingleChoiceDialog(None, |
|
580 | 600 |
_(""" |
205 | 601 |
An error happens. |
602 |
||
603 |
Click on OK for saving an error report. |
|
604 |
||
614 | 605 |
Please be kind enough to send this file to: |
606 |
edouard.tisserant@gmail.com |
|
205 | 607 |
|
608 |
||
609 |
Error: |
|
580 | 610 |
""") + |
611 |
str(e_type) + _(" : ") + str(e_value), |
|
612 |
_("Error"), |
|
205 | 613 |
trcbck_lst) |
614 |
try: |
|
615 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
616 |
finally: |
|
617 |
dlg.Destroy() |
|
618 |
||
619 |
return res |
|
620 |
||
621 |
def Display_Error_Dialog(e_value): |
|
580 | 622 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR) |
205 | 623 |
message.ShowModal() |
624 |
message.Destroy() |
|
625 |
||
626 |
def get_last_traceback(tb): |
|
627 |
while tb.tb_next: |
|
628 |
tb = tb.tb_next |
|
629 |
return tb |
|
630 |
||
631 |
||
632 |
def format_namespace(d, indent=' '): |
|
633 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
634 |
||
635 |
||
636 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
637 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
638 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
205 | 639 |
|
640 |
def handle_exception(e_type, e_value, e_traceback): |
|
641 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
642 |
last_tb = get_last_traceback(e_traceback) |
|
643 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
644 |
if str(e_value).startswith("!!!"): |
|
645 |
Display_Error_Dialog(e_value) |
|
646 |
elif ex not in ignored_exceptions: |
|
647 |
ignored_exceptions.append(ex) |
|
648 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
649 |
if result: |
|
650 |
info = { |
|
651 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
652 |
'app-version' : app_version, |
|
653 |
'wx-version' : wx.VERSION_STRING, |
|
654 |
'wx-platform' : wx.Platform, |
|
655 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
656 |
'platform' : platform.platform(), |
|
657 |
'e-type' : e_type, |
|
658 |
'e-value' : e_value, |
|
659 |
'date' : time.ctime(), |
|
660 |
'cwd' : os.getcwd(), |
|
661 |
} |
|
662 |
if e_traceback: |
|
663 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
664 |
last_tb = get_last_traceback(e_traceback) |
|
665 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
666 |
info['locals'] = format_namespace(exception_locals) |
|
667 |
if 'self' in exception_locals: |
|
668 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
669 |
||
670 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
671 |
lst = info.keys() |
|
672 |
lst.sort() |
|
673 |
for a in lst: |
|
674 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
675 |
||
676 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
677 |
sys.excepthook = handle_exception |
|
678 |
||
679 |
if __name__ == '__main__': |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
680 |
wx.InitAllImageHandlers() |
205 | 681 |
|
682 |
# Install a exception handle for bug reports |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
243
diff
changeset
|
683 |
AddExceptHook(os.getcwd(),__version__) |
205 | 684 |
|
276 | 685 |
frame = networkedit(None, projectOpen=projectOpen) |
205 | 686 |
|
687 |
frame.Show() |
|
688 |
app.MainLoop() |