author | nico |
Mon, 04 Jun 2007 17:59:50 +0200 | |
changeset 207 | b6572d0336c3 |
parent 206 | 6787754b251b |
child 209 | 2cb34a4ac65a |
permissions | -rwxr-xr-x |
0 | 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 |
from wxPython.wx import * |
|
25 |
from wxPython.grid import * |
|
26 |
import wx |
|
27 |
import wx.grid |
|
28 |
||
29 |
from types import * |
|
30 |
import os, re, platform, sys, time, traceback, getopt |
|
31 |
||
32 |
__version__ = "$Revision$" |
|
33 |
||
206 | 34 |
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes |
35 |
||
0 | 36 |
from nodemanager import * |
205 | 37 |
from subindextable import * |
38 |
from commondialogs import * |
|
0 | 39 |
from doc_index.DS301_index import * |
40 |
||
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
41 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
42 |
from wxPython.html import * |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
43 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
44 |
wxEVT_HTML_URL_CLICK = wxNewId() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
45 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
46 |
def EVT_HTML_URL_CLICK(win, func): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
47 |
win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
48 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
49 |
class wxHtmlWindowUrlClick(wxPyEvent): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
50 |
def __init__(self, linkinfo): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
51 |
wxPyEvent.__init__(self) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
52 |
self.SetEventType(wxEVT_HTML_URL_CLICK) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
53 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
54 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
55 |
class wxUrlClickHtmlWindow(wxHtmlWindow): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
56 |
""" HTML window that generates and OnLinkClicked event. |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
57 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
58 |
Use this to avoid having to override HTMLWindow |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
59 |
""" |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
60 |
def OnLinkClicked(self, linkinfo): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
61 |
wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo)) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
62 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
63 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
64 |
# Html Frame |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
65 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
66 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
67 |
[wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
68 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
69 |
class HtmlFrame(wx.Frame): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
70 |
def _init_ctrls(self, prnt): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
71 |
# generated method, don't edit |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
72 |
wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame', |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
73 |
parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
74 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
75 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
76 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
77 |
self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
78 |
name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
79 |
size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
80 |
EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
81 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
82 |
def __init__(self, parent, opened): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
83 |
self._init_ctrls(parent) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
84 |
self.HtmlFrameOpened = opened |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
85 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
86 |
def SetHtmlCode(self, htmlcode): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
87 |
self.HtmlContent.SetPage(htmlcode) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
88 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
89 |
def SetHtmlPage(self, htmlpage): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
90 |
self.HtmlContent.LoadPage(htmlpage) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
91 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
92 |
def OnCloseFrame(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
93 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
94 |
event.Skip() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
95 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
96 |
def OnLinkClick(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
97 |
url = event.linkinfo[0] |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
98 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
99 |
import webbrowser |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
100 |
except ImportError: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
101 |
wxMessageBox('Please point your browser at: %s' % url) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
102 |
else: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
103 |
webbrowser.open(url) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
104 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
105 |
Html_Window = True |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
106 |
except: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
107 |
Html_Window = False |
0 | 108 |
|
109 |
def create(parent): |
|
110 |
return objdictedit(parent) |
|
111 |
||
112 |
def usage(): |
|
205 | 113 |
print "\nUsage of objdictedit.py :" |
0 | 114 |
print "\n %s [Filepath, ...]\n"%sys.argv[0] |
115 |
||
116 |
try: |
|
117 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
118 |
except getopt.GetoptError: |
|
119 |
# print help information and exit: |
|
120 |
usage() |
|
121 |
sys.exit(2) |
|
122 |
||
123 |
for o, a in opts: |
|
124 |
if o in ("-h", "--help"): |
|
125 |
usage() |
|
126 |
sys.exit() |
|
127 |
||
128 |
filesOpen = args |
|
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
129 |
ScriptDirectory = sys.path[0] |
0 | 130 |
|
131 |
||
132 |
[wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, |
|
133 |
wxID_OBJDICTEDITHELPBAR, |
|
134 |
] = [wx.NewId() for _init_ctrls in range(3)] |
|
135 |
||
136 |
[wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, |
|
137 |
wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, |
|
138 |
wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, |
|
139 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
|
140 |
||
141 |
[wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, |
|
142 |
wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, |
|
143 |
wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, |
|
144 |
wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8, |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
145 |
wxID_OBJDICTEDITFILEMENUITEMS9, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
146 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
0 | 147 |
|
148 |
[wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, |
|
149 |
wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, |
|
150 |
wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, |
|
151 |
wxID_OBJDICTEDITEDITMENUITEMS8, |
|
152 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] |
|
153 |
||
154 |
[wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1, |
|
155 |
wxID_OBJDICTEDITHELPMENUITEMS2, |
|
156 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] |
|
157 |
||
158 |
class objdictedit(wx.Frame): |
|
159 |
def _init_coll_menuBar1_Menus(self, parent): |
|
160 |
# generated method, don't edit |
|
161 |
||
162 |
parent.Append(menu=self.FileMenu, title='File') |
|
163 |
parent.Append(menu=self.EditMenu, title='Edit') |
|
164 |
parent.Append(menu=self.AddMenu, title='Add') |
|
165 |
parent.Append(menu=self.HelpMenu, title='Help') |
|
166 |
||
167 |
def _init_coll_EditMenu_Items(self, parent): |
|
168 |
# generated method, don't edit |
|
169 |
||
170 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4, |
|
171 |
kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') |
|
172 |
parent.AppendSeparator() |
|
173 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1, |
|
174 |
kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') |
|
175 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0, |
|
176 |
kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') |
|
177 |
parent.AppendSeparator() |
|
178 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6, |
|
179 |
kind=wx.ITEM_NORMAL, text='Node infos') |
|
180 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2, |
|
181 |
kind=wx.ITEM_NORMAL, text='DS-301 Profile') |
|
182 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8, |
|
183 |
kind=wx.ITEM_NORMAL, text='DS-302 Profile') |
|
184 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7, |
|
185 |
kind=wx.ITEM_NORMAL, text='Other Profile') |
|
186 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, |
|
187 |
id=wxID_OBJDICTEDITEDITMENUITEMS1) |
|
188 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, |
|
189 |
id=wxID_OBJDICTEDITEDITMENUITEMS0) |
|
190 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
|
191 |
id=wxID_OBJDICTEDITEDITMENUITEMS2) |
|
192 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
|
193 |
id=wxID_OBJDICTEDITEDITMENUITEMS4) |
|
194 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
|
195 |
id=wxID_OBJDICTEDITEDITMENUITEMS6) |
|
196 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
|
197 |
id=wxID_OBJDICTEDITEDITMENUITEMS7) |
|
198 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
|
199 |
id=wxID_OBJDICTEDITEDITMENUITEMS8) |
|
200 |
||
201 |
def _init_coll_HelpMenu_Items(self, parent): |
|
202 |
# generated method, don't edit |
|
203 |
||
204 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0, |
|
205 |
kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') |
|
206 |
self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, |
|
207 |
id=wxID_OBJDICTEDITHELPMENUITEMS0) |
|
205 | 208 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1, |
209 |
kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') |
|
210 |
self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, |
|
211 |
id=wxID_OBJDICTEDITHELPMENUITEMS1) |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
212 |
if Html_Window: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
213 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
214 |
kind=wx.ITEM_NORMAL, text='About') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
215 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
216 |
id=wxID_OBJDICTEDITHELPMENUITEMS2) |
0 | 217 |
|
218 |
def _init_coll_FileMenu_Items(self, parent): |
|
219 |
# generated method, don't edit |
|
220 |
||
221 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5, |
|
222 |
kind=wx.ITEM_NORMAL, text='New\tCTRL+N') |
|
223 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0, |
|
224 |
kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') |
|
225 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1, |
|
226 |
kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') |
|
227 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6, |
|
228 |
kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') |
|
229 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2, |
|
230 |
kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') |
|
231 |
parent.AppendSeparator() |
|
171 | 232 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7, |
233 |
kind=wx.ITEM_NORMAL, text='Import EDS file') |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
234 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS9, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
235 |
kind=wx.ITEM_NORMAL, text='Export to EDS file') |
0 | 236 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8, |
237 |
kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') |
|
238 |
parent.AppendSeparator() |
|
239 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4, |
|
240 |
kind=wx.ITEM_NORMAL, text='Exit') |
|
241 |
self.Bind(wx.EVT_MENU, self.OnOpenMenu, |
|
242 |
id=wxID_OBJDICTEDITFILEMENUITEMS0) |
|
243 |
self.Bind(wx.EVT_MENU, self.OnSaveMenu, |
|
244 |
id=wxID_OBJDICTEDITFILEMENUITEMS1) |
|
245 |
self.Bind(wx.EVT_MENU, self.OnCloseMenu, |
|
246 |
id=wxID_OBJDICTEDITFILEMENUITEMS2) |
|
247 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
|
248 |
id=wxID_OBJDICTEDITFILEMENUITEMS4) |
|
249 |
self.Bind(wx.EVT_MENU, self.OnNewMenu, |
|
250 |
id=wxID_OBJDICTEDITFILEMENUITEMS5) |
|
251 |
self.Bind(wx.EVT_MENU, self.OnSaveAsMenu, |
|
252 |
id=wxID_OBJDICTEDITFILEMENUITEMS6) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
253 |
self.Bind(wx.EVT_MENU, self.OnImportEDSMenu, |
171 | 254 |
id=wxID_OBJDICTEDITFILEMENUITEMS7) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
255 |
self.Bind(wx.EVT_MENU, self.OnExportCMenu, |
0 | 256 |
id=wxID_OBJDICTEDITFILEMENUITEMS8) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
257 |
self.Bind(wx.EVT_MENU, self.OnExportEDSMenu, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
258 |
id=wxID_OBJDICTEDITFILEMENUITEMS9) |
0 | 259 |
|
260 |
def _init_coll_AddMenu_Items(self, parent): |
|
261 |
# generated method, don't edit |
|
262 |
||
263 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0, |
|
264 |
kind=wx.ITEM_NORMAL, text='SDO Server') |
|
265 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1, |
|
266 |
kind=wx.ITEM_NORMAL, text='SDO Client') |
|
267 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2, |
|
268 |
kind=wx.ITEM_NORMAL, text='PDO Transmit') |
|
269 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3, |
|
270 |
kind=wx.ITEM_NORMAL, text='PDO Receive') |
|
271 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4, |
|
272 |
kind=wx.ITEM_NORMAL, text='Map Variable') |
|
273 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5, |
|
274 |
kind=wx.ITEM_NORMAL, text='User Type') |
|
275 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
|
276 |
id=wxID_OBJDICTEDITADDMENUITEMS0) |
|
277 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
|
278 |
id=wxID_OBJDICTEDITADDMENUITEMS1) |
|
279 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
|
280 |
id=wxID_OBJDICTEDITADDMENUITEMS2) |
|
281 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
|
282 |
id=wxID_OBJDICTEDITADDMENUITEMS3) |
|
283 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
|
284 |
id=wxID_OBJDICTEDITADDMENUITEMS4) |
|
285 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
|
286 |
id=wxID_OBJDICTEDITADDMENUITEMS5) |
|
287 |
||
288 |
def _init_coll_HelpBar_Fields(self, parent): |
|
289 |
# generated method, don't edit |
|
290 |
parent.SetFieldsCount(3) |
|
291 |
||
292 |
parent.SetStatusText(number=0, text='') |
|
293 |
parent.SetStatusText(number=1, text='') |
|
294 |
parent.SetStatusText(number=2, text='') |
|
295 |
||
296 |
parent.SetStatusWidths([100, 110, -1]) |
|
297 |
||
298 |
def _init_utils(self): |
|
299 |
# generated method, don't edit |
|
300 |
self.menuBar1 = wx.MenuBar() |
|
301 |
self.menuBar1.SetEvtHandlerEnabled(True) |
|
302 |
||
303 |
self.FileMenu = wx.Menu(title='') |
|
304 |
||
305 |
self.EditMenu = wx.Menu(title='') |
|
306 |
||
307 |
self.AddMenu = wx.Menu(title='') |
|
308 |
||
309 |
self.HelpMenu = wx.Menu(title='') |
|
310 |
||
311 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
312 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
313 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
314 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
315 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
316 |
||
317 |
def _init_ctrls(self, prnt): |
|
318 |
# generated method, don't edit |
|
319 |
wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit', |
|
320 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
|
321 |
style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') |
|
322 |
self._init_utils() |
|
323 |
self.SetClientSize(wx.Size(1000, 700)) |
|
324 |
self.SetMenuBar(self.menuBar1) |
|
325 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_OBJDICTEDIT) |
|
326 |
||
327 |
self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED, |
|
328 |
name='FileOpened', parent=self, pos=wx.Point(0, 0), |
|
329 |
size=wx.Size(0, 0), style=0) |
|
330 |
self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
331 |
self.OnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED) |
|
332 |
||
333 |
self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar', |
|
334 |
parent=self, style=wxST_SIZEGRIP) |
|
335 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
|
336 |
self.SetStatusBar(self.HelpBar) |
|
337 |
||
338 |
def __init__(self, parent): |
|
339 |
self._init_ctrls(parent) |
|
340 |
self.HtmlFrameOpened = [] |
|
341 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
342 |
self.Manager = NodeManager(ScriptDirectory) |
0 | 343 |
for filepath in filesOpen: |
344 |
self.Manager.OpenFileInCurrent(filepath) |
|
345 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
346 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
347 |
self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) |
|
348 |
if self.Manager.CurrentDS302Defined(): |
|
349 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
350 |
else: |
|
351 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
|
352 |
self.RefreshEditMenu() |
|
353 |
self.RefreshBufferState() |
|
354 |
self.RefreshProfileMenu() |
|
355 |
self.RefreshTitle() |
|
356 |
self.RefreshMainMenu() |
|
357 |
||
358 |
def GetNoteBook(self): |
|
359 |
return self.FileOpened |
|
360 |
||
361 |
def OnAddSDOServerMenu(self, event): |
|
362 |
self.Manager.AddSDOServerToCurrent() |
|
363 |
self.RefreshBufferState() |
|
364 |
self.RefreshCurrentIndexList() |
|
365 |
event.Skip() |
|
366 |
||
367 |
def OnAddSDOClientMenu(self, event): |
|
368 |
self.Manager.AddSDOClientToCurrent() |
|
369 |
self.RefreshBufferState() |
|
370 |
self.RefreshCurrentIndexList() |
|
371 |
event.Skip() |
|
372 |
||
373 |
def OnAddPDOTransmitMenu(self, event): |
|
374 |
self.Manager.AddPDOTransmitToCurrent() |
|
375 |
self.RefreshBufferState() |
|
376 |
self.RefreshCurrentIndexList() |
|
377 |
event.Skip() |
|
378 |
||
379 |
def OnAddPDOReceiveMenu(self, event): |
|
380 |
self.Manager.AddPDOReceiveToCurrent() |
|
381 |
self.RefreshBufferState() |
|
382 |
self.RefreshCurrentIndexList() |
|
383 |
event.Skip() |
|
384 |
||
385 |
def OnAddMapVariableMenu(self, event): |
|
386 |
self.AddMapVariable() |
|
387 |
event.Skip() |
|
388 |
||
389 |
def OnAddUserTypeMenu(self, event): |
|
390 |
self.AddUserType() |
|
391 |
event.Skip() |
|
392 |
||
393 |
def OnFileSelectedChanged(self, event): |
|
43 | 394 |
selected = event.GetSelection() |
37 | 395 |
# At init selected = -1 |
396 |
if selected >= 0: |
|
205 | 397 |
window = self.FileOpened.GetPage(selected) |
398 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
399 |
self.RefreshBufferState() |
|
400 |
self.RefreshStatusBar() |
|
401 |
self.RefreshProfileMenu() |
|
0 | 402 |
event.Skip() |
403 |
||
404 |
def OnHelpDS301Menu(self, event): |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
405 |
find_index = False |
0 | 406 |
selected = self.FileOpened.GetSelection() |
407 |
if selected >= 0: |
|
408 |
window = self.FileOpened.GetPage(selected) |
|
409 |
result = window.GetSelection() |
|
410 |
if result: |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
411 |
find_index = True |
0 | 412 |
index, subIndex = result |
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
413 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
0 | 414 |
if type(result) == StringType: |
415 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
|
416 |
message.ShowModal() |
|
417 |
message.Destroy() |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
418 |
if not find_index: |
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
419 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
420 |
if type(result) == StringType: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
421 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
422 |
message.ShowModal() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
423 |
message.Destroy() |
0 | 424 |
event.Skip() |
425 |
||
426 |
def OnHelpCANFestivalMenu(self, event): |
|
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
427 |
#self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) |
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
428 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
0 | 429 |
event.Skip() |
430 |
||
431 |
def OnAboutMenu(self, event): |
|
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
432 |
self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
0 | 433 |
event.Skip() |
434 |
||
435 |
def OpenHtmlFrame(self, title, file, size): |
|
436 |
if title not in self.HtmlFrameOpened: |
|
437 |
self.HtmlFrameOpened.append(title) |
|
438 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
439 |
window.SetTitle(title) |
|
440 |
window.SetHtmlPage(file) |
|
441 |
window.SetClientSize(size) |
|
442 |
window.Show() |
|
443 |
||
444 |
def OnQuitMenu(self, event): |
|
445 |
self.Close() |
|
446 |
event.Skip() |
|
447 |
||
448 |
def OnCloseFrame(self, event): |
|
449 |
if self.Manager.OneFileHasChanged(): |
|
450 |
dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION) |
|
451 |
answer = dialog.ShowModal() |
|
452 |
dialog.Destroy() |
|
453 |
if answer == wxID_YES: |
|
454 |
self.Manager.ChangeCurrentNode(0) |
|
455 |
for i in xrange(self.FileOpened.GetPageCount()): |
|
456 |
if self.Manager.CurrentIsSaved(): |
|
457 |
self.Manager.CloseCurrent() |
|
458 |
else: |
|
459 |
self.Save() |
|
460 |
self.Manager.CloseCurrent(True) |
|
461 |
event.Skip() |
|
462 |
elif answer == wxID_NO: |
|
463 |
for i in xrange(self.FileOpened.GetPageCount()): |
|
464 |
self.Manager.CloseCurrent(True) |
|
465 |
wxCallAfter(self.Close) |
|
466 |
event.Skip() |
|
467 |
else: |
|
468 |
event.Skip() |
|
469 |
||
470 |
#------------------------------------------------------------------------------- |
|
471 |
# Refresh Functions |
|
472 |
#------------------------------------------------------------------------------- |
|
473 |
||
474 |
def RefreshTitle(self): |
|
475 |
if self.FileOpened.GetPageCount() > 0: |
|
476 |
self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename()) |
|
477 |
else: |
|
478 |
self.SetTitle("Objdictedit") |
|
479 |
||
480 |
def OnRefreshMenu(self, event): |
|
481 |
self.RefreshCurrentIndexList() |
|
482 |
event.Skip() |
|
483 |
||
484 |
def RefreshCurrentIndexList(self): |
|
485 |
selected = self.FileOpened.GetSelection() |
|
486 |
window = self.FileOpened.GetPage(selected) |
|
487 |
window.RefreshIndexList() |
|
488 |
||
489 |
def RefreshStatusBar(self): |
|
205 | 490 |
if self.HelpBar: |
491 |
window = self.FileOpened.GetPage(self.FileOpened.GetSelection()) |
|
492 |
selection = window.GetSelection() |
|
493 |
if selection: |
|
494 |
index, subIndex = selection |
|
495 |
if self.Manager.IsCurrentEntry(index): |
|
496 |
self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) |
|
497 |
self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) |
|
498 |
entryinfos = self.Manager.GetEntryInfos(index) |
|
499 |
name = entryinfos["name"] |
|
500 |
category = "Optional" |
|
501 |
if entryinfos["need"]: |
|
502 |
category = "Mandatory" |
|
503 |
struct = "VAR" |
|
504 |
number = "" |
|
505 |
if entryinfos["struct"] & OD_IdenticalIndexes: |
|
506 |
number = " possibly defined %d times"%entryinfos["nbmax"] |
|
507 |
if entryinfos["struct"] & OD_IdenticalSubindexes: |
|
508 |
struct = "REC" |
|
509 |
elif entryinfos["struct"] & OD_MultipleSubindexes: |
|
510 |
struct = "ARRAY" |
|
511 |
text = "%s: %s entry of struct %s%s."%(name,category,struct,number) |
|
512 |
self.HelpBar.SetStatusText(text, 2) |
|
513 |
else: |
|
514 |
for i in xrange(3): |
|
515 |
self.HelpBar.SetStatusText("", i) |
|
0 | 516 |
else: |
517 |
for i in xrange(3): |
|
518 |
self.HelpBar.SetStatusText("", i) |
|
519 |
||
520 |
def RefreshMainMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
521 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
522 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
523 |
self.menuBar1.EnableTop(1, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
524 |
self.menuBar1.EnableTop(2, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
525 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
526 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
527 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
528 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
529 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
530 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
531 |
self.menuBar1.EnableTop(1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
532 |
self.menuBar1.EnableTop(2, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
533 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
534 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
535 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
536 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
537 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, False) |
0 | 538 |
|
539 |
def RefreshEditMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
540 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
541 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
542 |
undo, redo = self.Manager.GetCurrentBufferState() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
543 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, undo) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
544 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, redo) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
545 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
546 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
547 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, False) |
0 | 548 |
|
549 |
def RefreshProfileMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
550 |
if self.EditMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
551 |
profile = self.Manager.GetCurrentProfileName() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
552 |
edititem = self.EditMenu.FindItemById(wxID_OBJDICTEDITEDITMENUITEMS7) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
553 |
if edititem: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
554 |
length = self.AddMenu.GetMenuItemCount() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
555 |
for i in xrange(length-6): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
556 |
additem = self.AddMenu.FindItemByPosition(6) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
557 |
self.AddMenu.Delete(additem.GetId()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
558 |
if profile not in ("None", "DS-301"): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
559 |
edititem.SetText("%s Profile"%profile) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
560 |
edititem.Enable(True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
561 |
self.AddMenu.AppendSeparator() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
562 |
for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
563 |
new_id = wx.NewId() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
564 |
self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
565 |
self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
566 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
567 |
edititem.SetText("Other Profile") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
568 |
edititem.Enable(False) |
0 | 569 |
|
570 |
||
571 |
#------------------------------------------------------------------------------- |
|
572 |
# Buffer Functions |
|
573 |
#------------------------------------------------------------------------------- |
|
574 |
||
575 |
def RefreshBufferState(self): |
|
576 |
fileopened = self.Manager.GetAllFilenames() |
|
577 |
for idx, filename in enumerate(fileopened): |
|
578 |
self.FileOpened.SetPageText(idx, filename) |
|
579 |
self.RefreshEditMenu() |
|
580 |
self.RefreshTitle() |
|
581 |
||
582 |
def OnUndoMenu(self, event): |
|
583 |
self.Manager.LoadCurrentPrevious() |
|
584 |
self.RefreshCurrentIndexList() |
|
585 |
self.RefreshBufferState() |
|
586 |
event.Skip() |
|
587 |
||
588 |
def OnRedoMenu(self, event): |
|
589 |
self.Manager.LoadCurrentNext() |
|
590 |
self.RefreshCurrentIndexList() |
|
591 |
self.RefreshBufferState() |
|
592 |
event.Skip() |
|
593 |
||
594 |
||
595 |
#------------------------------------------------------------------------------- |
|
596 |
# Load and Save Funtions |
|
597 |
#------------------------------------------------------------------------------- |
|
598 |
||
599 |
def OnNewMenu(self, event): |
|
600 |
self.FilePath = "" |
|
206 | 601 |
dialog = CreateNodeDialog(self, ScriptDirectory) |
0 | 602 |
if dialog.ShowModal() == wxID_OK: |
205 | 603 |
name, id, nodetype, description = dialog.GetValues() |
59 | 604 |
profile, filepath = dialog.GetProfile() |
605 |
NMT = dialog.GetNMTManagement() |
|
606 |
options = dialog.GetOptions() |
|
205 | 607 |
result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) |
608 |
if type(result) == IntType: |
|
59 | 609 |
new_editingpanel = EditingPanel(self, self.Manager) |
205 | 610 |
new_editingpanel.SetIndex(result) |
59 | 611 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 612 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
59 | 613 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
614 |
if "DS302" in options: |
|
615 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
616 |
self.RefreshBufferState() |
|
617 |
self.RefreshProfileMenu() |
|
618 |
self.RefreshMainMenu() |
|
0 | 619 |
else: |
59 | 620 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
0 | 621 |
message.ShowModal() |
622 |
message.Destroy() |
|
623 |
event.Skip() |
|
624 |
||
625 |
def OnOpenMenu(self, event): |
|
626 |
filepath = self.Manager.GetCurrentFilePath() |
|
627 |
if filepath != "": |
|
628 |
directory = os.path.dirname(filepath) |
|
629 |
else: |
|
630 |
directory = os.getcwd() |
|
59 | 631 |
dialog = wxFileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR) |
0 | 632 |
if dialog.ShowModal() == wxID_OK: |
633 |
filepath = dialog.GetPath() |
|
634 |
if os.path.isfile(filepath): |
|
635 |
result = self.Manager.OpenFileInCurrent(filepath) |
|
205 | 636 |
if type(result) == IntType: |
0 | 637 |
new_editingpanel = EditingPanel(self, self.Manager) |
205 | 638 |
new_editingpanel.SetIndex(result) |
0 | 639 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 640 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
0 | 641 |
if self.Manager.CurrentDS302Defined(): |
642 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
643 |
else: |
|
644 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
|
645 |
self.RefreshEditMenu() |
|
646 |
self.RefreshBufferState() |
|
647 |
self.RefreshProfileMenu() |
|
648 |
self.RefreshMainMenu() |
|
649 |
else: |
|
650 |
message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR) |
|
651 |
message.ShowModal() |
|
652 |
message.Destroy() |
|
653 |
dialog.Destroy() |
|
654 |
event.Skip() |
|
655 |
||
656 |
def OnSaveMenu(self, event): |
|
657 |
self.Save() |
|
658 |
event.Skip() |
|
659 |
||
660 |
def OnSaveAsMenu(self, event): |
|
661 |
self.SaveAs() |
|
30 | 662 |
event.Skip() |
0 | 663 |
|
664 |
def Save(self): |
|
665 |
result = self.Manager.SaveCurrentInFile() |
|
666 |
if not result: |
|
667 |
self.SaveAs() |
|
668 |
elif type(result) != StringType: |
|
669 |
self.RefreshBufferState() |
|
670 |
else: |
|
671 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
672 |
message.ShowModal() |
|
673 |
message.Destroy() |
|
674 |
||
675 |
def SaveAs(self): |
|
676 |
filepath = self.Manager.GetCurrentFilePath() |
|
677 |
if filepath != "": |
|
678 |
directory, filename = os.path.split(filepath) |
|
679 |
else: |
|
680 |
directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] |
|
59 | 681 |
dialog = wxFileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) |
0 | 682 |
if dialog.ShowModal() == wxID_OK: |
683 |
filepath = dialog.GetPath() |
|
684 |
if os.path.isdir(os.path.dirname(filepath)): |
|
685 |
result = self.Manager.SaveCurrentInFile(filepath) |
|
686 |
if type(result) != StringType: |
|
687 |
self.RefreshBufferState() |
|
688 |
else: |
|
689 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
690 |
message.ShowModal() |
|
691 |
message.Destroy() |
|
692 |
else: |
|
693 |
message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
|
694 |
message.ShowModal() |
|
695 |
message.Destroy() |
|
696 |
dialog.Destroy() |
|
697 |
||
698 |
def OnCloseMenu(self, event): |
|
699 |
answer = wxID_YES |
|
700 |
result = self.Manager.CloseCurrent() |
|
701 |
if not result: |
|
702 |
dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION) |
|
703 |
answer = dialog.ShowModal() |
|
704 |
dialog.Destroy() |
|
705 |
if answer == wxID_YES: |
|
706 |
self.OnSaveMenu(event) |
|
707 |
if self.Manager.CurrentIsSaved(): |
|
708 |
self.Manager.CloseCurrent() |
|
709 |
elif answer == wxID_NO: |
|
710 |
self.Manager.CloseCurrent(True) |
|
711 |
if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): |
|
712 |
current = self.FileOpened.GetSelection() |
|
713 |
self.FileOpened.DeletePage(current) |
|
714 |
if self.FileOpened.GetPageCount() > 0: |
|
715 |
self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) |
|
716 |
self.RefreshBufferState() |
|
717 |
self.RefreshMainMenu() |
|
718 |
event.Skip() |
|
719 |
||
720 |
||
721 |
#------------------------------------------------------------------------------- |
|
722 |
# Import and Export Functions |
|
723 |
#------------------------------------------------------------------------------- |
|
724 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
725 |
def OnImportEDSMenu(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
726 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR) |
0 | 727 |
if dialog.ShowModal() == wxID_OK: |
728 |
filepath = dialog.GetPath() |
|
729 |
if os.path.isfile(filepath): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
730 |
result = self.Manager.ImportCurrentFromEDSFile(filepath) |
205 | 731 |
if type(result) == IntType: |
732 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
733 |
new_editingpanel.SetIndex(result) |
|
734 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
735 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
|
0 | 736 |
self.RefreshBufferState() |
737 |
self.RefreshCurrentIndexList() |
|
738 |
self.RefreshProfileMenu() |
|
739 |
self.RefreshMainMenu() |
|
740 |
message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION) |
|
741 |
message.ShowModal() |
|
742 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
743 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
744 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
745 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
746 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
747 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
748 |
message = wxMessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
749 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
750 |
message.Destroy() |
0 | 751 |
dialog.Destroy() |
752 |
event.Skip() |
|
753 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
754 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
755 |
def OnExportEDSMenu(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
756 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "EDS files (*.eds)|*.eds|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
757 |
if dialog.ShowModal() == wxID_OK: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
758 |
filepath = dialog.GetPath() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
759 |
if os.path.isdir(os.path.dirname(filepath)): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
760 |
path, extend = os.path.splitext(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
761 |
if extend in ("", "."): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
762 |
filepath = path + ".eds" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
763 |
result = self.Manager.ExportCurrentToEDSFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
764 |
if not result: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
765 |
message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
766 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
767 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
768 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
769 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
770 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
771 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
772 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
773 |
message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
774 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
775 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
776 |
dialog.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
777 |
event.Skip() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
778 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
779 |
def OnExportCMenu(self, event): |
59 | 780 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) |
0 | 781 |
if dialog.ShowModal() == wxID_OK: |
782 |
filepath = dialog.GetPath() |
|
783 |
if os.path.isdir(os.path.dirname(filepath)): |
|
784 |
path, extend = os.path.splitext(filepath) |
|
785 |
if extend in ("", "."): |
|
786 |
filepath = path + ".c" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
787 |
result = self.Manager.ExportCurrentToCFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
788 |
if not result: |
0 | 789 |
message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) |
790 |
message.ShowModal() |
|
791 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
792 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
793 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
794 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
795 |
message.Destroy() |
0 | 796 |
else: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
797 |
message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
0 | 798 |
message.ShowModal() |
799 |
message.Destroy() |
|
800 |
dialog.Destroy() |
|
801 |
event.Skip() |
|
802 |
||
803 |
#------------------------------------------------------------------------------- |
|
804 |
# Editing Profiles functions |
|
805 |
#------------------------------------------------------------------------------- |
|
806 |
||
807 |
def OnCommunicationMenu(self, event): |
|
808 |
dictionary,current = self.Manager.GetCurrentCommunicationLists() |
|
809 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
810 |
event.Skip() |
|
811 |
||
812 |
def OnOtherCommunicationMenu(self, event): |
|
813 |
dictionary,current = self.Manager.GetCurrentDS302Lists() |
|
814 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
815 |
event.Skip() |
|
816 |
||
817 |
def OnEditProfileMenu(self, event): |
|
818 |
title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() |
|
819 |
dictionary,current = self.Manager.GetCurrentProfileLists() |
|
820 |
self.EditProfile(title, dictionary, current) |
|
821 |
event.Skip() |
|
822 |
||
823 |
def EditProfile(self, title, dictionary, current): |
|
824 |
dialog = CommunicationDialog(self) |
|
825 |
dialog.SetTitle(title) |
|
826 |
dialog.SetIndexDictionary(dictionary) |
|
827 |
dialog.SetCurrentList(current) |
|
828 |
dialog.RefreshLists() |
|
829 |
if dialog.ShowModal() == wxID_OK: |
|
830 |
new_profile = dialog.GetCurrentList() |
|
831 |
addinglist = [] |
|
832 |
removinglist = [] |
|
833 |
for index in new_profile: |
|
834 |
if index not in current: |
|
835 |
addinglist.append(index) |
|
836 |
for index in current: |
|
837 |
if index not in new_profile: |
|
838 |
removinglist.append(index) |
|
839 |
self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) |
|
840 |
self.Manager.GenerateMapList() |
|
841 |
self.Manager.BufferCurrentNode() |
|
842 |
self.RefreshBufferState() |
|
843 |
self.RefreshCurrentIndexList() |
|
844 |
dialog.Destroy() |
|
845 |
||
846 |
def GetProfileCallBack(self, text): |
|
847 |
def ProfileCallBack(event): |
|
848 |
self.Manager.AddSpecificEntryToCurrent(text) |
|
849 |
self.RefreshBufferState() |
|
850 |
self.RefreshCurrentIndexList() |
|
851 |
event.Skip() |
|
852 |
return ProfileCallBack |
|
853 |
||
854 |
#------------------------------------------------------------------------------- |
|
855 |
# Edit Node informations function |
|
856 |
#------------------------------------------------------------------------------- |
|
857 |
||
858 |
def OnNodeInfosMenu(self, event): |
|
859 |
dialog = NodeInfosDialog(self) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
860 |
name, id, type, description = self.Manager.GetCurrentNodeInfos() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
861 |
dialog.SetValues(name, id, type, description) |
0 | 862 |
if dialog.ShowModal() == wxID_OK: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
863 |
name, id, type, description = dialog.GetValues() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
864 |
self.Manager.SetCurrentNodeInfos(name, id, type, description) |
0 | 865 |
self.RefreshBufferState() |
866 |
self.RefreshProfileMenu() |
|
205 | 867 |
selected = self.FileOpened.GetSelection() |
868 |
if selected >= 0: |
|
869 |
window = self.FileOpened.GetPage(selected) |
|
870 |
window.RefreshTable() |
|
0 | 871 |
event.Skip() |
872 |
||
873 |
||
874 |
#------------------------------------------------------------------------------- |
|
875 |
# Add User Types and Variables |
|
876 |
#------------------------------------------------------------------------------- |
|
877 |
||
878 |
def AddMapVariable(self): |
|
39 | 879 |
index = self.Manager.GetCurrentNextMapIndex() |
880 |
if index: |
|
881 |
dialog = MapVariableDialog(self) |
|
882 |
dialog.SetIndex(index) |
|
883 |
if dialog.ShowModal() == wxID_OK: |
|
884 |
index, name, struct, number = dialog.GetValues() |
|
885 |
result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) |
|
886 |
if type(result) != StringType: |
|
887 |
self.RefreshBufferState() |
|
888 |
self.RefreshCurrentIndexList() |
|
889 |
else: |
|
890 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
891 |
message.ShowModal() |
|
892 |
message.Destroy() |
|
893 |
dialog.Destroy() |
|
894 |
else: |
|
895 |
message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR) |
|
896 |
message.ShowModal() |
|
897 |
message.Destroy() |
|
0 | 898 |
|
899 |
def AddUserType(self): |
|
900 |
dialog = UserTypeDialog(self) |
|
901 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
|
902 |
if dialog.ShowModal() == wxID_OK: |
|
903 |
type, min, max, length = dialog.GetValues() |
|
904 |
result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
|
205 | 905 |
if not result: |
0 | 906 |
self.RefreshBufferState() |
907 |
self.RefreshCurrentIndexList() |
|
908 |
else: |
|
909 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
910 |
message.ShowModal() |
|
911 |
message.Destroy() |
|
912 |
dialog.Destroy() |
|
913 |
||
914 |
||
915 |
#------------------------------------------------------------------------------- |
|
916 |
# Exception Handler |
|
917 |
#------------------------------------------------------------------------------- |
|
918 |
||
919 |
Max_Traceback_List_Size = 20 |
|
920 |
||
921 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
922 |
trcbck_lst = [] |
|
923 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
924 |
trcbck = " " + str(i+1) + ". " |
|
925 |
if line[0].find(os.getcwd()) == -1: |
|
926 |
trcbck += "file : " + str(line[0]) + ", " |
|
927 |
else: |
|
928 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
929 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
930 |
trcbck_lst.append(trcbck) |
|
931 |
||
932 |
# Allow clicking.... |
|
933 |
cap = wx.Window_GetCapture() |
|
934 |
if cap: |
|
935 |
cap.ReleaseMouse() |
|
936 |
||
937 |
dlg = wx.SingleChoiceDialog(None, |
|
938 |
""" |
|
939 |
An error happens. |
|
940 |
||
941 |
Click on OK for saving an error report. |
|
942 |
||
943 |
Please contact LOLITech at: |
|
944 |
+33 (0)3 29 52 95 67 |
|
945 |
bugs_objdictedit@lolitech.fr |
|
946 |
||
947 |
||
948 |
Error: |
|
949 |
""" + |
|
950 |
str(e_type) + " : " + str(e_value), |
|
951 |
"Error", |
|
952 |
trcbck_lst) |
|
953 |
try: |
|
954 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
955 |
finally: |
|
956 |
dlg.Destroy() |
|
957 |
||
958 |
return res |
|
959 |
||
960 |
def Display_Error_Dialog(e_value): |
|
961 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
962 |
message.ShowModal() |
|
963 |
message.Destroy() |
|
964 |
||
965 |
def get_last_traceback(tb): |
|
966 |
while tb.tb_next: |
|
967 |
tb = tb.tb_next |
|
968 |
return tb |
|
969 |
||
970 |
||
971 |
def format_namespace(d, indent=' '): |
|
972 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
973 |
||
974 |
||
975 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
976 |
||
977 |
def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
|
978 |
||
979 |
def handle_exception(e_type, e_value, e_traceback): |
|
980 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
981 |
last_tb = get_last_traceback(e_traceback) |
|
982 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
983 |
if str(e_value).startswith("!!!"): |
|
984 |
Display_Error_Dialog(e_value) |
|
985 |
elif ex not in ignored_exceptions: |
|
986 |
ignored_exceptions.append(ex) |
|
987 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
988 |
if result: |
|
989 |
info = { |
|
990 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
991 |
'app-version' : app_version, |
|
992 |
'wx-version' : wx.VERSION_STRING, |
|
993 |
'wx-platform' : wx.Platform, |
|
994 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
995 |
'platform' : platform.platform(), |
|
996 |
'e-type' : e_type, |
|
997 |
'e-value' : e_value, |
|
998 |
'date' : time.ctime(), |
|
999 |
'cwd' : os.getcwd(), |
|
1000 |
} |
|
1001 |
if e_traceback: |
|
1002 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
1003 |
last_tb = get_last_traceback(e_traceback) |
|
1004 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
1005 |
info['locals'] = format_namespace(exception_locals) |
|
1006 |
if 'self' in exception_locals: |
|
1007 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1008 |
||
1009 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
1010 |
lst = info.keys() |
|
1011 |
lst.sort() |
|
1012 |
for a in lst: |
|
1013 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
1014 |
||
1015 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
1016 |
sys.excepthook = handle_exception |
|
1017 |
||
1018 |
if __name__ == '__main__': |
|
1019 |
app = wxPySimpleApp() |
|
1020 |
wxInitAllImageHandlers() |
|
1021 |
||
1022 |
# Install a exception handle for bug reports |
|
1023 |
wxAddExceptHook(os.getcwd(),__version__) |
|
1024 |
||
1025 |
frame = objdictedit(None) |
|
1026 |
||
1027 |
frame.Show() |
|
1028 |
app.MainLoop() |