author | greg |
Thu, 10 May 2007 09:33:07 +0200 | |
changeset 183 | 4cddad17c81f |
parent 182 | 988f2b302aa6 |
child 205 | dac0f9b4e3f8 |
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 |
from wx.lib.anchors import LayoutAnchors |
|
28 |
import wx.grid |
|
29 |
||
30 |
from types import * |
|
31 |
import os, re, platform, sys, time, traceback, getopt |
|
32 |
||
33 |
__version__ = "$Revision$" |
|
34 |
||
35 |
from nodemanager import * |
|
36 |
from node import OD_Subindex,OD_MultipleSubindexes,OD_IdenticalSubindexes,OD_IdenticalIndexes |
|
37 |
from doc_index.DS301_index import * |
|
38 |
||
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
39 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
40 |
from wxPython.html import * |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
41 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
42 |
wxEVT_HTML_URL_CLICK = wxNewId() |
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 |
def EVT_HTML_URL_CLICK(win, func): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
45 |
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
|
46 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
47 |
class wxHtmlWindowUrlClick(wxPyEvent): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
48 |
def __init__(self, linkinfo): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
49 |
wxPyEvent.__init__(self) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
50 |
self.SetEventType(wxEVT_HTML_URL_CLICK) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
51 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
52 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
53 |
class wxUrlClickHtmlWindow(wxHtmlWindow): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
54 |
""" HTML window that generates and OnLinkClicked event. |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
55 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
56 |
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
|
57 |
""" |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
58 |
def OnLinkClicked(self, linkinfo): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
59 |
wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo)) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
60 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
61 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
62 |
# Html Frame |
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 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
65 |
[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
|
66 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
67 |
class HtmlFrame(wx.Frame): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
68 |
def _init_ctrls(self, prnt): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
69 |
# generated method, don't edit |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
70 |
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
|
71 |
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
|
72 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
73 |
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
|
74 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
75 |
self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
80 |
def __init__(self, parent, opened): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
81 |
self._init_ctrls(parent) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
82 |
self.HtmlFrameOpened = opened |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
83 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
84 |
def SetHtmlCode(self, htmlcode): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
85 |
self.HtmlContent.SetPage(htmlcode) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
86 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
87 |
def SetHtmlPage(self, htmlpage): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
88 |
self.HtmlContent.LoadPage(htmlpage) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
89 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
90 |
def OnCloseFrame(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
91 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
92 |
event.Skip() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
93 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
94 |
def OnLinkClick(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
95 |
url = event.linkinfo[0] |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
96 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
97 |
import webbrowser |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
98 |
except ImportError: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
99 |
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
|
100 |
else: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
101 |
webbrowser.open(url) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
102 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
103 |
Html_Window = True |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
104 |
except: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
105 |
Html_Window = False |
0 | 106 |
|
107 |
def create(parent): |
|
108 |
return objdictedit(parent) |
|
109 |
||
110 |
def usage(): |
|
111 |
print "\nUsage of objectdict.py :" |
|
112 |
print "\n %s [Filepath, ...]\n"%sys.argv[0] |
|
113 |
||
114 |
try: |
|
115 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
116 |
except getopt.GetoptError: |
|
117 |
# print help information and exit: |
|
118 |
usage() |
|
119 |
sys.exit(2) |
|
120 |
||
121 |
for o, a in opts: |
|
122 |
if o in ("-h", "--help"): |
|
123 |
usage() |
|
124 |
sys.exit() |
|
125 |
||
126 |
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
|
127 |
ScriptDirectory = sys.path[0] |
0 | 128 |
|
129 |
ColSizes = [75, 250, 150, 125, 100, 60, 250] |
|
130 |
ColAlignements = [wxALIGN_CENTER, wxALIGN_LEFT, wxALIGN_CENTER, wxALIGN_RIGHT, wxALIGN_CENTER, wxALIGN_CENTER, wxALIGN_LEFT] |
|
131 |
AccessList = "Read Only,Write Only,Read/Write" |
|
68
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
132 |
RAccessList = "Read Only,Read/Write" |
0 | 133 |
BoolList = "True,False" |
134 |
OptionList = "Yes,No" |
|
135 |
||
136 |
DictionaryOrganisation = [ |
|
137 |
{"minIndex" : 0x0001, "maxIndex" : 0x0FFF, "name" : "Data Type Definitions"}, |
|
138 |
{"minIndex" : 0x1000, "maxIndex" : 0x1029, "name" : "Communication Parameters"}, |
|
139 |
{"minIndex" : 0x1200, "maxIndex" : 0x12FF, "name" : "SDO Parameters"}, |
|
140 |
{"minIndex" : 0x1400, "maxIndex" : 0x15FF, "name" : "Receive PDO Parameters"}, |
|
141 |
{"minIndex" : 0x1600, "maxIndex" : 0x17FF, "name" : "Receive PDO Mapping"}, |
|
142 |
{"minIndex" : 0x1800, "maxIndex" : 0x19FF, "name" : "Transmit PDO Parameters"}, |
|
143 |
{"minIndex" : 0x1A00, "maxIndex" : 0x1BFF, "name" : "Transmit PDO Mapping"}, |
|
144 |
{"minIndex" : 0x1C00, "maxIndex" : 0x1FFF, "name" : "Other Communication Parameters"}, |
|
145 |
{"minIndex" : 0x2000, "maxIndex" : 0x5FFF, "name" : "Manufacturer Specific"}, |
|
146 |
{"minIndex" : 0x6000, "maxIndex" : 0x9FFF, "name" : "Standardized Device Profile"}, |
|
147 |
{"minIndex" : 0xA000, "maxIndex" : 0xBFFF, "name" : "Standardized Interface Profile"}] |
|
148 |
||
149 |
class SubindexTable(wxPyGridTableBase): |
|
150 |
||
151 |
""" |
|
152 |
A custom wxGrid Table using user supplied data |
|
153 |
""" |
|
154 |
def __init__(self, parent, data, editors, colnames): |
|
155 |
# The base class must be initialized *first* |
|
156 |
wxPyGridTableBase.__init__(self) |
|
157 |
self.data = data |
|
158 |
self.editors = editors |
|
159 |
self.CurrentIndex = 0 |
|
160 |
self.colnames = colnames |
|
161 |
self.Parent = parent |
|
162 |
# XXX |
|
163 |
# we need to store the row length and collength to |
|
164 |
# see if the table has changed size |
|
165 |
self._rows = self.GetNumberRows() |
|
166 |
self._cols = self.GetNumberCols() |
|
167 |
||
168 |
def GetNumberCols(self): |
|
169 |
return len(self.colnames) |
|
170 |
||
171 |
def GetNumberRows(self): |
|
172 |
return len(self.data) |
|
173 |
||
174 |
def GetColLabelValue(self, col): |
|
175 |
if col < len(self.colnames): |
|
176 |
return self.colnames[col] |
|
177 |
||
178 |
def GetRowLabelValues(self, row): |
|
179 |
return row |
|
180 |
||
181 |
def GetValue(self, row, col): |
|
182 |
if row < self.GetNumberRows(): |
|
63
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
59
diff
changeset
|
183 |
value = self.data[row].get(self.GetColLabelValue(col), "") |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
59
diff
changeset
|
184 |
if (type(value) == UnicodeType): |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
59
diff
changeset
|
185 |
return value |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
59
diff
changeset
|
186 |
else: |
2be18e405e40
Bug on map variable type changing and on comments with special characters corrected
lbessard
parents:
59
diff
changeset
|
187 |
return str(value) |
0 | 188 |
|
189 |
def GetEditor(self, row, col): |
|
190 |
if row < self.GetNumberRows(): |
|
191 |
return self.editors[row].get(self.GetColLabelValue(col), "") |
|
192 |
||
193 |
def GetValueByName(self, row, colname): |
|
194 |
return self.data[row].get(colname) |
|
195 |
||
196 |
def SetValue(self, row, col, value): |
|
197 |
if col < len(self.colnames): |
|
198 |
self.data[row][self.GetColLabelValue(col)] = value |
|
199 |
||
200 |
def ResetView(self, grid): |
|
201 |
""" |
|
202 |
(wxGrid) -> Reset the grid view. Call this to |
|
203 |
update the grid if rows and columns have been added or deleted |
|
204 |
""" |
|
205 |
grid.BeginBatch() |
|
206 |
for current, new, delmsg, addmsg in [ |
|
207 |
(self._rows, self.GetNumberRows(), wxGRIDTABLE_NOTIFY_ROWS_DELETED, wxGRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
208 |
(self._cols, self.GetNumberCols(), wxGRIDTABLE_NOTIFY_COLS_DELETED, wxGRIDTABLE_NOTIFY_COLS_APPENDED), |
|
209 |
]: |
|
210 |
if new < current: |
|
211 |
msg = wxGridTableMessage(self,delmsg,new,current-new) |
|
212 |
grid.ProcessTableMessage(msg) |
|
213 |
elif new > current: |
|
214 |
msg = wxGridTableMessage(self,addmsg,new-current) |
|
215 |
grid.ProcessTableMessage(msg) |
|
216 |
self.UpdateValues(grid) |
|
217 |
grid.EndBatch() |
|
218 |
||
219 |
self._rows = self.GetNumberRows() |
|
220 |
self._cols = self.GetNumberCols() |
|
221 |
# update the column rendering scheme |
|
222 |
self._updateColAttrs(grid) |
|
223 |
||
224 |
# update the scrollbars and the displayed part of the grid |
|
225 |
grid.AdjustScrollbars() |
|
226 |
grid.ForceRefresh() |
|
227 |
||
228 |
||
229 |
def UpdateValues(self, grid): |
|
230 |
"""Update all displayed values""" |
|
231 |
# This sends an event to the grid table to update all of the values |
|
232 |
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
233 |
grid.ProcessTableMessage(msg) |
|
234 |
||
235 |
def _updateColAttrs(self, grid): |
|
236 |
""" |
|
237 |
wxGrid -> update the column attributes to add the |
|
238 |
appropriate renderer given the column name. |
|
239 |
||
240 |
Otherwise default to the default renderer. |
|
241 |
""" |
|
242 |
||
243 |
for col in range(self.GetNumberCols()): |
|
244 |
attr = wxGridCellAttr() |
|
245 |
attr.SetAlignment(ColAlignements[col], wxALIGN_CENTRE) |
|
246 |
grid.SetColAttr(col, attr) |
|
247 |
grid.SetColSize(col, ColSizes[col]) |
|
248 |
||
249 |
typelist = None |
|
250 |
accesslist = None |
|
251 |
for row in range(self.GetNumberRows()): |
|
252 |
editors = self.editors[row] |
|
253 |
for col in range(self.GetNumberCols()): |
|
254 |
editor = None |
|
255 |
renderer = None |
|
256 |
||
257 |
colname = self.GetColLabelValue(col) |
|
258 |
editortype = editors[colname] |
|
259 |
if editortype: |
|
260 |
grid.SetReadOnly(row, col, False) |
|
261 |
if editortype == "string": |
|
262 |
editor = wxGridCellTextEditor() |
|
263 |
renderer = wxGridCellStringRenderer() |
|
264 |
if colname == "value" and "length" in editors: |
|
265 |
editor.SetParameters(editors["length"]) |
|
266 |
elif editortype == "number": |
|
267 |
editor = wxGridCellNumberEditor() |
|
268 |
renderer = wxGridCellNumberRenderer() |
|
269 |
if colname == "value" and "min" in editors and "max" in editors: |
|
270 |
editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
271 |
elif editortype == "real": |
|
272 |
editor = wxGridCellFloatEditor() |
|
273 |
renderer = wxGridCellFloatRenderer() |
|
274 |
if colname == "value" and "min" in editors and "max" in editors: |
|
275 |
editor.SetParameters("%s,%s"%(editors["min"],editors["max"])) |
|
276 |
elif editortype == "bool": |
|
277 |
editor = wxGridCellChoiceEditor() |
|
278 |
editor.SetParameters(BoolList) |
|
279 |
elif editortype == "access": |
|
280 |
editor = wxGridCellChoiceEditor() |
|
281 |
editor.SetParameters(AccessList) |
|
68
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
282 |
elif editortype == "raccess": |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
283 |
editor = wxGridCellChoiceEditor() |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
284 |
editor.SetParameters(RAccessList) |
0 | 285 |
elif editortype == "option": |
286 |
editor = wxGridCellChoiceEditor() |
|
287 |
editor.SetParameters(OptionList) |
|
288 |
elif editortype == "type": |
|
289 |
editor = wxGridCellChoiceEditor() |
|
290 |
editor.SetParameters(self.Parent.Manager.GetCurrentTypeList()) |
|
291 |
elif editortype == "map": |
|
292 |
editor = wxGridCellChoiceEditor() |
|
293 |
editor.SetParameters(self.Parent.Manager.GetCurrentMapList()) |
|
68
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
294 |
elif editortype == "time": |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
295 |
editor = wxGridCellTextEditor() |
234dad27b398
Adding the possibility for users to choose between Dynamic Mapping and Static Mapping
lbessard
parents:
63
diff
changeset
|
296 |
renderer = wxGridCellStringRenderer() |
176 | 297 |
elif editortype == "domain": |
298 |
editor = wxGridCellTextEditor() |
|
299 |
renderer = wxGridCellStringRenderer() |
|
0 | 300 |
else: |
301 |
grid.SetReadOnly(row, col, True) |
|
302 |
||
303 |
grid.SetCellEditor(row, col, editor) |
|
304 |
grid.SetCellRenderer(row, col, renderer) |
|
305 |
||
306 |
grid.SetCellBackgroundColour(row, col, wxWHITE) |
|
307 |
||
308 |
def SetData(self, data): |
|
309 |
self.data = data |
|
310 |
||
311 |
def SetEditors(self, editors): |
|
312 |
self.editors = editors |
|
313 |
||
314 |
def GetCurrentIndex(self): |
|
315 |
return self.CurrentIndex |
|
316 |
||
317 |
def SetCurrentIndex(self, index): |
|
318 |
self.CurrentIndex = index |
|
319 |
||
320 |
def AppendRow(self, row_content): |
|
321 |
self.data.append(row_content) |
|
322 |
||
323 |
def Empty(self): |
|
324 |
self.data = [] |
|
325 |
self.editors = [] |
|
326 |
||
327 |
[wxID_EDITINGPANEL, wxID_EDITINGPANELADDBUTTON, wxID_EDITINGPANELINDEXCHOICE, |
|
328 |
wxID_EDITINGPANELINDEXLIST, wxID_EDITINGPANELINDEXLISTPANEL, wxID_EDITINGPANELPARTLIST, |
|
329 |
wxID_EDITINGPANELSECONDSPLITTER, wxID_EDITINGPANELSUBINDEXGRID, |
|
330 |
wxID_EDITINGPANELSUBINDEXGRIDPANEL, wxID_EDITINGPANELCALLBACKCHECK, |
|
331 |
] = [wx.NewId() for _init_ctrls in range(10)] |
|
332 |
||
333 |
[wxID_EDITINGPANELINDEXLISTMENUITEMS0, wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
334 |
wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
335 |
] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)] |
|
336 |
||
337 |
[wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, |
|
338 |
] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)] |
|
339 |
||
340 |
class EditingPanel(wx.SplitterWindow): |
|
341 |
def _init_coll_AddToListSizer_Items(self, parent): |
|
342 |
# generated method, don't edit |
|
343 |
||
344 |
parent.AddWindow(self.AddButton, 0, border=0, flag=0) |
|
345 |
parent.AddWindow(self.IndexChoice, 0, border=0, flag=wxGROW) |
|
346 |
||
347 |
def _init_coll_SubindexGridSizer_Items(self, parent): |
|
348 |
# generated method, don't edit |
|
349 |
||
350 |
parent.AddWindow(self.CallbackCheck, 0, border=0, flag=0) |
|
351 |
parent.AddWindow(self.SubindexGrid, 0, border=0, flag=wxGROW) |
|
352 |
||
353 |
def _init_coll_IndexListSizer_Items(self, parent): |
|
354 |
# generated method, don't edit |
|
355 |
||
356 |
parent.AddWindow(self.IndexList, 0, border=0, flag=wxGROW) |
|
357 |
parent.AddSizer(self.AddToListSizer, 0, border=0, flag=wxGROW) |
|
358 |
||
359 |
def _init_coll_AddToListSizer_Growables(self, parent): |
|
360 |
# generated method, don't edit |
|
361 |
||
362 |
parent.AddGrowableCol(1) |
|
363 |
||
364 |
def _init_coll_SubindexGridSizer_Growables(self, parent): |
|
365 |
# generated method, don't edit |
|
366 |
||
367 |
parent.AddGrowableCol(0) |
|
368 |
parent.AddGrowableRow(1) |
|
369 |
||
370 |
def _init_coll_IndexListSizer_Growables(self, parent): |
|
371 |
# generated method, don't edit |
|
372 |
||
373 |
parent.AddGrowableCol(0) |
|
374 |
parent.AddGrowableRow(0) |
|
375 |
||
376 |
def _init_coll_SubindexGridMenu_Items(self, parent): |
|
377 |
# generated method, don't edit |
|
378 |
||
379 |
parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS0, |
|
380 |
kind=wx.ITEM_NORMAL, text='Add') |
|
381 |
parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1, |
|
382 |
kind=wx.ITEM_NORMAL, text='Delete') |
|
383 |
self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu, |
|
384 |
id=wxID_EDITINGPANELMENU1ITEMS0) |
|
385 |
self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu, |
|
386 |
id=wxID_EDITINGPANELMENU1ITEMS1) |
|
387 |
||
388 |
def _init_coll_IndexListMenu_Items(self, parent): |
|
389 |
# generated method, don't edit |
|
390 |
||
391 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS0, |
|
392 |
kind=wx.ITEM_NORMAL, text='Rename') |
|
393 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS2, |
|
394 |
kind=wx.ITEM_NORMAL, text='Modify') |
|
395 |
parent.Append(help='', id=wxID_EDITINGPANELINDEXLISTMENUITEMS1, |
|
396 |
kind=wx.ITEM_NORMAL, text='Delete') |
|
397 |
self.Bind(wx.EVT_MENU, self.OnRenameIndexMenu, |
|
398 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS0) |
|
399 |
self.Bind(wx.EVT_MENU, self.OnDeleteIndexMenu, |
|
400 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS1) |
|
401 |
self.Bind(wx.EVT_MENU, self.OnModifyIndexMenu, |
|
402 |
id=wxID_EDITINGPANELINDEXLISTMENUITEMS2) |
|
403 |
||
404 |
def _init_utils(self): |
|
405 |
# generated method, don't edit |
|
406 |
self.IndexListMenu = wx.Menu(title='') |
|
407 |
||
408 |
self.SubindexGridMenu = wx.Menu(title='') |
|
409 |
||
410 |
self._init_coll_IndexListMenu_Items(self.IndexListMenu) |
|
411 |
self._init_coll_SubindexGridMenu_Items(self.SubindexGridMenu) |
|
412 |
||
413 |
def _init_sizers(self): |
|
414 |
# generated method, don't edit |
|
415 |
self.IndexListSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
416 |
||
417 |
self.SubindexGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
418 |
||
419 |
self.AddToListSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
|
420 |
||
421 |
self._init_coll_IndexListSizer_Growables(self.IndexListSizer) |
|
422 |
self._init_coll_IndexListSizer_Items(self.IndexListSizer) |
|
423 |
self._init_coll_SubindexGridSizer_Growables(self.SubindexGridSizer) |
|
424 |
self._init_coll_SubindexGridSizer_Items(self.SubindexGridSizer) |
|
425 |
self._init_coll_AddToListSizer_Growables(self.AddToListSizer) |
|
426 |
self._init_coll_AddToListSizer_Items(self.AddToListSizer) |
|
427 |
||
428 |
self.SubindexGridPanel.SetSizer(self.SubindexGridSizer) |
|
429 |
self.IndexListPanel.SetSizer(self.IndexListSizer) |
|
430 |
||
431 |
def _init_ctrls(self, prnt): |
|
432 |
wx.SplitterWindow.__init__(self, id=wxID_EDITINGPANEL, |
|
433 |
name='MainSplitter', parent=prnt, point=wx.Point(0, 0), |
|
434 |
size=wx.Size(-1, -1), style=wx.SP_3D) |
|
435 |
self._init_utils() |
|
436 |
self.SetNeedUpdating(True) |
|
437 |
self.SetMinimumPaneSize(1) |
|
438 |
||
439 |
self.PartList = wx.ListBox(choices=[], id=wxID_EDITINGPANELPARTLIST, |
|
440 |
name='PartList', parent=self, pos=wx.Point(0, 0), |
|
441 |
size=wx.Size(-1, -1), style=0) |
|
442 |
self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick, |
|
443 |
id=wxID_EDITINGPANELPARTLIST) |
|
444 |
||
445 |
self.SecondSplitter = wx.SplitterWindow(id=wxID_EDITINGPANELSECONDSPLITTER, |
|
446 |
name='SecondSplitter', parent=self, point=wx.Point(0, |
|
447 |
0), size=wx.Size(-1, -1), style=wx.SP_3D) |
|
448 |
self.SecondSplitter.SetMinimumPaneSize(1) |
|
449 |
self.SplitHorizontally(self.PartList, self.SecondSplitter, |
|
450 |
110) |
|
451 |
||
452 |
self.SubindexGridPanel = wx.Panel(id=wxID_EDITINGPANELSUBINDEXGRIDPANEL, |
|
453 |
name='SubindexGridPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
454 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
455 |
||
456 |
self.IndexListPanel = wx.Panel(id=wxID_EDITINGPANELINDEXLISTPANEL, |
|
457 |
name='IndexListPanel', parent=self.SecondSplitter, pos=wx.Point(0, |
|
458 |
0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL) |
|
459 |
self.SecondSplitter.SplitVertically(self.IndexListPanel, |
|
460 |
self.SubindexGridPanel, 280) |
|
461 |
||
462 |
self.SubindexGrid = wx.grid.Grid(id=wxID_EDITINGPANELSUBINDEXGRID, |
|
463 |
name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0, |
|
464 |
0), size=wx.Size(-1, -1), style=0) |
|
465 |
self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
|
466 |
'Sans')) |
|
467 |
self.SubindexGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
|
468 |
False, 'Sans')) |
|
469 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, |
|
470 |
self.OnSubindexGridCellChange) |
|
471 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, |
|
472 |
self.OnSubindexGridRightClick) |
|
473 |
self.SubindexGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, |
|
474 |
self.OnSubindexGridSelectCell) |
|
475 |
||
476 |
self.CallbackCheck = wx.CheckBox(id=wxID_EDITINGPANELCALLBACKCHECK, |
|
477 |
label='Have Callbacks', name='CallbackCheck', |
|
478 |
parent=self.SubindexGridPanel, pos=wx.Point(0, 0), size=wx.Size(152, |
|
479 |
24), style=0) |
|
480 |
self.CallbackCheck.Bind(wx.EVT_CHECKBOX, self.OnCallbackCheck, |
|
481 |
id=wxID_EDITINGPANELCALLBACKCHECK) |
|
482 |
||
483 |
self.IndexList = wx.ListBox(choices=[], id=wxID_EDITINGPANELINDEXLIST, |
|
484 |
name='IndexList', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
485 |
size=wx.Size(-1, -1), style=0) |
|
486 |
self.IndexList.Bind(wx.EVT_LISTBOX, self.OnIndexListClick, |
|
487 |
id=wxID_EDITINGPANELINDEXLIST) |
|
488 |
self.IndexList.Bind(wx.EVT_RIGHT_UP, self.OnIndexListRightUp) |
|
489 |
||
490 |
self.AddButton = wx.Button(id=wxID_EDITINGPANELADDBUTTON, label='Add', |
|
491 |
name='AddButton', parent=self.IndexListPanel, pos=wx.Point(0, 0), |
|
492 |
size=wx.Size(50, 30), style=0) |
|
493 |
self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButtonClick, |
|
494 |
id=wxID_EDITINGPANELADDBUTTON) |
|
495 |
||
496 |
self.IndexChoice = wx.Choice(choices=[], id=wxID_EDITINGPANELINDEXCHOICE, |
|
497 |
name='IndexChoice', parent=self.IndexListPanel, pos=wx.Point(50, |
|
498 |
0), size=wx.Size(-1, 30), style=0) |
|
499 |
||
500 |
self._init_sizers() |
|
501 |
||
502 |
def __init__(self, parent, manager): |
|
503 |
self._init_ctrls(parent.GetNoteBook()) |
|
504 |
self.Parent = parent |
|
505 |
self.Manager = manager |
|
506 |
self.ListIndex = [] |
|
507 |
self.ChoiceIndex = [] |
|
508 |
self.FirstCall = False |
|
509 |
||
510 |
for values in DictionaryOrganisation: |
|
37 | 511 |
text = " 0x%04X-0x%04X %s"%(values["minIndex"],values["maxIndex"],values["name"]) |
0 | 512 |
self.PartList.Append(text) |
513 |
self.Table = SubindexTable(self, [], [], ["subindex", "name", "type", "value", "access", "save", "comment"]) |
|
514 |
self.SubindexGrid.SetTable(self.Table) |
|
515 |
self.SubindexGrid.SetRowLabelSize(0) |
|
516 |
self.CallbackCheck.Disable() |
|
517 |
self.Table.ResetView(self.SubindexGrid) |
|
518 |
||
519 |
def GetSelection(self): |
|
520 |
selected = self.IndexList.GetSelection() |
|
521 |
if selected != wxNOT_FOUND: |
|
522 |
index = self.ListIndex[selected] |
|
523 |
subIndex = self.SubindexGrid.GetGridCursorRow() |
|
524 |
return index, subIndex |
|
525 |
return None |
|
526 |
||
527 |
def OnAddButtonClick(self, event): |
|
59 | 528 |
self.SubindexGrid.SetGridCursor(0, 0) |
0 | 529 |
selected = self.IndexChoice.GetStringSelection() |
530 |
if selected != "": |
|
531 |
if selected == "User Type": |
|
532 |
self.Parent.AddUserType() |
|
533 |
elif selected == "SDO Server": |
|
534 |
self.Manager.AddSDOServerToCurrent() |
|
535 |
elif selected == "SDO Client": |
|
536 |
self.Manager.AddSDOClientToCurrent() |
|
537 |
elif selected == "PDO Receive": |
|
538 |
self.Manager.AddPDOReceiveToCurrent() |
|
539 |
elif selected == "PDO Transmit": |
|
540 |
self.Manager.AddPDOTransmitToCurrent() |
|
541 |
elif selected == "Map Variable": |
|
542 |
self.Parent.AddMapVariable() |
|
543 |
elif selected in [menu for menu, indexes in self.Manager.GetCurrentSpecificMenu()]: |
|
544 |
self.Manager.AddSpecificEntryToCurrent(selected) |
|
545 |
else: |
|
546 |
index = self.ChoiceIndex[self.IndexChoice.GetSelection()] |
|
547 |
self.Manager.ManageEntriesOfCurrent([index], []) |
|
548 |
self.Parent.RefreshBufferState() |
|
549 |
self.RefreshIndexList() |
|
550 |
event.Skip() |
|
551 |
||
552 |
def OnPartListBoxClick(self, event): |
|
553 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
554 |
self.RefreshIndexList() |
|
555 |
event.Skip() |
|
556 |
||
557 |
def OnIndexListClick(self, event): |
|
558 |
self.SubindexGrid.SetGridCursor(0, 0) |
|
559 |
self.RefreshTable() |
|
560 |
event.Skip() |
|
561 |
||
562 |
def OnSubindexGridSelectCell(self, event): |
|
563 |
wxCallAfter(self.Parent.RefreshStatusBar) |
|
564 |
event.Skip() |
|
565 |
||
566 |
#------------------------------------------------------------------------------- |
|
567 |
# Refresh Functions |
|
568 |
#------------------------------------------------------------------------------- |
|
569 |
||
570 |
def RefreshIndexList(self): |
|
571 |
selected = self.IndexList.GetSelection() |
|
572 |
choice = self.IndexChoice.GetStringSelection() |
|
573 |
choiceindex = self.IndexChoice.GetSelection() |
|
574 |
if selected != wxNOT_FOUND: |
|
575 |
selectedindex = self.ListIndex[selected] |
|
576 |
self.IndexList.Clear() |
|
577 |
self.IndexChoice.Clear() |
|
578 |
i = self.PartList.GetSelection() |
|
579 |
if i < len(DictionaryOrganisation): |
|
580 |
values = DictionaryOrganisation[i] |
|
581 |
self.ListIndex = [] |
|
582 |
for name, index in self.Manager.GetCurrentValidIndexes(values["minIndex"], values["maxIndex"]): |
|
37 | 583 |
self.IndexList.Append("0x%04X %s"%(index, name)) |
0 | 584 |
self.ListIndex.append(index) |
585 |
self.ChoiceIndex = [] |
|
586 |
if i == 0: |
|
587 |
self.IndexChoice.Append("User Type") |
|
588 |
self.IndexChoice.SetStringSelection("User Type") |
|
589 |
elif i == 2: |
|
590 |
self.IndexChoice.Append("SDO Server") |
|
591 |
self.IndexChoice.Append("SDO Client") |
|
592 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
593 |
self.IndexChoice.SetStringSelection(choice) |
|
594 |
elif i in (3, 4): |
|
595 |
self.IndexChoice.Append("PDO Receive") |
|
596 |
self.IndexChoice.SetStringSelection("PDO Receive") |
|
597 |
elif i in (5, 6): |
|
598 |
self.IndexChoice.Append("PDO Transmit") |
|
599 |
self.IndexChoice.SetStringSelection("PDO Transmit") |
|
600 |
elif i == 8: |
|
601 |
self.IndexChoice.Append("Map Variable") |
|
602 |
self.IndexChoice.SetStringSelection("Map Variable") |
|
603 |
else: |
|
604 |
for name, index in self.Manager.GetCurrentValidChoices(values["minIndex"], values["maxIndex"]): |
|
605 |
if index: |
|
37 | 606 |
self.IndexChoice.Append("0x%04X %s"%(index, name)) |
0 | 607 |
else: |
608 |
self.IndexChoice.Append(name) |
|
609 |
self.ChoiceIndex.append(index) |
|
610 |
if choiceindex != wxNOT_FOUND and choice == self.IndexChoice.GetString(choiceindex): |
|
611 |
self.IndexChoice.SetStringSelection(choice) |
|
612 |
self.IndexChoice.Enable(self.IndexChoice.GetCount() != 0) |
|
613 |
self.AddButton.Enable(self.IndexChoice.GetCount() != 0) |
|
614 |
if selected == wxNOT_FOUND or selected >= len(self.ListIndex) or selectedindex != self.ListIndex[selected]: |
|
615 |
self.Table.Empty() |
|
616 |
self.CallbackCheck.SetValue(False) |
|
617 |
self.CallbackCheck.Disable() |
|
618 |
self.Table.ResetView(self.SubindexGrid) |
|
619 |
self.Parent.RefreshStatusBar() |
|
620 |
else: |
|
621 |
self.IndexList.SetSelection(selected) |
|
622 |
self.RefreshTable() |
|
623 |
||
624 |
def RefreshTable(self): |
|
625 |
selected = self.IndexList.GetSelection() |
|
626 |
if selected != wxNOT_FOUND: |
|
627 |
index = self.ListIndex[selected] |
|
628 |
if index > 0x260: |
|
629 |
self.CallbackCheck.Enable() |
|
630 |
self.CallbackCheck.SetValue(self.Manager.HasCurrentEntryCallbacks(index)) |
|
631 |
result = self.Manager.GetCurrentEntryValues(index) |
|
632 |
if result != None: |
|
633 |
self.Table.SetCurrentIndex(index) |
|
634 |
data, editors = result |
|
635 |
self.Table.SetData(data) |
|
636 |
self.Table.SetEditors(editors) |
|
637 |
self.Table.ResetView(self.SubindexGrid) |
|
638 |
self.Parent.RefreshStatusBar() |
|
639 |
||
640 |
#------------------------------------------------------------------------------- |
|
641 |
# Editing Table value function |
|
642 |
#------------------------------------------------------------------------------- |
|
643 |
||
644 |
def OnSubindexGridCellChange(self, event): |
|
645 |
index = self.Table.GetCurrentIndex() |
|
646 |
subIndex = event.GetRow() |
|
647 |
col = event.GetCol() |
|
648 |
name = self.Table.GetColLabelValue(col) |
|
649 |
value = self.Table.GetValue(subIndex, col) |
|
650 |
editor = self.Table.GetEditor(subIndex, col) |
|
651 |
self.Manager.SetCurrentEntry(index, subIndex, value, name, editor) |
|
652 |
self.Parent.RefreshBufferState() |
|
653 |
wxCallAfter(self.RefreshTable) |
|
654 |
event.Skip() |
|
655 |
||
656 |
def OnCallbackCheck(self, event): |
|
657 |
index = self.Table.GetCurrentIndex() |
|
658 |
self.Manager.SetCurrentEntryCallbacks(index, self.CallbackCheck.GetValue()) |
|
659 |
self.Parent.RefreshBufferState() |
|
660 |
wxCallAfter(self.RefreshTable) |
|
661 |
event.Skip() |
|
662 |
||
663 |
#------------------------------------------------------------------------------- |
|
664 |
# Contextual Menu functions |
|
665 |
#------------------------------------------------------------------------------- |
|
666 |
||
667 |
def OnIndexListRightUp(self, event): |
|
668 |
if not self.FirstCall: |
|
669 |
self.FirstCall = True |
|
670 |
selected = self.IndexList.GetSelection() |
|
671 |
if selected != wxNOT_FOUND: |
|
672 |
index = self.ListIndex[selected] |
|
673 |
if index < 0x260: |
|
674 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
675 |
self.IndexListMenu.FindItemByPosition(1).Enable(True) |
|
676 |
self.PopupMenu(self.IndexListMenu) |
|
677 |
elif 0x1000 <= index <= 0x1BFF: |
|
678 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
679 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
680 |
self.PopupMenu(self.IndexListMenu) |
|
681 |
elif 0x2000 <= index <= 0x5FFF: |
|
682 |
self.IndexListMenu.FindItemByPosition(0).Enable(True) |
|
683 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
684 |
self.PopupMenu(self.IndexListMenu) |
|
685 |
elif index >= 0x6000: |
|
686 |
self.IndexListMenu.FindItemByPosition(0).Enable(False) |
|
687 |
self.IndexListMenu.FindItemByPosition(1).Enable(False) |
|
688 |
self.PopupMenu(self.IndexListMenu) |
|
689 |
else: |
|
690 |
self.FirstCall = False |
|
691 |
event.Skip() |
|
692 |
||
693 |
def OnSubindexGridRightClick(self, event): |
|
694 |
selected = self.IndexList.GetSelection() |
|
695 |
if selected != wxNOT_FOUND: |
|
696 |
index = self.ListIndex[selected] |
|
697 |
if self.Manager.IsCurrentEntry(index): |
|
698 |
infos = self.Manager.GetEntryInfos(index) |
|
699 |
if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes: |
|
700 |
self.PopupMenu(self.SubindexGridMenu) |
|
701 |
event.Skip() |
|
702 |
||
703 |
def OnRenameIndexMenu(self, event): |
|
704 |
selected = self.IndexList.GetSelection() |
|
705 |
if selected != wxNOT_FOUND: |
|
706 |
index = self.ListIndex[selected] |
|
707 |
if self.Manager.IsCurrentEntry(index): |
|
708 |
infos = self.Manager.GetEntryInfos(index) |
|
709 |
dialog = wxTextEntryDialog(self, "Give a new name for index 0x%04X"%index, |
|
710 |
"Rename an index", infos["name"], wxOK|wxCANCEL) |
|
711 |
if dialog.ShowModal() == wxID_OK: |
|
712 |
self.Manager.SetCurrentEntryName(index, dialog.GetValue()) |
|
713 |
self.Parent.RefreshBufferState() |
|
714 |
self.RefreshIndexList() |
|
715 |
dialog.Destroy() |
|
716 |
event.Skip() |
|
717 |
||
718 |
def OnModifyIndexMenu(self, event): |
|
719 |
selected = self.IndexList.GetSelection() |
|
720 |
if selected != wxNOT_FOUND: |
|
721 |
index = self.ListIndex[selected] |
|
722 |
if self.Manager.IsCurrentEntry(index) and index < 0x260: |
|
723 |
values, valuetype = self.Manager.GetCustomisedTypeValues(index) |
|
724 |
dialog = UserTypeDialog(self) |
|
725 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes(), values[1]) |
|
726 |
if valuetype == 0: |
|
727 |
dialog.SetValues(min = values[2], max = values[3]) |
|
728 |
elif valuetype == 1: |
|
729 |
dialog.SetValues(length = values[2]) |
|
730 |
if dialog.ShowModal() == wxID_OK: |
|
731 |
type, min, max, length = dialog.GetValues() |
|
732 |
self.Manager.SetCurrentUserType(index, type, min, max, length) |
|
733 |
self.Parent.RefreshBufferState() |
|
734 |
self.RefreshIndexList() |
|
735 |
event.Skip() |
|
736 |
||
737 |
def OnDeleteIndexMenu(self, event): |
|
738 |
selected = self.IndexList.GetSelection() |
|
739 |
if selected != wxNOT_FOUND: |
|
740 |
index = self.ListIndex[selected] |
|
741 |
if self.Manager.IsCurrentEntry(index): |
|
742 |
self.Manager.ManageEntriesOfCurrent([],[index]) |
|
743 |
self.Parent.RefreshBufferState() |
|
744 |
self.RefreshIndexList() |
|
745 |
event.Skip() |
|
746 |
||
747 |
def OnAddSubindexMenu(self, event): |
|
748 |
selected = self.IndexList.GetSelection() |
|
749 |
if selected != wxNOT_FOUND: |
|
750 |
index = self.ListIndex[selected] |
|
751 |
if self.Manager.IsCurrentEntry(index): |
|
752 |
dialog = wxTextEntryDialog(self, "Number of subindexes to add:", |
|
753 |
"Add subindexes", "1", wxOK|wxCANCEL) |
|
754 |
if dialog.ShowModal() == wxID_OK: |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
755 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
756 |
number = int(dialog.GetValue()) |
0 | 757 |
self.Manager.AddSubentriesToCurrent(index, number) |
758 |
self.Parent.RefreshBufferState() |
|
759 |
self.RefreshIndexList() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
760 |
except: |
0 | 761 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
762 |
message.ShowModal() |
|
763 |
message.Destroy() |
|
764 |
dialog.Destroy() |
|
765 |
event.Skip() |
|
766 |
||
767 |
def OnDeleteSubindexMenu(self, event): |
|
768 |
selected = self.IndexList.GetSelection() |
|
769 |
if selected != wxNOT_FOUND: |
|
770 |
index = self.ListIndex[selected] |
|
771 |
if self.Manager.IsCurrentEntry(index): |
|
772 |
dialog = wxTextEntryDialog(self, "Number of subindexes to delete:", |
|
773 |
"Delete subindexes", "1", wxOK|wxCANCEL) |
|
774 |
if dialog.ShowModal() == wxID_OK: |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
775 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
776 |
number = int(dialog.GetValue()) |
0 | 777 |
self.Manager.RemoveSubentriesFromCurrent(index, number) |
778 |
self.Parent.RefreshBufferState() |
|
779 |
self.RefreshIndexList() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
780 |
except: |
0 | 781 |
message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR) |
782 |
message.ShowModal() |
|
783 |
message.Destroy() |
|
784 |
dialog.Destroy() |
|
785 |
event.Skip() |
|
786 |
||
787 |
[wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, |
|
788 |
wxID_OBJDICTEDITHELPBAR, |
|
789 |
] = [wx.NewId() for _init_ctrls in range(3)] |
|
790 |
||
791 |
[wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, |
|
792 |
wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, |
|
793 |
wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, |
|
794 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
|
795 |
||
796 |
[wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, |
|
797 |
wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, |
|
798 |
wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, |
|
799 |
wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8, |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
800 |
wxID_OBJDICTEDITFILEMENUITEMS9, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
801 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
0 | 802 |
|
803 |
[wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, |
|
804 |
wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, |
|
805 |
wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, |
|
806 |
wxID_OBJDICTEDITEDITMENUITEMS8, |
|
807 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] |
|
808 |
||
809 |
[wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1, |
|
810 |
wxID_OBJDICTEDITHELPMENUITEMS2, |
|
811 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] |
|
812 |
||
813 |
class objdictedit(wx.Frame): |
|
814 |
def _init_coll_menuBar1_Menus(self, parent): |
|
815 |
# generated method, don't edit |
|
816 |
||
817 |
parent.Append(menu=self.FileMenu, title='File') |
|
818 |
parent.Append(menu=self.EditMenu, title='Edit') |
|
819 |
parent.Append(menu=self.AddMenu, title='Add') |
|
820 |
parent.Append(menu=self.HelpMenu, title='Help') |
|
821 |
||
822 |
def _init_coll_EditMenu_Items(self, parent): |
|
823 |
# generated method, don't edit |
|
824 |
||
825 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4, |
|
826 |
kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') |
|
827 |
parent.AppendSeparator() |
|
828 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1, |
|
829 |
kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') |
|
830 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0, |
|
831 |
kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') |
|
832 |
parent.AppendSeparator() |
|
833 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6, |
|
834 |
kind=wx.ITEM_NORMAL, text='Node infos') |
|
835 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2, |
|
836 |
kind=wx.ITEM_NORMAL, text='DS-301 Profile') |
|
837 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8, |
|
838 |
kind=wx.ITEM_NORMAL, text='DS-302 Profile') |
|
839 |
parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7, |
|
840 |
kind=wx.ITEM_NORMAL, text='Other Profile') |
|
841 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, |
|
842 |
id=wxID_OBJDICTEDITEDITMENUITEMS1) |
|
843 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, |
|
844 |
id=wxID_OBJDICTEDITEDITMENUITEMS0) |
|
845 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
|
846 |
id=wxID_OBJDICTEDITEDITMENUITEMS2) |
|
847 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
|
848 |
id=wxID_OBJDICTEDITEDITMENUITEMS4) |
|
849 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
|
850 |
id=wxID_OBJDICTEDITEDITMENUITEMS6) |
|
851 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
|
852 |
id=wxID_OBJDICTEDITEDITMENUITEMS7) |
|
853 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
|
854 |
id=wxID_OBJDICTEDITEDITMENUITEMS8) |
|
855 |
||
856 |
def _init_coll_HelpMenu_Items(self, parent): |
|
857 |
# generated method, don't edit |
|
858 |
||
859 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0, |
|
860 |
kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') |
|
861 |
self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, |
|
862 |
id=wxID_OBJDICTEDITHELPMENUITEMS0) |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
863 |
if Html_Window: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
864 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
865 |
kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
866 |
parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
867 |
kind=wx.ITEM_NORMAL, text='About') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
868 |
self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
869 |
id=wxID_OBJDICTEDITHELPMENUITEMS1) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
870 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
871 |
id=wxID_OBJDICTEDITHELPMENUITEMS2) |
0 | 872 |
|
873 |
def _init_coll_FileMenu_Items(self, parent): |
|
874 |
# generated method, don't edit |
|
875 |
||
876 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5, |
|
877 |
kind=wx.ITEM_NORMAL, text='New\tCTRL+N') |
|
878 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0, |
|
879 |
kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') |
|
880 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1, |
|
881 |
kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') |
|
882 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6, |
|
883 |
kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') |
|
884 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2, |
|
885 |
kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') |
|
886 |
parent.AppendSeparator() |
|
171 | 887 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7, |
888 |
kind=wx.ITEM_NORMAL, text='Import EDS file') |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
889 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS9, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
890 |
kind=wx.ITEM_NORMAL, text='Export to EDS file') |
0 | 891 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8, |
892 |
kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') |
|
893 |
parent.AppendSeparator() |
|
894 |
parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4, |
|
895 |
kind=wx.ITEM_NORMAL, text='Exit') |
|
896 |
self.Bind(wx.EVT_MENU, self.OnOpenMenu, |
|
897 |
id=wxID_OBJDICTEDITFILEMENUITEMS0) |
|
898 |
self.Bind(wx.EVT_MENU, self.OnSaveMenu, |
|
899 |
id=wxID_OBJDICTEDITFILEMENUITEMS1) |
|
900 |
self.Bind(wx.EVT_MENU, self.OnCloseMenu, |
|
901 |
id=wxID_OBJDICTEDITFILEMENUITEMS2) |
|
902 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
|
903 |
id=wxID_OBJDICTEDITFILEMENUITEMS4) |
|
904 |
self.Bind(wx.EVT_MENU, self.OnNewMenu, |
|
905 |
id=wxID_OBJDICTEDITFILEMENUITEMS5) |
|
906 |
self.Bind(wx.EVT_MENU, self.OnSaveAsMenu, |
|
907 |
id=wxID_OBJDICTEDITFILEMENUITEMS6) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
908 |
self.Bind(wx.EVT_MENU, self.OnImportEDSMenu, |
171 | 909 |
id=wxID_OBJDICTEDITFILEMENUITEMS7) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
910 |
self.Bind(wx.EVT_MENU, self.OnExportCMenu, |
0 | 911 |
id=wxID_OBJDICTEDITFILEMENUITEMS8) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
912 |
self.Bind(wx.EVT_MENU, self.OnExportEDSMenu, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
913 |
id=wxID_OBJDICTEDITFILEMENUITEMS9) |
0 | 914 |
|
915 |
def _init_coll_AddMenu_Items(self, parent): |
|
916 |
# generated method, don't edit |
|
917 |
||
918 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0, |
|
919 |
kind=wx.ITEM_NORMAL, text='SDO Server') |
|
920 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1, |
|
921 |
kind=wx.ITEM_NORMAL, text='SDO Client') |
|
922 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2, |
|
923 |
kind=wx.ITEM_NORMAL, text='PDO Transmit') |
|
924 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3, |
|
925 |
kind=wx.ITEM_NORMAL, text='PDO Receive') |
|
926 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4, |
|
927 |
kind=wx.ITEM_NORMAL, text='Map Variable') |
|
928 |
parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5, |
|
929 |
kind=wx.ITEM_NORMAL, text='User Type') |
|
930 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
|
931 |
id=wxID_OBJDICTEDITADDMENUITEMS0) |
|
932 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
|
933 |
id=wxID_OBJDICTEDITADDMENUITEMS1) |
|
934 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
|
935 |
id=wxID_OBJDICTEDITADDMENUITEMS2) |
|
936 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
|
937 |
id=wxID_OBJDICTEDITADDMENUITEMS3) |
|
938 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
|
939 |
id=wxID_OBJDICTEDITADDMENUITEMS4) |
|
940 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
|
941 |
id=wxID_OBJDICTEDITADDMENUITEMS5) |
|
942 |
||
943 |
def _init_coll_HelpBar_Fields(self, parent): |
|
944 |
# generated method, don't edit |
|
945 |
parent.SetFieldsCount(3) |
|
946 |
||
947 |
parent.SetStatusText(number=0, text='') |
|
948 |
parent.SetStatusText(number=1, text='') |
|
949 |
parent.SetStatusText(number=2, text='') |
|
950 |
||
951 |
parent.SetStatusWidths([100, 110, -1]) |
|
952 |
||
953 |
def _init_utils(self): |
|
954 |
# generated method, don't edit |
|
955 |
self.menuBar1 = wx.MenuBar() |
|
956 |
self.menuBar1.SetEvtHandlerEnabled(True) |
|
957 |
||
958 |
self.FileMenu = wx.Menu(title='') |
|
959 |
||
960 |
self.EditMenu = wx.Menu(title='') |
|
961 |
||
962 |
self.AddMenu = wx.Menu(title='') |
|
963 |
||
964 |
self.HelpMenu = wx.Menu(title='') |
|
965 |
||
966 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
967 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
968 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
969 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
970 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
971 |
||
972 |
def _init_ctrls(self, prnt): |
|
973 |
# generated method, don't edit |
|
974 |
wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit', |
|
975 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
|
976 |
style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') |
|
977 |
self._init_utils() |
|
978 |
self.SetClientSize(wx.Size(1000, 700)) |
|
979 |
self.SetMenuBar(self.menuBar1) |
|
980 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_OBJDICTEDIT) |
|
981 |
||
982 |
self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED, |
|
983 |
name='FileOpened', parent=self, pos=wx.Point(0, 0), |
|
984 |
size=wx.Size(0, 0), style=0) |
|
985 |
self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
986 |
self.OnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED) |
|
987 |
||
988 |
self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar', |
|
989 |
parent=self, style=wxST_SIZEGRIP) |
|
990 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
|
991 |
self.SetStatusBar(self.HelpBar) |
|
992 |
||
993 |
def __init__(self, parent): |
|
994 |
self._init_ctrls(parent) |
|
995 |
self.HtmlFrameOpened = [] |
|
996 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
997 |
self.Manager = NodeManager(ScriptDirectory) |
0 | 998 |
for filepath in filesOpen: |
999 |
self.Manager.OpenFileInCurrent(filepath) |
|
1000 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
1001 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
1002 |
self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) |
|
1003 |
if self.Manager.CurrentDS302Defined(): |
|
1004 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
1005 |
else: |
|
1006 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
|
1007 |
self.RefreshEditMenu() |
|
1008 |
self.RefreshBufferState() |
|
1009 |
self.RefreshProfileMenu() |
|
1010 |
self.RefreshMainMenu() |
|
1011 |
||
1012 |
self.RefreshBufferState() |
|
1013 |
self.RefreshTitle() |
|
1014 |
self.RefreshMainMenu() |
|
1015 |
||
1016 |
def GetNoteBook(self): |
|
1017 |
return self.FileOpened |
|
1018 |
||
1019 |
def OnAddSDOServerMenu(self, event): |
|
1020 |
self.Manager.AddSDOServerToCurrent() |
|
1021 |
self.RefreshBufferState() |
|
1022 |
self.RefreshCurrentIndexList() |
|
1023 |
event.Skip() |
|
1024 |
||
1025 |
def OnAddSDOClientMenu(self, event): |
|
1026 |
self.Manager.AddSDOClientToCurrent() |
|
1027 |
self.RefreshBufferState() |
|
1028 |
self.RefreshCurrentIndexList() |
|
1029 |
event.Skip() |
|
1030 |
||
1031 |
def OnAddPDOTransmitMenu(self, event): |
|
1032 |
self.Manager.AddPDOTransmitToCurrent() |
|
1033 |
self.RefreshBufferState() |
|
1034 |
self.RefreshCurrentIndexList() |
|
1035 |
event.Skip() |
|
1036 |
||
1037 |
def OnAddPDOReceiveMenu(self, event): |
|
1038 |
self.Manager.AddPDOReceiveToCurrent() |
|
1039 |
self.RefreshBufferState() |
|
1040 |
self.RefreshCurrentIndexList() |
|
1041 |
event.Skip() |
|
1042 |
||
1043 |
def OnAddMapVariableMenu(self, event): |
|
1044 |
self.AddMapVariable() |
|
1045 |
event.Skip() |
|
1046 |
||
1047 |
def OnAddUserTypeMenu(self, event): |
|
1048 |
self.AddUserType() |
|
1049 |
event.Skip() |
|
1050 |
||
1051 |
def OnFileSelectedChanged(self, event): |
|
43 | 1052 |
selected = event.GetSelection() |
37 | 1053 |
# At init selected = -1 |
1054 |
if selected >= 0: |
|
1055 |
self.Manager.ChangeCurrentNode(selected) |
|
1056 |
self.RefreshBufferState() |
|
1057 |
self.RefreshProfileMenu() |
|
0 | 1058 |
event.Skip() |
1059 |
||
1060 |
def OnHelpDS301Menu(self, event): |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1061 |
find_index = False |
0 | 1062 |
selected = self.FileOpened.GetSelection() |
1063 |
if selected >= 0: |
|
1064 |
window = self.FileOpened.GetPage(selected) |
|
1065 |
result = window.GetSelection() |
|
1066 |
if result: |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1067 |
find_index = True |
0 | 1068 |
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
|
1069 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
0 | 1070 |
if type(result) == StringType: |
1071 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
|
1072 |
message.ShowModal() |
|
1073 |
message.Destroy() |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1074 |
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
|
1075 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1076 |
if type(result) == StringType: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1077 |
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
|
1078 |
message.ShowModal() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
1079 |
message.Destroy() |
0 | 1080 |
event.Skip() |
1081 |
||
1082 |
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
|
1083 |
#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
|
1084 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
0 | 1085 |
event.Skip() |
1086 |
||
1087 |
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
|
1088 |
self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
0 | 1089 |
event.Skip() |
1090 |
||
1091 |
def OpenHtmlFrame(self, title, file, size): |
|
1092 |
if title not in self.HtmlFrameOpened: |
|
1093 |
self.HtmlFrameOpened.append(title) |
|
1094 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
1095 |
window.SetTitle(title) |
|
1096 |
window.SetHtmlPage(file) |
|
1097 |
window.SetClientSize(size) |
|
1098 |
window.Show() |
|
1099 |
||
1100 |
def OnQuitMenu(self, event): |
|
1101 |
self.Close() |
|
1102 |
event.Skip() |
|
1103 |
||
1104 |
def OnCloseFrame(self, event): |
|
1105 |
if self.Manager.OneFileHasChanged(): |
|
1106 |
dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION) |
|
1107 |
answer = dialog.ShowModal() |
|
1108 |
dialog.Destroy() |
|
1109 |
if answer == wxID_YES: |
|
1110 |
self.Manager.ChangeCurrentNode(0) |
|
1111 |
for i in xrange(self.FileOpened.GetPageCount()): |
|
1112 |
if self.Manager.CurrentIsSaved(): |
|
1113 |
self.Manager.CloseCurrent() |
|
1114 |
else: |
|
1115 |
self.Save() |
|
1116 |
self.Manager.CloseCurrent(True) |
|
1117 |
event.Skip() |
|
1118 |
elif answer == wxID_NO: |
|
1119 |
for i in xrange(self.FileOpened.GetPageCount()): |
|
1120 |
self.Manager.CloseCurrent(True) |
|
1121 |
wxCallAfter(self.Close) |
|
1122 |
event.Skip() |
|
1123 |
else: |
|
1124 |
event.Skip() |
|
1125 |
||
1126 |
#------------------------------------------------------------------------------- |
|
1127 |
# Refresh Functions |
|
1128 |
#------------------------------------------------------------------------------- |
|
1129 |
||
1130 |
def RefreshTitle(self): |
|
1131 |
if self.FileOpened.GetPageCount() > 0: |
|
1132 |
self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename()) |
|
1133 |
else: |
|
1134 |
self.SetTitle("Objdictedit") |
|
1135 |
||
1136 |
def OnRefreshMenu(self, event): |
|
1137 |
self.RefreshCurrentIndexList() |
|
1138 |
event.Skip() |
|
1139 |
||
1140 |
def RefreshCurrentIndexList(self): |
|
1141 |
selected = self.FileOpened.GetSelection() |
|
1142 |
window = self.FileOpened.GetPage(selected) |
|
1143 |
window.RefreshIndexList() |
|
1144 |
||
1145 |
def RefreshStatusBar(self): |
|
1146 |
window = self.FileOpened.GetPage(self.FileOpened.GetSelection()) |
|
1147 |
selection = window.GetSelection() |
|
1148 |
if selection: |
|
1149 |
index, subIndex = selection |
|
1150 |
if self.Manager.IsCurrentEntry(index): |
|
1151 |
self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) |
|
1152 |
self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) |
|
1153 |
entryinfos = self.Manager.GetEntryInfos(index) |
|
1154 |
name = entryinfos["name"] |
|
1155 |
category = "Optional" |
|
1156 |
if entryinfos["need"]: |
|
1157 |
category = "Mandatory" |
|
1158 |
struct = "VAR" |
|
1159 |
number = "" |
|
1160 |
if entryinfos["struct"] & OD_IdenticalIndexes: |
|
1161 |
number = " possibly defined %d times"%entryinfos["nbmax"] |
|
1162 |
if entryinfos["struct"] & OD_IdenticalSubindexes: |
|
1163 |
struct = "REC" |
|
1164 |
elif entryinfos["struct"] & OD_MultipleSubindexes: |
|
1165 |
struct = "ARRAY" |
|
1166 |
text = "%s: %s entry of struct %s%s."%(name,category,struct,number) |
|
1167 |
self.HelpBar.SetStatusText(text, 2) |
|
1168 |
else: |
|
1169 |
for i in xrange(3): |
|
1170 |
self.HelpBar.SetStatusText("", i) |
|
1171 |
else: |
|
1172 |
for i in xrange(3): |
|
1173 |
self.HelpBar.SetStatusText("", i) |
|
1174 |
||
1175 |
def RefreshMainMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1176 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1177 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1178 |
self.menuBar1.EnableTop(1, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1179 |
self.menuBar1.EnableTop(2, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1180 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1181 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1182 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1183 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1184 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1185 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1186 |
self.menuBar1.EnableTop(1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1187 |
self.menuBar1.EnableTop(2, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1188 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1189 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1190 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1191 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1192 |
self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, False) |
0 | 1193 |
|
1194 |
def RefreshEditMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1195 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1196 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1197 |
undo, redo = self.Manager.GetCurrentBufferState() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1198 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, undo) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1199 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, redo) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1200 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1201 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, False) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1202 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, False) |
0 | 1203 |
|
1204 |
def RefreshProfileMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1205 |
if self.EditMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1206 |
profile = self.Manager.GetCurrentProfileName() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1207 |
edititem = self.EditMenu.FindItemById(wxID_OBJDICTEDITEDITMENUITEMS7) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1208 |
if edititem: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1209 |
length = self.AddMenu.GetMenuItemCount() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1210 |
for i in xrange(length-6): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1211 |
additem = self.AddMenu.FindItemByPosition(6) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1212 |
self.AddMenu.Delete(additem.GetId()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1213 |
if profile not in ("None", "DS-301"): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1214 |
edititem.SetText("%s Profile"%profile) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1215 |
edititem.Enable(True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1216 |
self.AddMenu.AppendSeparator() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1217 |
for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1218 |
new_id = wx.NewId() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1219 |
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
|
1220 |
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
|
1221 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1222 |
edititem.SetText("Other Profile") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1223 |
edititem.Enable(False) |
0 | 1224 |
|
1225 |
||
1226 |
#------------------------------------------------------------------------------- |
|
1227 |
# Buffer Functions |
|
1228 |
#------------------------------------------------------------------------------- |
|
1229 |
||
1230 |
def RefreshBufferState(self): |
|
1231 |
fileopened = self.Manager.GetAllFilenames() |
|
1232 |
for idx, filename in enumerate(fileopened): |
|
1233 |
self.FileOpened.SetPageText(idx, filename) |
|
1234 |
self.RefreshEditMenu() |
|
1235 |
self.RefreshTitle() |
|
1236 |
||
1237 |
def OnUndoMenu(self, event): |
|
1238 |
self.Manager.LoadCurrentPrevious() |
|
1239 |
self.RefreshCurrentIndexList() |
|
1240 |
self.RefreshBufferState() |
|
1241 |
event.Skip() |
|
1242 |
||
1243 |
def OnRedoMenu(self, event): |
|
1244 |
self.Manager.LoadCurrentNext() |
|
1245 |
self.RefreshCurrentIndexList() |
|
1246 |
self.RefreshBufferState() |
|
1247 |
event.Skip() |
|
1248 |
||
1249 |
||
1250 |
#------------------------------------------------------------------------------- |
|
1251 |
# Load and Save Funtions |
|
1252 |
#------------------------------------------------------------------------------- |
|
1253 |
||
1254 |
def OnNewMenu(self, event): |
|
1255 |
self.FilePath = "" |
|
1256 |
dialog = CreateNodeDialog(self) |
|
1257 |
if dialog.ShowModal() == wxID_OK: |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1258 |
name, id, type, description = dialog.GetValues() |
59 | 1259 |
profile, filepath = dialog.GetProfile() |
1260 |
NMT = dialog.GetNMTManagement() |
|
1261 |
options = dialog.GetOptions() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1262 |
result = self.Manager.CreateNewNode(name, id, type, description, profile, filepath, NMT, options) |
59 | 1263 |
if not IsOfType(result, StringType): |
1264 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
1265 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
1266 |
self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) |
|
1267 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
|
1268 |
if "DS302" in options: |
|
1269 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
1270 |
self.RefreshBufferState() |
|
1271 |
self.RefreshProfileMenu() |
|
1272 |
self.RefreshMainMenu() |
|
0 | 1273 |
else: |
59 | 1274 |
message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) |
0 | 1275 |
message.ShowModal() |
1276 |
message.Destroy() |
|
1277 |
event.Skip() |
|
1278 |
||
1279 |
def OnOpenMenu(self, event): |
|
1280 |
filepath = self.Manager.GetCurrentFilePath() |
|
1281 |
if filepath != "": |
|
1282 |
directory = os.path.dirname(filepath) |
|
1283 |
else: |
|
1284 |
directory = os.getcwd() |
|
59 | 1285 |
dialog = wxFileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR) |
0 | 1286 |
if dialog.ShowModal() == wxID_OK: |
1287 |
filepath = dialog.GetPath() |
|
1288 |
if os.path.isfile(filepath): |
|
1289 |
result = self.Manager.OpenFileInCurrent(filepath) |
|
1290 |
if type(result) != StringType: |
|
1291 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
1292 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
1293 |
self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) |
|
1294 |
if self.Manager.CurrentDS302Defined(): |
|
1295 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) |
|
1296 |
else: |
|
1297 |
self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) |
|
1298 |
self.RefreshEditMenu() |
|
1299 |
self.RefreshBufferState() |
|
1300 |
self.RefreshProfileMenu() |
|
1301 |
self.RefreshMainMenu() |
|
1302 |
else: |
|
1303 |
message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR) |
|
1304 |
message.ShowModal() |
|
1305 |
message.Destroy() |
|
1306 |
dialog.Destroy() |
|
1307 |
event.Skip() |
|
1308 |
||
1309 |
def OnSaveMenu(self, event): |
|
1310 |
self.Save() |
|
1311 |
event.Skip() |
|
1312 |
||
1313 |
def OnSaveAsMenu(self, event): |
|
1314 |
self.SaveAs() |
|
30 | 1315 |
event.Skip() |
0 | 1316 |
|
1317 |
def Save(self): |
|
1318 |
result = self.Manager.SaveCurrentInFile() |
|
1319 |
if not result: |
|
1320 |
self.SaveAs() |
|
1321 |
elif type(result) != StringType: |
|
1322 |
self.RefreshBufferState() |
|
1323 |
else: |
|
1324 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
1325 |
message.ShowModal() |
|
1326 |
message.Destroy() |
|
1327 |
||
1328 |
def SaveAs(self): |
|
1329 |
filepath = self.Manager.GetCurrentFilePath() |
|
1330 |
if filepath != "": |
|
1331 |
directory, filename = os.path.split(filepath) |
|
1332 |
else: |
|
1333 |
directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] |
|
59 | 1334 |
dialog = wxFileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) |
0 | 1335 |
if dialog.ShowModal() == wxID_OK: |
1336 |
filepath = dialog.GetPath() |
|
1337 |
if os.path.isdir(os.path.dirname(filepath)): |
|
1338 |
result = self.Manager.SaveCurrentInFile(filepath) |
|
1339 |
if type(result) != StringType: |
|
1340 |
self.RefreshBufferState() |
|
1341 |
else: |
|
1342 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
1343 |
message.ShowModal() |
|
1344 |
message.Destroy() |
|
1345 |
else: |
|
1346 |
message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
|
1347 |
message.ShowModal() |
|
1348 |
message.Destroy() |
|
1349 |
dialog.Destroy() |
|
1350 |
||
1351 |
def OnCloseMenu(self, event): |
|
1352 |
answer = wxID_YES |
|
1353 |
result = self.Manager.CloseCurrent() |
|
1354 |
if not result: |
|
1355 |
dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION) |
|
1356 |
answer = dialog.ShowModal() |
|
1357 |
dialog.Destroy() |
|
1358 |
if answer == wxID_YES: |
|
1359 |
self.OnSaveMenu(event) |
|
1360 |
if self.Manager.CurrentIsSaved(): |
|
1361 |
self.Manager.CloseCurrent() |
|
1362 |
elif answer == wxID_NO: |
|
1363 |
self.Manager.CloseCurrent(True) |
|
1364 |
if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): |
|
1365 |
current = self.FileOpened.GetSelection() |
|
1366 |
self.FileOpened.DeletePage(current) |
|
1367 |
if self.FileOpened.GetPageCount() > 0: |
|
1368 |
self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) |
|
1369 |
self.RefreshBufferState() |
|
1370 |
self.RefreshMainMenu() |
|
1371 |
event.Skip() |
|
1372 |
||
1373 |
||
1374 |
#------------------------------------------------------------------------------- |
|
1375 |
# Import and Export Functions |
|
1376 |
#------------------------------------------------------------------------------- |
|
1377 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1378 |
def OnImportEDSMenu(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1379 |
dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR) |
0 | 1380 |
if dialog.ShowModal() == wxID_OK: |
1381 |
filepath = dialog.GetPath() |
|
1382 |
if os.path.isfile(filepath): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1383 |
result = self.Manager.ImportCurrentFromEDSFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1384 |
if not result: |
0 | 1385 |
if self.FileOpened.GetPageCount() == 0: |
1386 |
new_editingpanel = EditingPanel(self, self.Manager) |
|
1387 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
1388 |
self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex()) |
|
1389 |
self.RefreshBufferState() |
|
1390 |
self.RefreshCurrentIndexList() |
|
1391 |
self.RefreshProfileMenu() |
|
1392 |
self.RefreshMainMenu() |
|
1393 |
message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION) |
|
1394 |
message.ShowModal() |
|
1395 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1396 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1397 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1398 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1399 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1400 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1401 |
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
|
1402 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1403 |
message.Destroy() |
0 | 1404 |
dialog.Destroy() |
1405 |
event.Skip() |
|
1406 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1407 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1408 |
def OnExportEDSMenu(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1409 |
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
|
1410 |
if dialog.ShowModal() == wxID_OK: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1411 |
filepath = dialog.GetPath() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1412 |
if os.path.isdir(os.path.dirname(filepath)): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1413 |
path, extend = os.path.splitext(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1414 |
if extend in ("", "."): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1415 |
filepath = path + ".eds" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1416 |
result = self.Manager.ExportCurrentToEDSFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1417 |
if not result: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1418 |
message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1419 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1420 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1421 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1422 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1423 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1424 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1425 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1426 |
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
|
1427 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1428 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1429 |
dialog.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1430 |
event.Skip() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1431 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1432 |
def OnExportCMenu(self, event): |
59 | 1433 |
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 | 1434 |
if dialog.ShowModal() == wxID_OK: |
1435 |
filepath = dialog.GetPath() |
|
1436 |
if os.path.isdir(os.path.dirname(filepath)): |
|
1437 |
path, extend = os.path.splitext(filepath) |
|
1438 |
if extend in ("", "."): |
|
1439 |
filepath = path + ".c" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1440 |
result = self.Manager.ExportCurrentToCFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1441 |
if not result: |
0 | 1442 |
message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) |
1443 |
message.ShowModal() |
|
1444 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1445 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1446 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1447 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1448 |
message.Destroy() |
0 | 1449 |
else: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1450 |
message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) |
0 | 1451 |
message.ShowModal() |
1452 |
message.Destroy() |
|
1453 |
dialog.Destroy() |
|
1454 |
event.Skip() |
|
1455 |
||
1456 |
#------------------------------------------------------------------------------- |
|
1457 |
# Editing Profiles functions |
|
1458 |
#------------------------------------------------------------------------------- |
|
1459 |
||
1460 |
def OnCommunicationMenu(self, event): |
|
1461 |
dictionary,current = self.Manager.GetCurrentCommunicationLists() |
|
1462 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
1463 |
event.Skip() |
|
1464 |
||
1465 |
def OnOtherCommunicationMenu(self, event): |
|
1466 |
dictionary,current = self.Manager.GetCurrentDS302Lists() |
|
1467 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
1468 |
event.Skip() |
|
1469 |
||
1470 |
def OnEditProfileMenu(self, event): |
|
1471 |
title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() |
|
1472 |
dictionary,current = self.Manager.GetCurrentProfileLists() |
|
1473 |
self.EditProfile(title, dictionary, current) |
|
1474 |
event.Skip() |
|
1475 |
||
1476 |
def EditProfile(self, title, dictionary, current): |
|
1477 |
dialog = CommunicationDialog(self) |
|
1478 |
dialog.SetTitle(title) |
|
1479 |
dialog.SetIndexDictionary(dictionary) |
|
1480 |
dialog.SetCurrentList(current) |
|
1481 |
dialog.RefreshLists() |
|
1482 |
if dialog.ShowModal() == wxID_OK: |
|
1483 |
new_profile = dialog.GetCurrentList() |
|
1484 |
addinglist = [] |
|
1485 |
removinglist = [] |
|
1486 |
for index in new_profile: |
|
1487 |
if index not in current: |
|
1488 |
addinglist.append(index) |
|
1489 |
for index in current: |
|
1490 |
if index not in new_profile: |
|
1491 |
removinglist.append(index) |
|
1492 |
self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) |
|
1493 |
self.Manager.GenerateMapList() |
|
1494 |
self.Manager.BufferCurrentNode() |
|
1495 |
self.RefreshBufferState() |
|
1496 |
self.RefreshCurrentIndexList() |
|
1497 |
dialog.Destroy() |
|
1498 |
||
1499 |
def GetProfileCallBack(self, text): |
|
1500 |
def ProfileCallBack(event): |
|
1501 |
self.Manager.AddSpecificEntryToCurrent(text) |
|
1502 |
self.RefreshBufferState() |
|
1503 |
self.RefreshCurrentIndexList() |
|
1504 |
event.Skip() |
|
1505 |
return ProfileCallBack |
|
1506 |
||
1507 |
#------------------------------------------------------------------------------- |
|
1508 |
# Edit Node informations function |
|
1509 |
#------------------------------------------------------------------------------- |
|
1510 |
||
1511 |
def OnNodeInfosMenu(self, event): |
|
1512 |
dialog = NodeInfosDialog(self) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1513 |
name, id, type, description = self.Manager.GetCurrentNodeInfos() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1514 |
dialog.SetValues(name, id, type, description) |
0 | 1515 |
if dialog.ShowModal() == wxID_OK: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1516 |
name, id, type, description = dialog.GetValues() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1517 |
self.Manager.SetCurrentNodeInfos(name, id, type, description) |
0 | 1518 |
self.RefreshBufferState() |
1519 |
self.RefreshProfileMenu() |
|
1520 |
event.Skip() |
|
1521 |
||
1522 |
||
1523 |
#------------------------------------------------------------------------------- |
|
1524 |
# Add User Types and Variables |
|
1525 |
#------------------------------------------------------------------------------- |
|
1526 |
||
1527 |
def AddMapVariable(self): |
|
39 | 1528 |
index = self.Manager.GetCurrentNextMapIndex() |
1529 |
if index: |
|
1530 |
dialog = MapVariableDialog(self) |
|
1531 |
dialog.SetIndex(index) |
|
1532 |
if dialog.ShowModal() == wxID_OK: |
|
1533 |
index, name, struct, number = dialog.GetValues() |
|
1534 |
result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) |
|
1535 |
if type(result) != StringType: |
|
1536 |
self.RefreshBufferState() |
|
1537 |
self.RefreshCurrentIndexList() |
|
1538 |
else: |
|
1539 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
1540 |
message.ShowModal() |
|
1541 |
message.Destroy() |
|
1542 |
dialog.Destroy() |
|
1543 |
else: |
|
1544 |
message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR) |
|
1545 |
message.ShowModal() |
|
1546 |
message.Destroy() |
|
0 | 1547 |
|
1548 |
def AddUserType(self): |
|
1549 |
dialog = UserTypeDialog(self) |
|
1550 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
|
1551 |
if dialog.ShowModal() == wxID_OK: |
|
1552 |
type, min, max, length = dialog.GetValues() |
|
1553 |
result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
|
1554 |
if not IsOfType(result, StringType): |
|
1555 |
self.RefreshBufferState() |
|
1556 |
self.RefreshCurrentIndexList() |
|
1557 |
else: |
|
1558 |
message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) |
|
1559 |
message.ShowModal() |
|
1560 |
message.Destroy() |
|
1561 |
dialog.Destroy() |
|
1562 |
||
1563 |
||
1564 |
||
1565 |
#------------------------------------------------------------------------------- |
|
1566 |
# Editing Communication Dialog |
|
1567 |
#------------------------------------------------------------------------------- |
|
1568 |
||
1569 |
||
1570 |
[wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL, |
|
1571 |
wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES, |
|
1572 |
wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT, |
|
1573 |
wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2 |
|
1574 |
] = [wx.NewId() for _init_ctrls in range(8)] |
|
1575 |
||
1576 |
class CommunicationDialog(wx.Dialog): |
|
1577 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1578 |
# generated method, don't edit |
|
1579 |
||
1580 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1581 |
||
1582 |
def _init_sizers(self): |
|
1583 |
# generated method, don't edit |
|
1584 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1585 |
||
1586 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1587 |
||
1588 |
self.SetSizer(self.flexGridSizer1) |
|
1589 |
||
1590 |
def _init_ctrls(self, prnt): |
|
1591 |
# generated method, don't edit |
|
1592 |
wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG, |
|
1593 |
name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216), |
|
1594 |
size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE, |
|
1595 |
title='Edit Communication Profile') |
|
1596 |
self.SetClientSize(wx.Size(726, 437)) |
|
1597 |
||
1598 |
self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL, |
|
1599 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1600 |
size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL) |
|
1601 |
self.MainPanel.SetAutoLayout(True) |
|
1602 |
||
1603 |
self.PossibleIndexes = wx.ListBox(choices=[], |
|
1604 |
id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, |
|
1605 |
name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40, |
|
1606 |
48), size=wx.Size(280, 320), style=wxLB_EXTENDED) |
|
1607 |
self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick, |
|
1608 |
id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES) |
|
1609 |
||
1610 |
self.CurrentIndexes = wx.ListBox(choices=[], |
|
1611 |
id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes', |
|
1612 |
parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280, |
|
1613 |
320), style=wxLB_EXTENDED) |
|
1614 |
self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick, |
|
1615 |
id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES) |
|
1616 |
||
1617 |
self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>', |
|
1618 |
name='Select', parent=self.MainPanel, pos=wx.Point(345, 136), |
|
1619 |
size=wx.Size(32, 32), style=0) |
|
1620 |
self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton, |
|
1621 |
id=wxID_COMMUNICATIONDIALOGSELECT) |
|
1622 |
||
1623 |
self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT, |
|
1624 |
label='<<', name='Unselect', parent=self.MainPanel, |
|
1625 |
pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0) |
|
1626 |
self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton, |
|
1627 |
id=wxID_COMMUNICATIONDIALOGUNSELECT) |
|
1628 |
||
1629 |
self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1, |
|
59 | 1630 |
label='Possible Profile Indexes:', name='staticText1', |
0 | 1631 |
parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156, |
1632 |
17), style=0) |
|
1633 |
||
1634 |
self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2, |
|
59 | 1635 |
label='Current Profile Indexes:', name='staticText2', |
0 | 1636 |
parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152, |
1637 |
17), style=0) |
|
1638 |
||
1639 |
self._init_sizers() |
|
1640 |
||
1641 |
def __init__(self, parent): |
|
1642 |
self._init_ctrls(parent) |
|
1643 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1644 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1645 |
self.AllList = [] |
|
1646 |
self.CurrentList = [] |
|
1647 |
self.IndexDictionary = {} |
|
1648 |
||
1649 |
def SetIndexDictionary(self, dictionary): |
|
1650 |
self.IndexDictionary = dictionary |
|
1651 |
||
1652 |
def SetCurrentList(self, list): |
|
1653 |
self.CurrentList = [] |
|
1654 |
self.CurrentList.extend(list) |
|
1655 |
self.CurrentList.sort() |
|
1656 |
||
1657 |
def GetCurrentList(self): |
|
1658 |
return self.CurrentList |
|
1659 |
||
1660 |
def RefreshLists(self): |
|
1661 |
self.PossibleIndexes.Clear() |
|
1662 |
self.CurrentIndexes.Clear() |
|
1663 |
self.AllList = [] |
|
1664 |
for index in self.IndexDictionary.iterkeys(): |
|
1665 |
if index not in self.CurrentList: |
|
1666 |
self.AllList.append(index) |
|
1667 |
self.AllList.sort() |
|
1668 |
for index in self.AllList: |
|
37 | 1669 |
self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) |
0 | 1670 |
for index in self.CurrentList: |
1671 |
if index in self.IndexDictionary: |
|
37 | 1672 |
self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) |
0 | 1673 |
|
1674 |
def OnPossibleIndexesDClick(self, event): |
|
1675 |
self.SelectPossible() |
|
1676 |
event.Skip() |
|
1677 |
||
1678 |
def OnCurrentIndexesDClick(self, event): |
|
1679 |
self.UnselectCurrent() |
|
1680 |
event.Skip() |
|
1681 |
||
1682 |
def OnSelectButton(self, event): |
|
1683 |
self.SelectPossible() |
|
1684 |
event.Skip() |
|
1685 |
||
1686 |
def OnUnselectButton(self, event): |
|
1687 |
self.UnselectCurrent() |
|
1688 |
event.Skip() |
|
1689 |
||
1690 |
def SelectPossible(self): |
|
1691 |
selected = self.PossibleIndexes.GetSelections() |
|
1692 |
for i in selected: |
|
1693 |
self.CurrentList.append(self.AllList[i]) |
|
1694 |
self.CurrentList.sort() |
|
1695 |
self.RefreshLists() |
|
1696 |
||
1697 |
def UnselectCurrent(self): |
|
1698 |
selected = self.CurrentIndexes.GetSelections() |
|
1699 |
for i in selected: |
|
1700 |
if not self.IndexDictionary[self.CurrentList[i]][1]: |
|
1701 |
self.CurrentList.pop(i) |
|
1702 |
self.CurrentList.sort() |
|
1703 |
self.RefreshLists() |
|
1704 |
||
1705 |
||
1706 |
||
1707 |
#------------------------------------------------------------------------------- |
|
1708 |
# Create Map Variable Dialog |
|
1709 |
#------------------------------------------------------------------------------- |
|
1710 |
||
1711 |
||
1712 |
[wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX, |
|
1713 |
wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL, |
|
1714 |
wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1, |
|
1715 |
wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3, |
|
1716 |
wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2, |
|
1717 |
wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4, |
|
1718 |
] = [wx.NewId() for _init_ctrls in range(12)] |
|
1719 |
||
1720 |
class MapVariableDialog(wx.Dialog): |
|
1721 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1722 |
# generated method, don't edit |
|
1723 |
||
1724 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1725 |
||
1726 |
def _init_sizers(self): |
|
1727 |
# generated method, don't edit |
|
1728 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1729 |
||
1730 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1731 |
||
1732 |
self.SetSizer(self.flexGridSizer1) |
|
1733 |
||
1734 |
def _init_ctrls(self, prnt): |
|
1735 |
# generated method, don't edit |
|
1736 |
wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG, |
|
1737 |
name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223), |
|
1738 |
size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE, |
|
1739 |
title='Add Map Variable') |
|
1740 |
self.SetClientSize(wx.Size(444, 186)) |
|
1741 |
||
1742 |
self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL, |
|
1743 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1744 |
size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL) |
|
1745 |
self.MainPanel.SetAutoLayout(True) |
|
1746 |
||
1747 |
self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1, |
|
59 | 1748 |
label='Index:', name='staticText1', parent=self.MainPanel, |
0 | 1749 |
pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
1750 |
||
39 | 1751 |
self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index', |
1752 |
parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152, |
|
1753 |
25), style=0, value='0x2000') |
|
1754 |
||
1755 |
self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3, |
|
59 | 1756 |
label='Name:', name='staticText3', parent=self.MainPanel, |
39 | 1757 |
pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0) |
1758 |
||
1759 |
self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME, |
|
1760 |
name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104), |
|
1761 |
size=wx.Size(152, 24), style=0, value='Undefined') |
|
1762 |
||
1763 |
self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2, |
|
59 | 1764 |
label='Type:', name='staticText2', parent=self.MainPanel, |
39 | 1765 |
pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0) |
1766 |
||
0 | 1767 |
self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1, |
1768 |
label='VAR', name='radioButton1', parent=self.MainPanel, |
|
39 | 1769 |
pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP) |
0 | 1770 |
self.radioButton1.SetValue(True) |
1771 |
self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click, |
|
1772 |
id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1) |
|
1773 |
||
1774 |
self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2, |
|
39 | 1775 |
label='ARRAY', name='radioButton2', parent=self.MainPanel, |
1776 |
pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE) |
|
0 | 1777 |
self.radioButton2.SetValue(False) |
1778 |
self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click, |
|
1779 |
id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2) |
|
1780 |
||
1781 |
self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3, |
|
39 | 1782 |
label='REC', name='radioButton3', parent=self.MainPanel, |
1783 |
pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE) |
|
0 | 1784 |
self.radioButton3.SetValue(False) |
1785 |
self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click, |
|
1786 |
id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3) |
|
1787 |
||
1788 |
self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4, |
|
59 | 1789 |
label='Number:', name='staticText4', parent=self.MainPanel, |
0 | 1790 |
pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0) |
1791 |
||
1792 |
self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER, |
|
1793 |
name='Number', parent=self.MainPanel, pos=wx.Point(312, 104), |
|
1794 |
size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0') |
|
1795 |
||
1796 |
self._init_sizers() |
|
1797 |
||
1798 |
def __init__(self, parent): |
|
1799 |
self._init_ctrls(parent) |
|
1800 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1801 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1802 |
self.staticText4.Enable(False) |
|
1803 |
self.Number.Enable(False) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1804 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1805 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
0 | 1806 |
|
39 | 1807 |
def SetIndex(self, index): |
1808 |
self.Index.SetValue("0x%04X"%index) |
|
1809 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1810 |
def OnOK(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1811 |
error = [] |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1812 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1813 |
int(self.Index.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1814 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1815 |
error.append("Index") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1816 |
if self.radioButton2.GetValue() or self.radioButton3.GetValue(): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1817 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1818 |
int(self.Number.GetValue()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1819 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1820 |
error.append("Number") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1821 |
if len(error) > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1822 |
text = "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1823 |
if len(error) > 1: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1824 |
suffix = "s" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1825 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1826 |
suffix = "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1827 |
for i, item in enumerate(error): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1828 |
if i == 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1829 |
text += item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1830 |
elif i == len(error) - 1: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1831 |
text += " and %s"%item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1832 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1833 |
text += ", %s"%item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1834 |
message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1835 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1836 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1837 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1838 |
self.EndModal(wxID_OK) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1839 |
|
0 | 1840 |
def GetValues(self): |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1841 |
name = self.IndexName.GetValue() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1842 |
index = int(self.Index.GetValue(), 16) |
0 | 1843 |
if self.radioButton1.GetValue(): |
1844 |
struct = 1 |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1845 |
number = None |
43 | 1846 |
elif self.radioButton2.GetValue(): |
1847 |
struct = 3 |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1848 |
number = int(self.Number.GetValue()) |
0 | 1849 |
elif self.radioButton3.GetValue(): |
1850 |
struct = 7 |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1851 |
number = int(self.Number.GetValue()) |
0 | 1852 |
return index, name, struct, number |
1853 |
||
1854 |
def OnRadioButton1Click(self, event): |
|
39 | 1855 |
self.EnableNumberTyping(False) |
0 | 1856 |
event.Skip() |
1857 |
||
1858 |
def OnRadioButton2Click(self, event): |
|
39 | 1859 |
self.EnableNumberTyping(True) |
0 | 1860 |
event.Skip() |
1861 |
||
1862 |
def OnRadioButton3Click(self, event): |
|
39 | 1863 |
self.EnableNumberTyping(True) |
1864 |
event.Skip() |
|
1865 |
||
1866 |
def EnableNumberTyping(self, enable): |
|
1867 |
self.staticText4.Enable(enable) |
|
1868 |
self.Number.Enable(enable) |
|
0 | 1869 |
|
1870 |
||
1871 |
#------------------------------------------------------------------------------- |
|
1872 |
# Create User Type Dialog |
|
1873 |
#------------------------------------------------------------------------------- |
|
1874 |
||
1875 |
||
1876 |
[wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL, |
|
1877 |
wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN, |
|
1878 |
wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1, |
|
1879 |
wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3, |
|
1880 |
wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE, |
|
1881 |
] = [wx.NewId() for _init_ctrls in range(11)] |
|
1882 |
||
1883 |
class UserTypeDialog(wx.Dialog): |
|
1884 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
1885 |
# generated method, don't edit |
|
1886 |
||
1887 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
1888 |
||
1889 |
def _init_sizers(self): |
|
1890 |
# generated method, don't edit |
|
1891 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
1892 |
||
1893 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
1894 |
||
1895 |
self.SetSizer(self.flexGridSizer1) |
|
1896 |
||
1897 |
def _init_ctrls(self, prnt): |
|
1898 |
# generated method, don't edit |
|
1899 |
wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog', |
|
1900 |
parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228), |
|
1901 |
style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type') |
|
1902 |
self.SetClientSize(wx.Size(444, 228)) |
|
1903 |
||
1904 |
self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL, |
|
1905 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
1906 |
size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL) |
|
1907 |
self.MainPanel.SetAutoLayout(True) |
|
1908 |
||
1909 |
self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1, |
|
59 | 1910 |
label='Type:', name='staticText1', parent=self.MainPanel, |
0 | 1911 |
pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
1912 |
||
1913 |
self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE, |
|
1914 |
name='Type', parent=self.MainPanel, pos=wx.Point(24, 48), |
|
1915 |
size=wx.Size(160, 24), style=0) |
|
1916 |
self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice, |
|
1917 |
id=wxID_USERTYPEDIALOGTYPE) |
|
1918 |
||
39 | 1919 |
self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1, |
1920 |
label='Values', name='staticBox1', parent=self.MainPanel, |
|
1921 |
pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0) |
|
1922 |
||
1923 |
self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2, |
|
59 | 1924 |
label='Minimum:', name='staticText2', parent=self.MainPanel, |
39 | 1925 |
pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0) |
1926 |
||
1927 |
self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min', |
|
1928 |
parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112, |
|
1929 |
24), style=wx.TE_RIGHT, value='0') |
|
1930 |
||
1931 |
self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3, |
|
59 | 1932 |
label='Maximum:', name='staticText3', parent=self.MainPanel, |
39 | 1933 |
pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0) |
1934 |
||
1935 |
self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max', |
|
1936 |
parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112, |
|
1937 |
25), style=wx.TE_RIGHT, value='0') |
|
1938 |
||
1939 |
self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4, |
|
59 | 1940 |
label='Length:', name='staticText4', parent=self.MainPanel, |
39 | 1941 |
pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0) |
1942 |
||
1943 |
self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length', |
|
1944 |
parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112, |
|
1945 |
25), style=wx.TE_RIGHT, value='0') |
|
1946 |
||
0 | 1947 |
self._init_sizers() |
1948 |
||
1949 |
def __init__(self, parent): |
|
1950 |
self._init_ctrls(parent) |
|
1951 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
1952 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
1953 |
self.TypeDictionary = {} |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1954 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1955 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1956 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1957 |
def OnOK(self, event): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1958 |
error = [] |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1959 |
good = True |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1960 |
firstmessage = "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1961 |
secondmessage = "" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1962 |
name = self.Type.GetStringSelection() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1963 |
if name != "": |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1964 |
valuetype = self.TypeDictionary[name][1] |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1965 |
if valuetype == 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1966 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1967 |
int(self.Min.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1968 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1969 |
error.append("Minimum") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1970 |
good = False |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1971 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1972 |
int(self.Max.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1973 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1974 |
error.append("Maximum") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1975 |
good = False |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1976 |
elif valuetype == 1: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1977 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1978 |
int(self.Length.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1979 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1980 |
error.append("Length") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1981 |
good = False |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1982 |
if len(error) > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1983 |
secondmessage = ". " |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1984 |
for i, item in enumerate(error): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1985 |
if i == 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1986 |
secondmessage += item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1987 |
elif i == len(error) - 1: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1988 |
secondmessage += " and %s"%item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1989 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1990 |
secondmessage += ", %s"%item |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1991 |
secondmessage += " must be integer" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1992 |
if len(error) > 1: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1993 |
secondmessage += "s" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1994 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1995 |
firstmessage = ". A type must be selected" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1996 |
good = False |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1997 |
if not good: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1998 |
message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
1999 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2000 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2001 |
self.Name.SetFocus() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2002 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2003 |
self.EndModal(wxID_OK) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2004 |
|
0 | 2005 |
def SetValues(self, min = None, max = None, length = None): |
2006 |
if min != None: |
|
2007 |
self.Min.SetValue(str(min)) |
|
2008 |
if max != None: |
|
2009 |
self.Max.SetValue(str(max)) |
|
2010 |
if length != None: |
|
2011 |
self.Length.SetValue(str(length)) |
|
2012 |
||
2013 |
def SetTypeList(self, typedic, type = None): |
|
2014 |
self.Type.Clear() |
|
2015 |
list = [] |
|
2016 |
for index, (name, valuetype) in typedic.iteritems(): |
|
2017 |
self.TypeDictionary[name] = (index, valuetype) |
|
2018 |
list.append((index, name)) |
|
2019 |
list.sort() |
|
2020 |
for index, name in list: |
|
2021 |
self.Type.Append(name) |
|
2022 |
if type != None: |
|
2023 |
self.Type.SetStringSelection(typedic[type][0]) |
|
2024 |
self.RefreshValues() |
|
2025 |
||
2026 |
def OnTypeChoice(self, event): |
|
2027 |
self.RefreshValues() |
|
2028 |
event.Skip() |
|
2029 |
||
2030 |
def RefreshValues(self): |
|
2031 |
name = self.Type.GetStringSelection() |
|
2032 |
if name != "": |
|
2033 |
valuetype = self.TypeDictionary[name][1] |
|
2034 |
if valuetype == 0: |
|
2035 |
self.staticText2.Enable(True) |
|
2036 |
self.staticText3.Enable(True) |
|
2037 |
self.staticText4.Enable(False) |
|
2038 |
self.Min.Enable(True) |
|
2039 |
self.Max.Enable(True) |
|
2040 |
self.Length.Enable(False) |
|
2041 |
elif valuetype == 1: |
|
2042 |
self.staticText2.Enable(False) |
|
2043 |
self.staticText3.Enable(False) |
|
2044 |
self.staticText4.Enable(True) |
|
2045 |
self.Min.Enable(False) |
|
2046 |
self.Max.Enable(False) |
|
2047 |
self.Length.Enable(True) |
|
2048 |
else: |
|
2049 |
self.staticText2.Enable(False) |
|
2050 |
self.staticText3.Enable(False) |
|
2051 |
self.staticText4.Enable(False) |
|
2052 |
self.Min.Enable(False) |
|
2053 |
self.Max.Enable(False) |
|
2054 |
self.Length.Enable(False) |
|
2055 |
||
2056 |
def GetValues(self): |
|
2057 |
name = self.Type.GetStringSelection() |
|
2058 |
type = self.TypeDictionary[name][0] |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2059 |
min = int(self.Min.GetValue()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2060 |
max = int(self.Max.GetValue()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2061 |
length = int(self.Length.GetValue()) |
0 | 2062 |
return type, min, max, length |
2063 |
||
2064 |
||
2065 |
||
2066 |
#------------------------------------------------------------------------------- |
|
2067 |
# Editing Node Infos Dialog |
|
2068 |
#------------------------------------------------------------------------------- |
|
2069 |
||
2070 |
||
2071 |
[wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, |
|
2072 |
wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2073 |
wxID_NODEINFOSDIALOGDESCRIPTION, wxID_NODEINFOSDIALOGSTATICTEXT1, |
0 | 2074 |
wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, |
2075 |
wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, |
|
2076 |
] = [wx.NewId() for _init_ctrls in range(10)] |
|
2077 |
||
2078 |
class NodeInfosDialog(wx.Dialog): |
|
2079 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
2080 |
# generated method, don't edit |
|
2081 |
||
2082 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
2083 |
||
2084 |
def _init_sizers(self): |
|
2085 |
# generated method, don't edit |
|
2086 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
2087 |
||
2088 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
2089 |
||
2090 |
self.SetSizer(self.flexGridSizer1) |
|
2091 |
||
2092 |
def _init_ctrls(self, prnt): |
|
2093 |
# generated method, don't edit |
|
2094 |
wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG, |
|
2095 |
name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223), |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2096 |
size=wx.Size(300, 300), style=wx.DEFAULT_DIALOG_STYLE, |
0 | 2097 |
title='Node Infos') |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2098 |
self.SetClientSize(wx.Size(300, 300)) |
0 | 2099 |
|
2100 |
self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL, |
|
2101 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2102 |
size=wx.Size(280, 264), style=wx.TAB_TRAVERSAL) |
0 | 2103 |
self.MainPanel.SetAutoLayout(True) |
2104 |
||
2105 |
self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1, |
|
59 | 2106 |
label='Name:', |
2107 |
name='staticText1', parent=self.MainPanel, |
|
0 | 2108 |
pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
2109 |
||
39 | 2110 |
self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name', |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2111 |
parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(250, |
39 | 2112 |
25), style=0, value='') |
2113 |
||
0 | 2114 |
self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2, |
59 | 2115 |
label='Node ID:', name='staticText2', parent=self.MainPanel, |
0 | 2116 |
pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) |
2117 |
||
39 | 2118 |
self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID', |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2119 |
parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(250, |
39 | 2120 |
25), style=wx.TE_RIGHT, value='') |
2121 |
||
0 | 2122 |
self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3, |
59 | 2123 |
label='Type:', name='staticText3', parent=self.MainPanel, |
0 | 2124 |
pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) |
2125 |
||
2126 |
self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE, |
|
2127 |
name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2128 |
size=wx.Size(250, 25), style=0) |
0 | 2129 |
|
2130 |
self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4, |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2131 |
label='Description:', name='staticText4', parent=self.MainPanel, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2132 |
pos=wx.Point(24, 192), size=wx.Size(71, 17), style=0) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2133 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2134 |
self.Description = wx.TextCtrl(id=wxID_NODEINFOSDIALOGDESCRIPTION, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2135 |
name='Description', parent=self.MainPanel, pos=wx.Point(24, 216), |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2136 |
size=wx.Size(250, 25), style=0, value='') |
0 | 2137 |
|
2138 |
self._init_sizers() |
|
2139 |
||
2140 |
def __init__(self, parent): |
|
2141 |
self._init_ctrls(parent) |
|
2142 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
2143 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
2144 |
self.Type.Append("master") |
|
2145 |
self.Type.Append("slave") |
|
59 | 2146 |
|
2147 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
2148 |
||
2149 |
def OnOK(self, event): |
|
2150 |
name = self.Name.GetValue() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2151 |
message = "" |
59 | 2152 |
if name != "": |
2153 |
good = not name[0].isdigit() |
|
2154 |
for item in name.split("_"): |
|
2155 |
good &= item.isalnum() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2156 |
if not good: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2157 |
message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2158 |
if message != "": |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2159 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2160 |
nodeid = int(self.NodeID.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2161 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2162 |
message = "Node ID must be integer!" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2163 |
if message != "": |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2164 |
message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR) |
59 | 2165 |
message.ShowModal() |
2166 |
message.Destroy() |
|
2167 |
self.Name.SetFocus() |
|
2168 |
else: |
|
2169 |
self.EndModal(wxID_OK) |
|
0 | 2170 |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2171 |
def SetValues(self, name, id, type, description): |
0 | 2172 |
self.Name.SetValue(name) |
2173 |
self.NodeID.SetValue("0x%02X"%id) |
|
2174 |
self.Type.SetStringSelection(type) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2175 |
self.Description.SetValue(description) |
0 | 2176 |
|
2177 |
def GetValues(self): |
|
2178 |
name = self.Name.GetValue() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2179 |
nodeid = int(self.NodeID.GetValue(), 16) |
0 | 2180 |
type = self.Type.GetStringSelection() |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2181 |
description = self.Description.GetValue() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2182 |
return name, nodeid, type, description |
0 | 2183 |
|
2184 |
||
2185 |
||
2186 |
#------------------------------------------------------------------------------- |
|
2187 |
# Create New Node Dialog |
|
2188 |
#------------------------------------------------------------------------------- |
|
2189 |
||
2190 |
||
2191 |
[wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY, |
|
2192 |
wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL, |
|
2193 |
wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT, |
|
2194 |
wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, |
|
2195 |
wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, |
|
2196 |
wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, |
|
2197 |
wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, |
|
2198 |
wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2199 |
wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTATICTEXT7, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2200 |
wxID_CREATENODEDIALOGSTOREEDS, wxID_CREATENODEDIALOGDESCRIPTION, |
0 | 2201 |
wxID_CREATENODEDIALOGTYPE, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2202 |
] = [wx.NewId() for _init_ctrls in range(21)] |
0 | 2203 |
|
2204 |
class CreateNodeDialog(wx.Dialog): |
|
2205 |
def _init_coll_flexGridSizer1_Items(self, parent): |
|
2206 |
# generated method, don't edit |
|
2207 |
||
2208 |
parent.AddWindow(self.MainPanel, 0, border=0, flag=0) |
|
2209 |
||
2210 |
def _init_sizers(self): |
|
2211 |
# generated method, don't edit |
|
2212 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
|
2213 |
||
2214 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
|
2215 |
||
2216 |
self.SetSizer(self.flexGridSizer1) |
|
2217 |
||
2218 |
def _init_ctrls(self, prnt): |
|
2219 |
# generated method, don't edit |
|
2220 |
wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG, |
|
2221 |
name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223), |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2222 |
size=wx.Size(451, 376), style=wx.DEFAULT_DIALOG_STYLE, |
0 | 2223 |
title='Create a new Node') |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2224 |
self.SetClientSize(wx.Size(451, 376)) |
0 | 2225 |
|
2226 |
self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL, |
|
2227 |
name='MainPanel', parent=self, pos=wx.Point(0, 0), |
|
2228 |
size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL) |
|
2229 |
self.MainPanel.SetAutoLayout(True) |
|
2230 |
||
2231 |
self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1, |
|
59 | 2232 |
label='Name:', name='staticText1', parent=self.MainPanel, |
0 | 2233 |
pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0) |
2234 |
||
2235 |
self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2, |
|
59 | 2236 |
label='Node ID:', name='staticText2', parent=self.MainPanel, |
0 | 2237 |
pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0) |
2238 |
||
2239 |
self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3, |
|
59 | 2240 |
label='Type:', name='staticText3', parent=self.MainPanel, |
0 | 2241 |
pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0) |
2242 |
||
2243 |
self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE, |
|
2244 |
name='Type', parent=self.MainPanel, pos=wx.Point(24, 160), |
|
2245 |
size=wx.Size(200, 24), style=0) |
|
2246 |
||
2247 |
self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name', |
|
2248 |
parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200, |
|
2249 |
25), style=0, value='') |
|
2250 |
||
2251 |
self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID', |
|
2252 |
parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200, |
|
2253 |
25), style=wx.TE_RIGHT, value='') |
|
2254 |
||
2255 |
self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4, |
|
59 | 2256 |
label='Profile:', name='staticText4', parent=self.MainPanel, |
0 | 2257 |
pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0) |
2258 |
||
2259 |
self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE, |
|
2260 |
name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216), |
|
2261 |
size=wx.Size(200, 24), style=0) |
|
2262 |
self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice, |
|
2263 |
id=wxID_CREATENODEDIALOGPROFILE) |
|
2264 |
||
2265 |
self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5, |
|
59 | 2266 |
label='Network Management:', name='staticText5', |
0 | 2267 |
parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152, |
2268 |
16), style=0) |
|
2269 |
||
2270 |
self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE, |
|
2271 |
label='None', name='NMT_None', parent=self.MainPanel, |
|
2272 |
pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0) |
|
2273 |
self.NMT_None.SetValue(True) |
|
2274 |
||
2275 |
self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING, |
|
2276 |
label='Node Guarding', name='NMT_NodeGuarding', |
|
2277 |
parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128, |
|
2278 |
24), style=0) |
|
2279 |
self.NMT_NodeGuarding.SetValue(False) |
|
2280 |
||
2281 |
self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT, |
|
2282 |
label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel, |
|
2283 |
pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0) |
|
2284 |
self.NMT_Heartbeat.SetValue(False) |
|
2285 |
||
2286 |
self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6, |
|
59 | 2287 |
label='Options:', name='staticText6', parent=self.MainPanel, |
0 | 2288 |
pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0) |
2289 |
||
2290 |
self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, |
|
2291 |
label='DS-302 Profile', name='DS302', parent=self.MainPanel, |
|
2292 |
pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0) |
|
2293 |
self.DS302.SetValue(False) |
|
176 | 2294 |
#self.DS302.Enable(False) |
0 | 2295 |
|
2296 |
self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC, |
|
2297 |
label='Generate SYNC', name='GenSYNC', parent=self.MainPanel, |
|
2298 |
pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0) |
|
2299 |
self.GenSYNC.SetValue(False) |
|
2300 |
||
2301 |
self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY, |
|
2302 |
label='Emergency support', name='Emergency', |
|
2303 |
parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152, |
|
2304 |
24), style=0) |
|
2305 |
self.Emergency.SetValue(False) |
|
59 | 2306 |
self.Emergency.Enable(False) |
0 | 2307 |
|
2308 |
self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG, |
|
2309 |
label='Save Configuration', name='SaveConfig', |
|
2310 |
parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152, |
|
2311 |
24), style=0) |
|
2312 |
self.SaveConfig.SetValue(False) |
|
59 | 2313 |
self.SaveConfig.Enable(False) |
2314 |
||
2315 |
# self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS, |
|
2316 |
# label='Store EDS', name='StoreEDS', parent=self.MainPanel, |
|
2317 |
# pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0) |
|
2318 |
# self.StoreEDS.SetValue(False) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2319 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2320 |
self.staticText7 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT7, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2321 |
label='Description:', name='staticText7', parent=self.MainPanel, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2322 |
pos=wx.Point(24, 248), size=wx.Size(71, 17), style=0) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2323 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2324 |
self.Description = wx.TextCtrl(id=wxID_CREATENODEDIALOGDESCRIPTION, |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2325 |
name='Description', parent=self.MainPanel, pos=wx.Point(24, 272), |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2326 |
size=wx.Size(400, 25), style=0, value='') |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2327 |
|
0 | 2328 |
self._init_sizers() |
2329 |
||
2330 |
def __init__(self, parent): |
|
2331 |
self._init_ctrls(parent) |
|
2332 |
self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL) |
|
2333 |
self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER) |
|
59 | 2334 |
self.NodeID.SetValue("0x00") |
0 | 2335 |
self.Type.Append("master") |
2336 |
self.Type.Append("slave") |
|
2337 |
self.Type.SetStringSelection("slave") |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2338 |
self.Description.SetValue("") |
0 | 2339 |
self.ListProfile = {"None" : ""} |
2340 |
self.Profile.Append("None") |
|
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
|
2341 |
self.Directory = os.path.join(ScriptDirectory, "config") |
0 | 2342 |
listfiles = os.listdir(self.Directory) |
2343 |
listfiles.sort() |
|
2344 |
for item in listfiles: |
|
2345 |
name, extend = os.path.splitext(item) |
|
2346 |
if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302": |
|
2347 |
self.ListProfile[name] = os.path.join(self.Directory, item) |
|
2348 |
self.Profile.Append(name) |
|
2349 |
self.Profile.Append("Other") |
|
2350 |
self.Profile.SetStringSelection("None") |
|
59 | 2351 |
self.Name.SetFocus() |
2352 |
||
2353 |
EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK) |
|
2354 |
||
2355 |
def OnOK(self, event): |
|
2356 |
name = self.Name.GetValue() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2357 |
message = "" |
59 | 2358 |
if name != "": |
2359 |
good = not name[0].isdigit() |
|
2360 |
for item in name.split("_"): |
|
2361 |
good &= item.isalnum() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2362 |
if not good: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2363 |
message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2364 |
if message != "": |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2365 |
try: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2366 |
nodeid = int(self.NodeID.GetValue(), 16) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2367 |
except: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2368 |
message = "Node ID must be an integer!" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2369 |
if message != "": |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2370 |
message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR) |
59 | 2371 |
message.ShowModal() |
2372 |
message.Destroy() |
|
2373 |
self.Name.SetFocus() |
|
2374 |
else: |
|
2375 |
self.EndModal(wxID_OK) |
|
0 | 2376 |
|
2377 |
def GetValues(self): |
|
2378 |
name = self.Name.GetValue() |
|
2379 |
nodeid = 0 |
|
2380 |
if self.NodeID.GetValue() != "": |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2381 |
nodeid = int(self.NodeID.GetValue(), 16) |
0 | 2382 |
type = self.Type.GetStringSelection() |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2383 |
description = self.Description.GetValue() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
2384 |
return name, nodeid, type, description |
0 | 2385 |
|
2386 |
def GetProfile(self): |
|
2387 |
name = self.Profile.GetStringSelection() |
|
2388 |
return name, self.ListProfile[name] |
|
2389 |
||
2390 |
def GetNMTManagement(self): |
|
2391 |
if self.NMT_None.GetValue(): |
|
2392 |
return "None" |
|
2393 |
elif self.NMT_NodeGuarding.GetValue(): |
|
2394 |
return "NodeGuarding" |
|
2395 |
elif self.NMT_Heartbeat.GetValue(): |
|
2396 |
return "Heartbeat" |
|
2397 |
return None |
|
2398 |
||
2399 |
def GetOptions(self): |
|
2400 |
options = [] |
|
2401 |
if self.DS302.GetValue(): |
|
2402 |
options.append("DS302") |
|
2403 |
if self.GenSYNC.GetValue(): |
|
2404 |
options.append("GenSYNC") |
|
2405 |
if self.Emergency.GetValue(): |
|
2406 |
options.append("Emergency") |
|
2407 |
if self.SaveConfig.GetValue(): |
|
2408 |
options.append("SaveConfig") |
|
59 | 2409 |
# if self.StoreEDS.GetValue(): |
2410 |
# options.append("StoreEDS") |
|
0 | 2411 |
return options |
2412 |
||
2413 |
def OnProfileChoice(self, event): |
|
2414 |
if self.Profile.GetStringSelection() == "Other": |
|
59 | 2415 |
dialog = wxFileDialog(self, "Choose a file", self.Directory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR) |
0 | 2416 |
dialog.ShowModal() |
2417 |
filepath = dialog.GetPath() |
|
2418 |
dialog.Destroy() |
|
2419 |
if os.path.isfile(filepath): |
|
2420 |
name = os.path.splitext(os.path.basename(filepath))[0] |
|
2421 |
self.ListProfile[name] = filepath |
|
2422 |
length = self.Profile.GetCount() |
|
2423 |
self.Profile.Insert(name, length - 2) |
|
2424 |
self.Profile.SetStringSelection(name) |
|
2425 |
else: |
|
2426 |
self.Profile.SetStringSelection("None") |
|
2427 |
event.Skip() |
|
2428 |
||
2429 |
||
2430 |
#------------------------------------------------------------------------------- |
|
2431 |
# Exception Handler |
|
2432 |
#------------------------------------------------------------------------------- |
|
2433 |
||
2434 |
Max_Traceback_List_Size = 20 |
|
2435 |
||
2436 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
2437 |
trcbck_lst = [] |
|
2438 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
2439 |
trcbck = " " + str(i+1) + ". " |
|
2440 |
if line[0].find(os.getcwd()) == -1: |
|
2441 |
trcbck += "file : " + str(line[0]) + ", " |
|
2442 |
else: |
|
2443 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
2444 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
2445 |
trcbck_lst.append(trcbck) |
|
2446 |
||
2447 |
# Allow clicking.... |
|
2448 |
cap = wx.Window_GetCapture() |
|
2449 |
if cap: |
|
2450 |
cap.ReleaseMouse() |
|
2451 |
||
2452 |
dlg = wx.SingleChoiceDialog(None, |
|
2453 |
""" |
|
2454 |
An error happens. |
|
2455 |
||
2456 |
Click on OK for saving an error report. |
|
2457 |
||
2458 |
Please contact LOLITech at: |
|
2459 |
+33 (0)3 29 52 95 67 |
|
2460 |
bugs_objdictedit@lolitech.fr |
|
2461 |
||
2462 |
||
2463 |
Error: |
|
2464 |
""" + |
|
2465 |
str(e_type) + " : " + str(e_value), |
|
2466 |
"Error", |
|
2467 |
trcbck_lst) |
|
2468 |
try: |
|
2469 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
2470 |
finally: |
|
2471 |
dlg.Destroy() |
|
2472 |
||
2473 |
return res |
|
2474 |
||
2475 |
def Display_Error_Dialog(e_value): |
|
2476 |
message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) |
|
2477 |
message.ShowModal() |
|
2478 |
message.Destroy() |
|
2479 |
||
2480 |
def get_last_traceback(tb): |
|
2481 |
while tb.tb_next: |
|
2482 |
tb = tb.tb_next |
|
2483 |
return tb |
|
2484 |
||
2485 |
||
2486 |
def format_namespace(d, indent=' '): |
|
2487 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
2488 |
||
2489 |
||
2490 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
2491 |
||
2492 |
def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
|
2493 |
||
2494 |
def handle_exception(e_type, e_value, e_traceback): |
|
2495 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
2496 |
last_tb = get_last_traceback(e_traceback) |
|
2497 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
2498 |
if str(e_value).startswith("!!!"): |
|
2499 |
Display_Error_Dialog(e_value) |
|
2500 |
elif ex not in ignored_exceptions: |
|
2501 |
ignored_exceptions.append(ex) |
|
2502 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
2503 |
if result: |
|
2504 |
info = { |
|
2505 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
2506 |
'app-version' : app_version, |
|
2507 |
'wx-version' : wx.VERSION_STRING, |
|
2508 |
'wx-platform' : wx.Platform, |
|
2509 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
2510 |
'platform' : platform.platform(), |
|
2511 |
'e-type' : e_type, |
|
2512 |
'e-value' : e_value, |
|
2513 |
'date' : time.ctime(), |
|
2514 |
'cwd' : os.getcwd(), |
|
2515 |
} |
|
2516 |
if e_traceback: |
|
2517 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
2518 |
last_tb = get_last_traceback(e_traceback) |
|
2519 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
2520 |
info['locals'] = format_namespace(exception_locals) |
|
2521 |
if 'self' in exception_locals: |
|
2522 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
2523 |
||
2524 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
2525 |
lst = info.keys() |
|
2526 |
lst.sort() |
|
2527 |
for a in lst: |
|
2528 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
2529 |
||
2530 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
2531 |
sys.excepthook = handle_exception |
|
2532 |
||
2533 |
if __name__ == '__main__': |
|
2534 |
app = wxPySimpleApp() |
|
2535 |
wxInitAllImageHandlers() |
|
2536 |
||
2537 |
# Install a exception handle for bug reports |
|
2538 |
wxAddExceptHook(os.getcwd(),__version__) |
|
2539 |
||
2540 |
frame = objdictedit(None) |
|
2541 |
||
2542 |
frame.Show() |
|
2543 |
app.MainLoop() |