2 # -*- coding: utf-8 -*-
4 #This file is part of CanFestival, a library implementing CanOpen Stack.
6 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
8 #See COPYING file for copyrights details.
10 #This library is free software; you can redistribute it and/or
11 #modify it under the terms of the GNU Lesser General Public
12 #License as published by the Free Software Foundation; either
13 #version 2.1 of the License, or (at your option) any later version.
15 #This library is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 #Lesser General Public License for more details.
20 #You should have received a copy of the GNU Lesser General Public
21 #License along with this library; if not, write to the Free Software
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 ScriptDirectory = os.path.split(__file__)[0]
30 #-------------------------------------------------------------------------------
31 # Editing Communication Dialog
32 #-------------------------------------------------------------------------------
35 [ID_COMMUNICATIONDIALOG, ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
36 ID_COMMUNICATIONDIALOGCURRENTINDEXES, ID_COMMUNICATIONDIALOGSELECT,
37 ID_COMMUNICATIONDIALOGUNSELECT, ID_COMMUNICATIONDIALOGSTATICTEXT1,
38 ID_COMMUNICATIONDIALOGSTATICTEXT2
39 ] = [wx.NewId() for _init_ctrls in range(7)]
41 class CommunicationDialog(wx.Dialog):
42 def _init_coll_flexGridSizer1_Items(self, parent):
43 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
44 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
46 def _init_coll_flexGridSizer1_Growables(self, parent):
47 parent.AddGrowableCol(0)
48 parent.AddGrowableRow(0)
50 def _init_coll_MainSizer_Items(self, parent):
51 parent.AddSizer(self.LeftGridSizer, 0, border=0, flag=wx.GROW)
52 parent.AddSizer(self.MiddleGridSizer, 0, border=0, flag=wx.GROW)
53 parent.AddSizer(self.RightGridSizer, 0, border=0, flag=wx.GROW)
55 def _init_coll_MainSizer_Growables(self, parent):
56 parent.AddGrowableCol(0)
57 parent.AddGrowableCol(2)
58 parent.AddGrowableRow(0)
60 def _init_coll_LeftGridSizer_Items(self, parent):
61 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
62 parent.AddWindow(self.PossibleIndexes, 0, border=0, flag=wx.GROW)
64 def _init_coll_LeftGridSizer_Growables(self, parent):
65 parent.AddGrowableCol(0)
66 parent.AddGrowableRow(1)
68 def _init_coll_MiddleGridSizer_Items(self, parent):
69 parent.AddWindow(self.Select, 0, border=0, flag=wx.ALIGN_BOTTOM)
70 parent.AddWindow(self.Unselect, 0, border=0, flag=wx.ALIGN_TOP)
72 def _init_coll_MiddleGridSizer_Growables(self, parent):
73 parent.AddGrowableCol(0)
74 parent.AddGrowableRow(0)
75 parent.AddGrowableRow(1)
77 def _init_coll_RightGridSizer_Items(self, parent):
78 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
79 parent.AddWindow(self.CurrentIndexes, 0, border=0, flag=wx.GROW)
81 def _init_coll_RightGridSizer_Growables(self, parent):
82 parent.AddGrowableCol(0)
83 parent.AddGrowableRow(1)
85 def _init_sizers(self):
86 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
87 self.MainSizer = wx.FlexGridSizer(cols=3, hgap=15, rows=1, vgap=0)
88 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
89 self.MiddleGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=40)
90 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
92 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
93 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
94 self._init_coll_MainSizer_Items(self.MainSizer)
95 self._init_coll_MainSizer_Growables(self.MainSizer)
96 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
97 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
98 self._init_coll_MiddleGridSizer_Items(self.MiddleGridSizer)
99 self._init_coll_MiddleGridSizer_Growables(self.MiddleGridSizer)
100 self._init_coll_RightGridSizer_Items(self.RightGridSizer)
101 self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
103 self.SetSizer(self.flexGridSizer1)
105 def _init_ctrls(self, prnt):
106 wx.Dialog.__init__(self, id=ID_COMMUNICATIONDIALOG,
107 name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216),
108 size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
109 title='Edit Communication Profile')
110 self.SetClientSize(wx.Size(726, 437))
112 self.staticText1 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT1,
113 label='Possible Profile Indexes:', name='staticText1',
114 parent=self, pos=wx.Point(0, 0), size=wx.Size(0,
117 self.PossibleIndexes = wx.ListBox(choices=[],
118 id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
119 name='PossibleIndexes', parent=self, pos=wx.Point(0, 0),
120 size=wx.Size(0, 0), style=wx.LB_EXTENDED)
121 self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick,
122 id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES)
124 self.Select = wx.Button(id=ID_COMMUNICATIONDIALOGSELECT, label='>>',
125 name='Select', parent=self, pos=wx.Point(0, 0),
126 size=wx.Size(32, 32), style=0)
127 self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton,
128 id=ID_COMMUNICATIONDIALOGSELECT)
130 self.Unselect = wx.Button(id=ID_COMMUNICATIONDIALOGUNSELECT,
131 label='<<', name='Unselect', parent=self,
132 pos=wx.Point(0, 0), size=wx.Size(32, 32), style=0)
133 self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton,
134 id=ID_COMMUNICATIONDIALOGUNSELECT)
136 self.staticText2 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT2,
137 label='Current Profile Indexes:', name='staticText2',
138 parent=self, pos=wx.Point(0, 0), size=wx.Size(0,
141 self.CurrentIndexes = wx.ListBox(choices=[],
142 id=ID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes',
143 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 0),
144 style=wx.LB_EXTENDED)
145 self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick,
146 id=ID_COMMUNICATIONDIALOGCURRENTINDEXES)
148 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
152 def __init__(self, parent):
153 self._init_ctrls(parent)
155 self.CurrentList = []
156 self.IndexDictionary = {}
158 def SetIndexDictionary(self, dictionary):
159 self.IndexDictionary = dictionary
161 def SetCurrentList(self, list):
162 self.CurrentList = []
163 self.CurrentList.extend(list)
164 self.CurrentList.sort()
166 def GetCurrentList(self):
167 return self.CurrentList
169 def RefreshLists(self):
170 self.PossibleIndexes.Clear()
171 self.CurrentIndexes.Clear()
173 for index in self.IndexDictionary.iterkeys():
174 if index not in self.CurrentList:
175 self.AllList.append(index)
177 for index in self.AllList:
178 self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0]))
179 for index in self.CurrentList:
180 if index in self.IndexDictionary:
181 self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0]))
183 def OnPossibleIndexesDClick(self, event):
184 self.SelectPossible()
187 def OnCurrentIndexesDClick(self, event):
188 self.UnselectCurrent()
191 def OnSelectButton(self, event):
192 self.SelectPossible()
195 def OnUnselectButton(self, event):
196 self.UnselectCurrent()
199 def SelectPossible(self):
200 selected = self.PossibleIndexes.GetSelections()
202 self.CurrentList.append(self.AllList[i])
203 self.CurrentList.sort()
206 def UnselectCurrent(self):
207 selected = self.CurrentIndexes.GetSelections()
209 if not self.IndexDictionary[self.CurrentList[i]][1]:
210 self.CurrentList.pop(i)
211 self.CurrentList.sort()
216 #-------------------------------------------------------------------------------
217 # Create Map Variable Dialog
218 #-------------------------------------------------------------------------------
221 [ID_MAPVARIABLEDIALOG, ID_MAPVARIABLEDIALOGINDEX,
222 ID_MAPVARIABLEDIALOGINDEXNAME, ID_MAPVARIABLEDIALOGSPACER,
223 ID_MAPVARIABLEDIALOGNUMBER, ID_MAPVARIABLEDIALOGRADIOBUTTON1,
224 ID_MAPVARIABLEDIALOGRADIOBUTTON2, ID_MAPVARIABLEDIALOGRADIOBUTTON3,
225 ID_MAPVARIABLEDIALOGSTATICTEXT1, ID_MAPVARIABLEDIALOGSTATICTEXT2,
226 ID_MAPVARIABLEDIALOGSTATICTEXT3, ID_MAPVARIABLEDIALOGSTATICTEXT4,
227 ] = [wx.NewId() for _init_ctrls in range(12)]
229 class MapVariableDialog(wx.Dialog):
230 def _init_coll_flexGridSizer1_Items(self, parent):
231 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
232 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
234 def _init_coll_flexGridSizer1_Growables(self, parent):
235 parent.AddGrowableCol(0)
236 parent.AddGrowableRow(0)
238 def _init_coll_MainSizer_Items(self, parent):
239 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
240 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
241 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
242 parent.AddWindow(self.Index, 0, border=0, flag=wx.GROW)
243 parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW)
244 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
245 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
246 parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW)
247 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
248 parent.AddWindow(self.IndexName, 0, border=0, flag=wx.GROW)
249 parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW)
250 parent.AddWindow(self.Number, 0, border=0, flag=wx.GROW)
252 def _init_coll_MainSizer_Growables(self, parent):
253 parent.AddGrowableCol(0)
254 parent.AddGrowableCol(2)
256 def _init_sizers(self):
257 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
258 self.MainSizer = wx.FlexGridSizer(cols=3, hgap=30, rows=4, vgap=5)
260 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
261 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
262 self._init_coll_MainSizer_Items(self.MainSizer)
263 self._init_coll_MainSizer_Growables(self.MainSizer)
265 self.SetSizer(self.flexGridSizer1)
267 def _init_ctrls(self, prnt):
268 wx.Dialog.__init__(self, id=ID_MAPVARIABLEDIALOG,
269 name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
270 size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
271 title='Add Map Variable')
272 self.SetClientSize(wx.Size(444, 186))
274 self.staticText1 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT1,
275 label='Index:', name='staticText1', parent=self,
276 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
278 self.staticText2 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT2,
279 label='Type:', name='staticText2', parent=self,
280 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
282 self.staticText3 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT3,
283 label='Name:', name='staticText3', parent=self,
284 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
286 self.staticText4 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT4,
287 label='Number:', name='staticText4', parent=self,
288 pos=wx.Point(0, 0), size=wx.Size(0, 16), style=0)
290 self.radioButton1 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON1,
291 label='VAR', name='radioButton1', parent=self,
292 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_GROUP)
293 self.radioButton1.SetValue(True)
294 self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click,
295 id=ID_MAPVARIABLEDIALOGRADIOBUTTON1)
297 self.radioButton2 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON2,
298 label='ARRAY', name='radioButton2', parent=self,
299 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
300 self.radioButton2.SetValue(False)
301 self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click,
302 id=ID_MAPVARIABLEDIALOGRADIOBUTTON2)
304 self.radioButton3 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON3,
305 label='REC', name='radioButton3', parent=self,
306 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
307 self.radioButton3.SetValue(False)
308 self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click,
309 id=ID_MAPVARIABLEDIALOGRADIOBUTTON3)
311 self.Index = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEX, name='Index',
312 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
313 style=0, value='0x2000')
315 self.IndexName = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEXNAME,
316 name='IndexName', parent=self, pos=wx.Point(0, 0),
317 size=wx.Size(0, 24), style=0, value='Undefined')
319 self.Number = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGNUMBER,
320 name='Number', parent=self, pos=wx.Point(0, 0),
321 size=wx.Size(0, 24), style=wx.TE_RIGHT, value='0')
323 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
324 name='Spacer', parent=self, pos=wx.Point(0, 0),
325 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
327 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
328 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
332 def __init__(self, parent):
333 self._init_ctrls(parent)
334 self.staticText4.Enable(False)
335 self.Number.Enable(False)
337 def SetIndex(self, index):
338 self.Index.SetValue("0x%04X"%index)
340 def OnOK(self, event):
343 int(self.Index.GetValue(), 16)
345 error.append("Index")
346 if self.radioButton2.GetValue() or self.radioButton3.GetValue():
348 int(self.Number.GetValue())
350 error.append("Number")
357 for i, item in enumerate(error):
360 elif i == len(error) - 1:
361 text += " and %s"%item
364 message = wx.MessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wx.OK|wx.ICON_ERROR)
368 self.EndModal(wx.ID_OK)
371 name = self.IndexName.GetValue()
372 index = int(self.Index.GetValue(), 16)
373 if self.radioButton1.GetValue():
376 elif self.radioButton2.GetValue():
378 number = int(self.Number.GetValue())
379 elif self.radioButton3.GetValue():
381 number = int(self.Number.GetValue())
382 return index, name, struct, number
384 def OnRadioButton1Click(self, event):
385 self.EnableNumberTyping(False)
388 def OnRadioButton2Click(self, event):
389 self.EnableNumberTyping(True)
392 def OnRadioButton3Click(self, event):
393 self.EnableNumberTyping(True)
396 def EnableNumberTyping(self, enable):
397 self.staticText4.Enable(enable)
398 self.Number.Enable(enable)
401 #-------------------------------------------------------------------------------
402 # Create User Type Dialog
403 #-------------------------------------------------------------------------------
406 [ID_USERTYPEDIALOG, ID_USERTYPEDIALOGSPACER,
407 ID_USERTYPEDIALOGTYPE, ID_USERTYPEDIALOGMAX,
408 ID_USERTYPEDIALOGMIN, ID_USERTYPEDIALOGLENGTH,
409 ID_USERTYPEDIALOGSTATICBOX1, ID_USERTYPEDIALOGSTATICTEXT1,
410 ID_USERTYPEDIALOGSTATICTEXT2, ID_USERTYPEDIALOGSTATICTEXT3,
411 ID_USERTYPEDIALOGSTATICTEXT4,
412 ] = [wx.NewId() for _init_ctrls in range(11)]
414 class UserTypeDialog(wx.Dialog):
415 def _init_coll_flexGridSizer1_Items(self, parent):
416 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
417 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
419 def _init_coll_flexGridSizer1_Growables(self, parent):
420 parent.AddGrowableCol(0)
421 parent.AddGrowableRow(0)
423 def _init_coll_MainSizer_Items(self, parent):
424 parent.AddSizer(self.LeftGridSizer, 2, border=5, flag=wx.GROW|wx.RIGHT)
425 parent.AddSizer(self.RightBoxSizer, 3, border=5, flag=wx.GROW|wx.LEFT)
427 def _init_coll_LeftGridSizer_Items(self, parent):
428 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
429 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
430 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
432 def _init_coll_LeftGridSizer_Growables(self, parent):
433 parent.AddGrowableCol(0)
434 parent.AddGrowableRow(2)
436 def _init_coll_RightBoxSizer_Items(self, parent):
437 parent.AddSizer(self.RightBoxGridSizer, 0, border=10, flag=wx.GROW|wx.ALL)
439 def _init_coll_RightBoxGridSizer_Items(self, parent):
440 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
441 parent.AddWindow(self.Min, 0, border=0, flag=wx.GROW)
442 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
443 parent.AddWindow(self.Max, 0, border=0, flag=wx.GROW)
444 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
445 parent.AddWindow(self.Length, 0, border=0, flag=wx.GROW)
447 def _init_coll_RightBoxGridSizer_Growables(self, parent):
448 parent.AddGrowableCol(1)
450 def _init_sizers(self):
451 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
452 self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
453 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
454 self.RightBoxSizer = wx.StaticBoxSizer(self.staticBox1, wx.VERTICAL)
455 self.RightBoxGridSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=10)
457 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
458 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
459 self._init_coll_MainSizer_Items(self.MainSizer)
460 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
461 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
462 self._init_coll_RightBoxSizer_Items(self.RightBoxSizer)
463 self._init_coll_RightBoxGridSizer_Items(self.RightBoxGridSizer)
464 self._init_coll_RightBoxGridSizer_Growables(self.RightBoxGridSizer)
466 self.SetSizer(self.flexGridSizer1)
468 def _init_ctrls(self, prnt):
469 wx.Dialog.__init__(self, id=ID_USERTYPEDIALOG, name='UserTypeDialog',
470 parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 210),
471 style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
472 self.SetClientSize(wx.Size(444, 210))
474 self.staticText1 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT1,
475 label='Type:', name='staticText1', parent=self,
476 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
478 self.Type = wx.Choice(choices=[], id=ID_USERTYPEDIALOGTYPE,
479 name='Type', parent=self, pos=wx.Point(0, 0),
480 size=wx.Size(0, 24), style=0)
481 self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice,
482 id=ID_USERTYPEDIALOGTYPE)
484 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
485 name='Spacer', parent=self, pos=wx.Point(0, 0),
486 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
488 self.staticBox1 = wx.StaticBox(id=ID_USERTYPEDIALOGSTATICBOX1,
489 label='Values', name='staticBox1', parent=self,
490 pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
492 self.staticText2 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT2,
493 label='Minimum:', name='staticText2', parent=self,
494 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
496 self.Min = wx.TextCtrl(id=ID_USERTYPEDIALOGMIN, name='Min',
497 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
498 style=wx.TE_RIGHT, value='0')
500 self.staticText3 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT3,
501 label='Maximum:', name='staticText3', parent=self,
502 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
504 self.Max = wx.TextCtrl(id=ID_USERTYPEDIALOGMAX, name='Max',
505 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
506 style=wx.TE_RIGHT, value='0')
508 self.staticText4 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT4,
509 label='Length:', name='staticText4', parent=self,
510 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
512 self.Length = wx.TextCtrl(id=ID_USERTYPEDIALOGLENGTH, name='Length',
513 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
514 style=wx.TE_RIGHT, value='0')
516 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
517 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
521 def __init__(self, parent):
522 self._init_ctrls(parent)
524 self.TypeDictionary = {}
526 def OnOK(self, event):
531 name = self.Type.GetStringSelection()
533 valuetype = self.TypeDictionary[name][1]
536 int(self.Min.GetValue(), 16)
538 error.append("Minimum")
541 int(self.Max.GetValue(), 16)
543 error.append("Maximum")
547 int(self.Length.GetValue(), 16)
549 error.append("Length")
553 for i, item in enumerate(error):
555 secondmessage += item
556 elif i == len(error) - 1:
557 secondmessage += " and %s"%item
559 secondmessage += ", %s"%item
560 secondmessage += " must be integer"
564 firstmessage = ". A type must be selected"
567 message = wx.MessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wx.OK|wx.ICON_ERROR)
572 self.EndModal(wx.ID_OK)
574 def SetValues(self, min = None, max = None, length = None):
576 self.Min.SetValue(str(min))
578 self.Max.SetValue(str(max))
580 self.Length.SetValue(str(length))
582 def SetTypeList(self, typedic, type = None):
585 for index, (name, valuetype) in typedic.iteritems():
586 self.TypeDictionary[name] = (index, valuetype)
587 list.append((index, name))
589 for index, name in list:
590 self.Type.Append(name)
592 self.Type.SetStringSelection(typedic[type][0])
595 def OnTypeChoice(self, event):
599 def RefreshValues(self):
600 name = self.Type.GetStringSelection()
602 valuetype = self.TypeDictionary[name][1]
604 self.staticText2.Enable(True)
605 self.staticText3.Enable(True)
606 self.staticText4.Enable(False)
607 self.Min.Enable(True)
608 self.Max.Enable(True)
609 self.Length.Enable(False)
611 self.staticText2.Enable(False)
612 self.staticText3.Enable(False)
613 self.staticText4.Enable(True)
614 self.Min.Enable(False)
615 self.Max.Enable(False)
616 self.Length.Enable(True)
618 self.staticText2.Enable(False)
619 self.staticText3.Enable(False)
620 self.staticText4.Enable(False)
621 self.Min.Enable(False)
622 self.Max.Enable(False)
623 self.Length.Enable(False)
626 name = self.Type.GetStringSelection()
627 type = self.TypeDictionary[name][0]
628 min = int(self.Min.GetValue())
629 max = int(self.Max.GetValue())
630 length = int(self.Length.GetValue())
631 return type, min, max, length
635 #-------------------------------------------------------------------------------
636 # Editing Node Infos Dialog
637 #-------------------------------------------------------------------------------
640 [ID_NODEINFOSDIALOG, ID_NODEINFOSDIALOGNAME,
641 ID_NODEINFOSDIALOGNODEID, ID_NODEINFOSDIALOGDESCRIPTION,
642 ID_NODEINFOSDIALOGTYPE, ID_NODEINFOSDIALOGSTATICTEXT1,
643 ID_NODEINFOSDIALOGSTATICTEXT2, ID_NODEINFOSDIALOGSTATICTEXT3,
644 ID_NODEINFOSDIALOGSTATICTEXT4,
645 ] = [wx.NewId() for _init_ctrls in range(9)]
647 class NodeInfosDialog(wx.Dialog):
648 def _init_coll_flexGridSizer1_Items(self, parent):
649 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
650 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
652 def _init_coll_flexGridSizer1_Growables(self, parent):
653 parent.AddGrowableCol(0)
654 parent.AddGrowableRow(0)
656 def _init_coll_MainSizer_Items(self, parent):
657 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
658 parent.AddWindow(self.Name, 0, border=0, flag=wx.GROW)
659 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
660 parent.AddWindow(self.NodeID, 0, border=0, flag=wx.GROW)
661 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
662 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
663 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
664 parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW)
666 def _init_coll_MainSizer_Growables(self, parent):
667 parent.AddGrowableCol(0)
669 def _init_sizers(self):
670 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
671 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5)
673 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
674 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
675 self._init_coll_MainSizer_Items(self.MainSizer)
676 self._init_coll_MainSizer_Growables(self.MainSizer)
678 self.SetSizer(self.flexGridSizer1)
680 def _init_ctrls(self, prnt):
681 wx.Dialog.__init__(self, id=ID_NODEINFOSDIALOG,
682 name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
683 size=wx.Size(300, 280), style=wx.DEFAULT_DIALOG_STYLE,
685 self.SetClientSize(wx.Size(300, 280))
687 self.staticText1 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT1,
688 label='Name:', name='staticText1', parent=self,
689 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
691 self.Name = wx.TextCtrl(id=ID_NODEINFOSDIALOGNAME, name='Name',
692 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
695 self.staticText2 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT2,
696 label='Node ID:', name='staticText2', parent=self,
697 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
699 self.NodeID = wx.TextCtrl(id=ID_NODEINFOSDIALOGNODEID, name='NodeID',
700 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
701 style=wx.TE_RIGHT, value='')
703 self.staticText3 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT3,
704 label='Type:', name='staticText3', parent=self,
705 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
707 self.Type = wx.Choice(choices=[], id=ID_NODEINFOSDIALOGTYPE,
708 name='Type', parent=self, pos=wx.Point(0, 0),
709 size=wx.Size(0, 25), style=0)
711 self.staticText4 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT4,
712 label='Description:', name='staticText4', parent=self,
713 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
715 self.Description = wx.TextCtrl(id=ID_NODEINFOSDIALOGDESCRIPTION,
716 name='Description', parent=self, pos=wx.Point(0, 0),
717 size=wx.Size(0, 24), style=0, value='')
719 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
720 name='Spacer', parent=self, pos=wx.Point(0, 0),
721 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
723 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
724 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
728 def __init__(self, parent):
729 self._init_ctrls(parent)
731 self.Type.Append("master")
732 self.Type.Append("slave")
734 def OnOK(self, event):
735 name = self.Name.GetValue()
738 good = not name[0].isdigit()
739 for item in name.split("_"):
740 good &= item.isalnum()
742 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
745 nodeid = int(self.NodeID.GetValue(), 16)
747 message = "Node ID must be integer!"
749 message = wx.MessageDialog(self, message, "ERROR", wx.OK|wx.ICON_ERROR)
754 self.EndModal(wx.ID_OK)
756 def SetValues(self, name, id, type, description):
757 self.Name.SetValue(name)
758 self.NodeID.SetValue("0x%02X"%id)
759 self.Type.SetStringSelection(type)
760 self.Description.SetValue(description)
763 name = self.Name.GetValue()
764 nodeid = int(self.NodeID.GetValue(), 16)
765 type = self.Type.GetStringSelection()
766 description = self.Description.GetValue()
767 return name, nodeid, type, description
771 #-------------------------------------------------------------------------------
772 # Create New Node Dialog
773 #-------------------------------------------------------------------------------
776 [ID_CREATENODEDIALOG, ID_CREATENODEDIALOGEMERGENCY,
777 ID_CREATENODEDIALOGGENSYNC, ID_CREATENODEDIALOGSPACER,
778 ID_CREATENODEDIALOGNAME, ID_CREATENODEDIALOGNMT_HEARTBEAT,
779 ID_CREATENODEDIALOGNMT_NODEGUARDING, ID_CREATENODEDIALOGNMT_NONE,
780 ID_CREATENODEDIALOGNODEID, ID_CREATENODEDIALOGPROFILE,
781 ID_CREATENODEDIALOGSAVECONFIG, ID_CREATENODEDIALOGSTATICTEXT1,
782 ID_CREATENODEDIALOGSTATICTEXT2, ID_CREATENODEDIALOGSTATICTEXT3,
783 ID_CREATENODEDIALOGSTATICTEXT4, ID_CREATENODEDIALOGSTATICTEXT5,
784 ID_CREATENODEDIALOGSTATICTEXT6, ID_CREATENODEDIALOGSTATICTEXT7,
785 ID_CREATENODEDIALOGSTOREEDS, ID_CREATENODEDIALOGDESCRIPTION,
786 ID_CREATENODEDIALOGTYPE,
787 ] = [wx.NewId() for _init_ctrls in range(21)]
789 class CreateNodeDialog(wx.Dialog):
790 def _init_coll_flexGridSizer1_Items(self, parent):
791 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
792 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
794 def _init_coll_flexGridSizer1_Growables(self, parent):
795 parent.AddGrowableCol(0)
796 parent.AddGrowableRow(0)
798 def _init_coll_MainSizer_Items(self, parent):
799 parent.AddSizer(self.TopBoxSizer, 0, border=0, flag=wx.GROW)
800 parent.AddWindow(self.staticText7, 0, border=0, flag=wx.GROW)
801 parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW)
803 def _init_coll_MainSizer_Growables(self, parent):
804 parent.AddGrowableCol(0)
805 parent.AddGrowableCol(0)
807 def _init_coll_TopBoxSizer_Items(self, parent):
808 parent.AddSizer(self.LeftBoxSizer, 1, border=10, flag=wx.GROW|wx.RIGHT)
809 parent.AddSizer(self.RightGridSizer, 1, border=10, flag=wx.GROW|wx.LEFT)
811 def _init_coll_LeftBoxSizer_Items(self, parent):
812 parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM)
813 parent.AddWindow(self.Type, 0, border=10, flag=wx.GROW|wx.BOTTOM)
814 parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM)
815 parent.AddWindow(self.Name, 0, border=10, flag=wx.GROW|wx.BOTTOM)
816 parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM)
817 parent.AddWindow(self.NodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM)
818 parent.AddWindow(self.staticText4, 0, border=5, flag=wx.GROW|wx.BOTTOM)
819 parent.AddWindow(self.Profile, 0, border=20, flag=wx.GROW|wx.BOTTOM)
821 def _init_coll_RightGridSizer_Items(self, parent):
822 parent.AddSizer(self.RightTopGridSizer, 0, border=0, flag=wx.GROW)
823 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
824 parent.AddSizer(self.RightBottomGridSizer, 0, border=0, flag=wx.GROW)
826 def _init_coll_RightGridSizer_Growables(self, parent):
827 parent.AddGrowableCol(0)
828 parent.AddGrowableRow(1)
830 def _init_coll_RightTopGridSizer_Items(self, parent):
831 parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW)
832 parent.AddWindow(self.NMT_None, 0, border=0, flag=wx.GROW)
833 parent.AddWindow(self.NMT_NodeGuarding, 0, border=0, flag=wx.GROW)
834 parent.AddWindow(self.NMT_Heartbeat, 0, border=0, flag=wx.GROW)
836 def _init_coll_RightTopGridSizer_Growables(self, parent):
837 parent.AddGrowableCol(0)
839 def _init_coll_RightBottomGridSizer_Items(self, parent):
840 parent.AddWindow(self.staticText6, 0, border=0, flag=wx.GROW)
841 parent.AddWindow(self.DS302, 0, border=0, flag=wx.GROW)
842 parent.AddWindow(self.GenSYNC, 0, border=0, flag=wx.GROW)
843 parent.AddWindow(self.Emergency, 0, border=0, flag=wx.GROW)
844 parent.AddWindow(self.SaveConfig, 0, border=0, flag=wx.GROW)
845 parent.AddWindow(self.StoreEDS, 0, border=0, flag=wx.GROW)
847 def _init_coll_RightBottomGridSizer_Growables(self, parent):
848 parent.AddGrowableCol(0)
850 def _init_sizers(self):
851 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
852 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=5, rows=3, vgap=0)
853 self.TopBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
854 self.LeftBoxSizer = wx.BoxSizer(wx.VERTICAL)
855 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
856 self.RightTopGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=0)
857 self.RightBottomGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=0)
859 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
860 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
861 self._init_coll_MainSizer_Items(self.MainSizer)
862 self._init_coll_MainSizer_Growables(self.MainSizer)
863 self._init_coll_TopBoxSizer_Items(self.TopBoxSizer)
864 self._init_coll_LeftBoxSizer_Items(self.LeftBoxSizer)
865 self._init_coll_RightGridSizer_Items(self.RightGridSizer)
866 self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
867 self._init_coll_RightTopGridSizer_Items(self.RightTopGridSizer)
868 self._init_coll_RightTopGridSizer_Growables(self.RightTopGridSizer)
869 self._init_coll_RightBottomGridSizer_Items(self.RightBottomGridSizer)
870 self._init_coll_RightBottomGridSizer_Growables(self.RightBottomGridSizer)
872 self.SetSizer(self.flexGridSizer1)
874 def _init_ctrls(self, prnt):
875 wx.Dialog.__init__(self, id=ID_CREATENODEDIALOG,
876 name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
877 size=wx.Size(450, 350), style=wx.DEFAULT_DIALOG_STYLE,
878 title='Create a new Node')
879 self.SetClientSize(wx.Size(450, 350))
881 self.staticText1 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT1,
882 label='Name:', name='staticText1', parent=self,
883 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
885 self.staticText2 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT2,
886 label='Node ID:', name='staticText2', parent=self,
887 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
889 self.staticText3 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT3,
890 label='Type:', name='staticText3', parent=self,
891 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
893 self.staticText4 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT4,
894 label='Profile:', name='staticText4', parent=self,
895 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
897 self.Type = wx.Choice(choices=[], id=ID_CREATENODEDIALOGTYPE,
898 name='Type', parent=self, pos=wx.Point(0, 0),
899 size=wx.Size(0, 25), style=0)
901 self.Name = wx.TextCtrl(id=ID_CREATENODEDIALOGNAME, name='Name',
902 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
905 self.NodeID = wx.TextCtrl(id=ID_CREATENODEDIALOGNODEID, name='NodeID',
906 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
907 style=wx.TE_RIGHT, value='')
909 self.Profile = wx.Choice(choices=[], id=ID_CREATENODEDIALOGPROFILE,
910 name='Profile', parent=self, pos=wx.Point(0, 0),
911 size=wx.Size(0, 24), style=0)
912 self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice,
913 id=ID_CREATENODEDIALOGPROFILE)
915 self.staticText5 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT5,
916 label='Network Management:', name='staticText5',
917 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
919 self.NMT_None = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NONE,
920 label='None', name='NMT_None', parent=self,
921 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
922 self.NMT_None.SetValue(True)
924 self.NMT_NodeGuarding = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NODEGUARDING,
925 label='Node Guarding', name='NMT_NodeGuarding', parent=self,
926 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
927 self.NMT_NodeGuarding.SetValue(False)
929 self.NMT_Heartbeat = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_HEARTBEAT,
930 label='Heartbeat', name='NMT_Heartbeat', parent=self,
931 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
932 self.NMT_Heartbeat.SetValue(False)
934 self.staticText6 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT6,
935 label='Options:', name='staticText6', parent=self,
936 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
938 self.DS302 = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC,
939 label='DS-302 Profile', name='DS302', parent=self,
940 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
941 self.DS302.SetValue(False)
942 #self.DS302.Enable(False)
944 self.GenSYNC = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC,
945 label='Generate SYNC', name='GenSYNC', parent=self,
946 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
947 self.GenSYNC.SetValue(False)
949 self.Emergency = wx.CheckBox(id=ID_CREATENODEDIALOGEMERGENCY,
950 label='Emergency support', name='Emergency',
951 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
952 self.Emergency.SetValue(False)
953 self.Emergency.Enable(False)
955 self.SaveConfig = wx.CheckBox(id=ID_CREATENODEDIALOGSAVECONFIG,
956 label='Save Configuration', name='SaveConfig', parent=self,
957 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
958 self.SaveConfig.SetValue(False)
959 self.SaveConfig.Enable(False)
961 self.StoreEDS = wx.CheckBox(id=ID_CREATENODEDIALOGSTOREEDS,
962 label='Store EDS', name='StoreEDS', parent=self,
963 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
964 self.StoreEDS.SetValue(False)
967 self.staticText7 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT7,
968 label='Description:', name='staticText7', parent=self,
969 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
971 self.Description = wx.TextCtrl(id=ID_CREATENODEDIALOGDESCRIPTION,
972 name='Description', parent=self, pos=wx.Point(0, 0),
973 size=wx.Size(0, 24), style=0, value='')
975 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
976 name='Spacer', parent=self, pos=wx.Point(0, 0),
977 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
979 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
980 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
984 def __init__(self, parent):
985 self._init_ctrls(parent)
987 self.NodeID.SetValue("0x00")
988 self.Type.Append("master")
989 self.Type.Append("slave")
990 self.Type.SetStringSelection("slave")
991 self.Description.SetValue("")
992 self.ListProfile = {"None" : ""}
993 self.Profile.Append("None")
994 self.Directory = os.path.join(ScriptDirectory, "config")
995 listfiles = os.listdir(self.Directory)
997 for item in listfiles:
998 name, extend = os.path.splitext(item)
999 if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302":
1000 self.ListProfile[name] = os.path.join(self.Directory, item)
1001 self.Profile.Append(name)
1002 self.Profile.Append("Other")
1003 self.Profile.SetStringSelection("None")
1004 self.Name.SetFocus()
1006 def OnOK(self, event):
1007 name = self.Name.GetValue()
1010 good = not name[0].isdigit()
1011 for item in name.split("_"):
1012 good &= item.isalnum()
1014 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
1017 nodeid = int(self.NodeID.GetValue(), 16)
1019 message = "Node ID must be an integer!"
1021 message = wx.MessageDialog(self, message, "ERROR", wx.OK|wx.ICON_ERROR)
1024 self.Name.SetFocus()
1026 self.EndModal(wx.ID_OK)
1028 def GetValues(self):
1029 name = self.Name.GetValue()
1031 if self.NodeID.GetValue() != "":
1032 nodeid = int(self.NodeID.GetValue(), 16)
1033 type = self.Type.GetStringSelection()
1034 description = self.Description.GetValue()
1035 return name, nodeid, type, description
1037 def GetProfile(self):
1038 name = self.Profile.GetStringSelection()
1039 return name, self.ListProfile[name]
1041 def GetNMTManagement(self):
1042 if self.NMT_None.GetValue():
1044 elif self.NMT_NodeGuarding.GetValue():
1045 return "NodeGuarding"
1046 elif self.NMT_Heartbeat.GetValue():
1050 def GetOptions(self):
1052 if self.DS302.GetValue():
1053 options.append("DS302")
1054 if self.GenSYNC.GetValue():
1055 options.append("GenSYNC")
1056 if self.Emergency.GetValue():
1057 options.append("Emergency")
1058 if self.SaveConfig.GetValue():
1059 options.append("SaveConfig")
1060 if self.StoreEDS.GetValue():
1061 options.append("StoreEDS")
1064 def OnProfileChoice(self, event):
1065 if self.Profile.GetStringSelection() == "Other":
1066 dialog = wx.FileDialog(self, "Choose a file", self.Directory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
1068 filepath = dialog.GetPath()
1070 if os.path.isfile(filepath):
1071 name = os.path.splitext(os.path.basename(filepath))[0]
1072 self.ListProfile[name] = filepath
1073 length = self.Profile.GetCount()
1074 self.Profile.Insert(name, length - 2)
1075 self.Profile.SetStringSelection(name)
1077 self.Profile.SetStringSelection("None")
1081 #-------------------------------------------------------------------------------
1082 # ADD Slave to NodeList Dialog
1083 #-------------------------------------------------------------------------------
1085 [ID_ADDSLAVEDIALOG, ID_ADDSLAVEDIALOGSLAVENAME,
1086 ID_ADDSLAVEDIALOGSLAVENODEID, ID_ADDSLAVEDIALOGEDSFILE,
1087 ID_ADDSLAVEDIALOGIMPORTEDS, ID_ADDSLAVEDIALOGSTATICTEXT1,
1088 ID_ADDSLAVEDIALOGSTATICTEXT2, ID_ADDSLAVEDIALOGSTATICTEXT3,
1089 ] = [wx.NewId() for _init_ctrls in range(8)]
1091 class AddSlaveDialog(wx.Dialog):
1092 def _init_coll_flexGridSizer1_Items(self, parent):
1093 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
1094 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
1096 def _init_coll_flexGridSizer1_Growables(self, parent):
1097 parent.AddGrowableCol(0)
1098 parent.AddGrowableRow(0)
1100 def _init_coll_MainSizer_Items(self, parent):
1101 parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1102 parent.AddWindow(self.SlaveName, 0, border=10, flag=wx.GROW|wx.BOTTOM)
1103 parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1104 parent.AddWindow(self.SlaveNodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM)
1105 parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1106 parent.AddSizer(self.BottomSizer, 0, border=0, flag=wx.GROW)
1108 def _init_coll_BottomSizer_Items(self, parent):
1109 parent.AddWindow(self.EDSFile, 0, border=4, flag=wx.GROW|wx.TOP|wx.BOTTOM)
1110 parent.AddWindow(self.ImportEDS, 0, border=0, flag=0)
1112 def _init_coll_BottomSizer_Growables(self, parent):
1113 parent.AddGrowableCol(0)
1114 parent.AddGrowableRow(0)
1116 def _init_sizers(self):
1117 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
1118 self.MainSizer = wx.BoxSizer(wx.VERTICAL)
1119 self.BottomSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=0)
1121 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1122 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
1123 self._init_coll_MainSizer_Items(self.MainSizer)
1124 self._init_coll_BottomSizer_Items(self.BottomSizer)
1125 self._init_coll_BottomSizer_Growables(self.BottomSizer)
1127 self.SetSizer(self.flexGridSizer1)
1129 def _init_ctrls(self, prnt):
1130 wx.Dialog.__init__(self, id=ID_ADDSLAVEDIALOG,
1131 name='AddSlaveDialog', parent=prnt, pos=wx.Point(376, 223),
1132 size=wx.Size(300, 250), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
1133 title='Add a slave to nodelist')
1134 self.SetClientSize(wx.Size(300, 250))
1136 self.staticText1 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT1,
1137 label='Slave Name:', name='staticText1', parent=self,
1138 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1140 self.SlaveName = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENAME,
1141 name='SlaveName', parent=self, pos=wx.Point(0, 0),
1142 size=wx.Size(0, 24), style=0)
1144 self.staticText2 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT2,
1145 label='Slave Node ID:', name='staticText2', parent=self,
1146 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1148 self.SlaveNodeID = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENODEID,
1149 name='SlaveName', parent=self, pos=wx.Point(0, 0),
1150 size=wx.Size(0, 24), style=wx.ALIGN_RIGHT)
1152 self.staticText3 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT3,
1153 label='EDS File:', name='staticText3', parent=self,
1154 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1156 self.EDSFile = wx.Choice(id=ID_ADDSLAVEDIALOGEDSFILE,
1157 name='EDSFile', parent=self, pos=wx.Point(0, 0),
1158 size=wx.Size(0, 24), style=0)
1160 self.ImportEDS = wx.Button(id=ID_ADDSLAVEDIALOGIMPORTEDS, label='Import EDS',
1161 name='ImportEDS', parent=self, pos=wx.Point(0, 0),
1162 size=wx.Size(100, 32), style=0)
1163 self.ImportEDS.Bind(wx.EVT_BUTTON, self.OnImportEDSButton,
1164 id=ID_ADDSLAVEDIALOGIMPORTEDS)
1166 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
1167 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
1171 def __init__(self, parent):
1172 self._init_ctrls(parent)
1174 self.SlaveNodeID.SetValue("0x00")
1176 def OnOK(self, event):
1178 if self.SlaveName.GetValue() == "":
1179 error.append("Slave Name")
1180 if self.SlaveNodeID.GetValue() == "":
1181 error.append("Slave Node ID")
1182 if self.EDSFile.GetStringSelection() == "":
1183 error.append("EDS File")
1186 for i, item in enumerate(error):
1189 elif i == len(error) - 1:
1190 text += " and %s"%item
1193 message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR)
1198 nodeid = self.SlaveNodeID.GetValue()
1199 if nodeid.find("x") != -1:
1200 nodeid = int(nodeid, 16)
1202 nodeid = int(nodeid)
1204 message = wx.MessageDialog(self, "Slave Node ID must be a value in decimal or hexadecimal!", "Error", wx.OK|wx.ICON_ERROR)
1208 if not 0 <= nodeid <= 127:
1209 message = wx.MessageDialog(self, "Slave Node ID must be between 0 and 127!", "Error", wx.OK|wx.ICON_ERROR)
1212 elif nodeid == 0 or nodeid in self.NodeList.SlaveNodes.keys():
1213 message = wx.MessageDialog(self, "A Node with this ID already exist in the network!", "Error", wx.OK|wx.ICON_ERROR)
1217 self.EndModal(wx.ID_OK)
1219 def OnImportEDSButton(self, event):
1220 dialog = wx.FileDialog(self, "Choose an EDS file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
1221 if dialog.ShowModal() == wx.ID_OK:
1222 filepath = dialog.GetPath()
1223 if os.path.isfile(filepath):
1224 result = self.NodeList.ImportEDSFile(filepath)
1226 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
1230 self.RefreshEDSFile()
1233 def RefreshEDSFile(self):
1234 selection = self.EDSFile.GetStringSelection()
1235 self.EDSFile.Clear()
1236 for option in self.NodeList.EDSNodes.keys():
1237 self.EDSFile.Append(option)
1238 if self.EDSFile.FindString(selection) != wx.NOT_FOUND:
1239 self.EDSFile.SetStringSelection(selection)
1241 def SetNodeList(self, nodelist):
1242 self.NodeList = nodelist
1243 self.RefreshEDSFile()
1245 def GetValues(self):
1247 values["slaveName"] = self.SlaveName.GetValue()
1248 nodeid = self.SlaveNodeID.GetValue()
1249 if nodeid.find("x") != -1:
1250 values["slaveNodeID"] = int(nodeid, 16)
1252 values["slaveNodeID"] = int(nodeid)
1253 values["edsFile"] = self.EDSFile.GetStringSelection()