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