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 #-------------------------------------------------------------------------------
29 # Editing Communication Dialog
30 #-------------------------------------------------------------------------------
33 [ID_COMMUNICATIONDIALOG, ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
34 ID_COMMUNICATIONDIALOGCURRENTINDEXES, ID_COMMUNICATIONDIALOGSELECT,
35 ID_COMMUNICATIONDIALOGUNSELECT, ID_COMMUNICATIONDIALOGSTATICTEXT1,
36 ID_COMMUNICATIONDIALOGSTATICTEXT2
37 ] = [wx.NewId() for _init_ctrls in range(7)]
39 class CommunicationDialog(wx.Dialog):
40 def _init_coll_flexGridSizer1_Items(self, parent):
41 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
42 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
44 def _init_coll_flexGridSizer1_Growables(self, parent):
45 parent.AddGrowableCol(0)
46 parent.AddGrowableRow(0)
48 def _init_coll_MainSizer_Items(self, parent):
49 parent.AddSizer(self.LeftGridSizer, 0, border=0, flag=wx.GROW)
50 parent.AddSizer(self.MiddleGridSizer, 0, border=0, flag=wx.GROW)
51 parent.AddSizer(self.RightGridSizer, 0, border=0, flag=wx.GROW)
53 def _init_coll_MainSizer_Growables(self, parent):
54 parent.AddGrowableCol(0)
55 parent.AddGrowableCol(2)
56 parent.AddGrowableRow(0)
58 def _init_coll_LeftGridSizer_Items(self, parent):
59 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
60 parent.AddWindow(self.PossibleIndexes, 0, border=0, flag=wx.GROW)
62 def _init_coll_LeftGridSizer_Growables(self, parent):
63 parent.AddGrowableCol(0)
64 parent.AddGrowableRow(1)
66 def _init_coll_MiddleGridSizer_Items(self, parent):
67 parent.AddWindow(self.Select, 0, border=0, flag=wx.ALIGN_BOTTOM)
68 parent.AddWindow(self.Unselect, 0, border=0, flag=wx.ALIGN_TOP)
70 def _init_coll_MiddleGridSizer_Growables(self, parent):
71 parent.AddGrowableCol(0)
72 parent.AddGrowableRow(0)
73 parent.AddGrowableRow(1)
75 def _init_coll_RightGridSizer_Items(self, parent):
76 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
77 parent.AddWindow(self.CurrentIndexes, 0, border=0, flag=wx.GROW)
79 def _init_coll_RightGridSizer_Growables(self, parent):
80 parent.AddGrowableCol(0)
81 parent.AddGrowableRow(1)
83 def _init_sizers(self):
84 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
85 self.MainSizer = wx.FlexGridSizer(cols=3, hgap=15, rows=1, vgap=0)
86 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
87 self.MiddleGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=40)
88 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
90 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
91 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
92 self._init_coll_MainSizer_Items(self.MainSizer)
93 self._init_coll_MainSizer_Growables(self.MainSizer)
94 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
95 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
96 self._init_coll_MiddleGridSizer_Items(self.MiddleGridSizer)
97 self._init_coll_MiddleGridSizer_Growables(self.MiddleGridSizer)
98 self._init_coll_RightGridSizer_Items(self.RightGridSizer)
99 self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
101 self.SetSizer(self.flexGridSizer1)
103 def _init_ctrls(self, prnt):
104 wx.Dialog.__init__(self, id=ID_COMMUNICATIONDIALOG,
105 name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216),
106 size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
107 title='Edit Communication Profile')
108 self.SetClientSize(wx.Size(726, 437))
110 self.staticText1 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT1,
111 label='Possible Profile Indexes:', name='staticText1',
112 parent=self, pos=wx.Point(0, 0), size=wx.Size(0,
115 self.PossibleIndexes = wx.ListBox(choices=[],
116 id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
117 name='PossibleIndexes', parent=self, pos=wx.Point(0, 0),
118 size=wx.Size(0, 0), style=wx.LB_EXTENDED)
119 self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick,
120 id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES)
122 self.Select = wx.Button(id=ID_COMMUNICATIONDIALOGSELECT, label='>>',
123 name='Select', parent=self, pos=wx.Point(0, 0),
124 size=wx.Size(32, 32), style=0)
125 self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton,
126 id=ID_COMMUNICATIONDIALOGSELECT)
128 self.Unselect = wx.Button(id=ID_COMMUNICATIONDIALOGUNSELECT,
129 label='<<', name='Unselect', parent=self,
130 pos=wx.Point(0, 0), size=wx.Size(32, 32), style=0)
131 self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton,
132 id=ID_COMMUNICATIONDIALOGUNSELECT)
134 self.staticText2 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT2,
135 label='Current Profile Indexes:', name='staticText2',
136 parent=self, pos=wx.Point(0, 0), size=wx.Size(0,
139 self.CurrentIndexes = wx.ListBox(choices=[],
140 id=ID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes',
141 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 0),
142 style=wx.LB_EXTENDED)
143 self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick,
144 id=ID_COMMUNICATIONDIALOGCURRENTINDEXES)
146 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
150 def __init__(self, parent):
151 self._init_ctrls(parent)
153 self.CurrentList = []
154 self.IndexDictionary = {}
156 def SetIndexDictionary(self, dictionary):
157 self.IndexDictionary = dictionary
159 def SetCurrentList(self, list):
160 self.CurrentList = []
161 self.CurrentList.extend(list)
162 self.CurrentList.sort()
164 def GetCurrentList(self):
165 return self.CurrentList
167 def RefreshLists(self):
168 self.PossibleIndexes.Clear()
169 self.CurrentIndexes.Clear()
171 for index in self.IndexDictionary.iterkeys():
172 if index not in self.CurrentList:
173 self.AllList.append(index)
175 for index in self.AllList:
176 self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0]))
177 for index in self.CurrentList:
178 if index in self.IndexDictionary:
179 self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0]))
181 def OnPossibleIndexesDClick(self, event):
182 self.SelectPossible()
185 def OnCurrentIndexesDClick(self, event):
186 self.UnselectCurrent()
189 def OnSelectButton(self, event):
190 self.SelectPossible()
193 def OnUnselectButton(self, event):
194 self.UnselectCurrent()
197 def SelectPossible(self):
198 selected = self.PossibleIndexes.GetSelections()
200 self.CurrentList.append(self.AllList[i])
201 self.CurrentList.sort()
204 def UnselectCurrent(self):
205 selected = self.CurrentIndexes.GetSelections()
207 if not self.IndexDictionary[self.CurrentList[i]][1]:
208 self.CurrentList.pop(i)
209 self.CurrentList.sort()
214 #-------------------------------------------------------------------------------
215 # Create Map Variable Dialog
216 #-------------------------------------------------------------------------------
219 [ID_MAPVARIABLEDIALOG, ID_MAPVARIABLEDIALOGINDEX,
220 ID_MAPVARIABLEDIALOGINDEXNAME, ID_MAPVARIABLEDIALOGSPACER,
221 ID_MAPVARIABLEDIALOGNUMBER, ID_MAPVARIABLEDIALOGRADIOBUTTON1,
222 ID_MAPVARIABLEDIALOGRADIOBUTTON2, ID_MAPVARIABLEDIALOGRADIOBUTTON3,
223 ID_MAPVARIABLEDIALOGSTATICTEXT1, ID_MAPVARIABLEDIALOGSTATICTEXT2,
224 ID_MAPVARIABLEDIALOGSTATICTEXT3, ID_MAPVARIABLEDIALOGSTATICTEXT4,
225 ] = [wx.NewId() for _init_ctrls in range(12)]
227 class MapVariableDialog(wx.Dialog):
228 def _init_coll_flexGridSizer1_Items(self, parent):
229 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
230 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
232 def _init_coll_flexGridSizer1_Growables(self, parent):
233 parent.AddGrowableCol(0)
234 parent.AddGrowableRow(0)
236 def _init_coll_MainSizer_Items(self, parent):
237 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
238 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
239 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
240 parent.AddWindow(self.Index, 0, border=0, flag=wx.GROW)
241 parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW)
242 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
243 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
244 parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW)
245 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
246 parent.AddWindow(self.IndexName, 0, border=0, flag=wx.GROW)
247 parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW)
248 parent.AddWindow(self.Number, 0, border=0, flag=wx.GROW)
250 def _init_coll_MainSizer_Growables(self, parent):
251 parent.AddGrowableCol(0)
252 parent.AddGrowableCol(2)
254 def _init_sizers(self):
255 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
256 self.MainSizer = wx.FlexGridSizer(cols=3, hgap=30, rows=4, vgap=5)
258 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
259 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
260 self._init_coll_MainSizer_Items(self.MainSizer)
261 self._init_coll_MainSizer_Growables(self.MainSizer)
263 self.SetSizer(self.flexGridSizer1)
265 def _init_ctrls(self, prnt):
266 wx.Dialog.__init__(self, id=ID_MAPVARIABLEDIALOG,
267 name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
268 size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
269 title='Add Map Variable')
270 self.SetClientSize(wx.Size(444, 186))
272 self.staticText1 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT1,
273 label='Index:', name='staticText1', parent=self,
274 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
276 self.staticText2 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT2,
277 label='Type:', name='staticText2', parent=self,
278 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
280 self.staticText3 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT3,
281 label='Name:', name='staticText3', parent=self,
282 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
284 self.staticText4 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT4,
285 label='Number:', name='staticText4', parent=self,
286 pos=wx.Point(0, 0), size=wx.Size(0, 16), style=0)
288 self.radioButton1 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON1,
289 label='VAR', name='radioButton1', parent=self,
290 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_GROUP)
291 self.radioButton1.SetValue(True)
292 self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click,
293 id=ID_MAPVARIABLEDIALOGRADIOBUTTON1)
295 self.radioButton2 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON2,
296 label='ARRAY', name='radioButton2', parent=self,
297 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
298 self.radioButton2.SetValue(False)
299 self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click,
300 id=ID_MAPVARIABLEDIALOGRADIOBUTTON2)
302 self.radioButton3 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON3,
303 label='REC', name='radioButton3', parent=self,
304 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
305 self.radioButton3.SetValue(False)
306 self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click,
307 id=ID_MAPVARIABLEDIALOGRADIOBUTTON3)
309 self.Index = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEX, name='Index',
310 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
311 style=0, value='0x2000')
313 self.IndexName = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEXNAME,
314 name='IndexName', parent=self, pos=wx.Point(0, 0),
315 size=wx.Size(0, 24), style=0, value='Undefined')
317 self.Number = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGNUMBER,
318 name='Number', parent=self, pos=wx.Point(0, 0),
319 size=wx.Size(0, 24), style=wx.TE_RIGHT, value='0')
321 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
322 name='Spacer', parent=self, pos=wx.Point(0, 0),
323 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
325 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
326 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
330 def __init__(self, parent):
331 self._init_ctrls(parent)
332 self.staticText4.Enable(False)
333 self.Number.Enable(False)
335 def SetIndex(self, index):
336 self.Index.SetValue("0x%04X"%index)
338 def OnOK(self, event):
341 int(self.Index.GetValue(), 16)
343 error.append("Index")
344 if self.radioButton2.GetValue() or self.radioButton3.GetValue():
346 int(self.Number.GetValue())
348 error.append("Number")
355 for i, item in enumerate(error):
358 elif i == len(error) - 1:
359 text += " and %s"%item
362 message = wx.MessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wx.OK|wx.ICON_ERROR)
366 self.EndModal(wx.ID_OK)
369 name = self.IndexName.GetValue()
370 index = int(self.Index.GetValue(), 16)
371 if self.radioButton1.GetValue():
374 elif self.radioButton2.GetValue():
376 number = int(self.Number.GetValue())
377 elif self.radioButton3.GetValue():
379 number = int(self.Number.GetValue())
380 return index, name, struct, number
382 def OnRadioButton1Click(self, event):
383 self.EnableNumberTyping(False)
386 def OnRadioButton2Click(self, event):
387 self.EnableNumberTyping(True)
390 def OnRadioButton3Click(self, event):
391 self.EnableNumberTyping(True)
394 def EnableNumberTyping(self, enable):
395 self.staticText4.Enable(enable)
396 self.Number.Enable(enable)
399 #-------------------------------------------------------------------------------
400 # Create User Type Dialog
401 #-------------------------------------------------------------------------------
404 [ID_USERTYPEDIALOG, ID_USERTYPEDIALOGSPACER,
405 ID_USERTYPEDIALOGTYPE, ID_USERTYPEDIALOGMAX,
406 ID_USERTYPEDIALOGMIN, ID_USERTYPEDIALOGLENGTH,
407 ID_USERTYPEDIALOGSTATICBOX1, ID_USERTYPEDIALOGSTATICTEXT1,
408 ID_USERTYPEDIALOGSTATICTEXT2, ID_USERTYPEDIALOGSTATICTEXT3,
409 ID_USERTYPEDIALOGSTATICTEXT4,
410 ] = [wx.NewId() for _init_ctrls in range(11)]
412 class UserTypeDialog(wx.Dialog):
413 def _init_coll_flexGridSizer1_Items(self, parent):
414 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
415 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
417 def _init_coll_flexGridSizer1_Growables(self, parent):
418 parent.AddGrowableCol(0)
419 parent.AddGrowableRow(0)
421 def _init_coll_MainSizer_Items(self, parent):
422 parent.AddSizer(self.LeftGridSizer, 2, border=5, flag=wx.GROW|wx.RIGHT)
423 parent.AddSizer(self.RightBoxSizer, 3, border=5, flag=wx.GROW|wx.LEFT)
425 def _init_coll_LeftGridSizer_Items(self, parent):
426 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
427 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
428 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
430 def _init_coll_LeftGridSizer_Growables(self, parent):
431 parent.AddGrowableCol(0)
432 parent.AddGrowableRow(2)
434 def _init_coll_RightBoxSizer_Items(self, parent):
435 parent.AddSizer(self.RightBoxGridSizer, 0, border=10, flag=wx.GROW|wx.ALL)
437 def _init_coll_RightBoxGridSizer_Items(self, parent):
438 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
439 parent.AddWindow(self.Min, 0, border=0, flag=wx.GROW)
440 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
441 parent.AddWindow(self.Max, 0, border=0, flag=wx.GROW)
442 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
443 parent.AddWindow(self.Length, 0, border=0, flag=wx.GROW)
445 def _init_coll_RightBoxGridSizer_Growables(self, parent):
446 parent.AddGrowableCol(1)
448 def _init_sizers(self):
449 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
450 self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
451 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
452 self.RightBoxSizer = wx.StaticBoxSizer(self.staticBox1, wx.VERTICAL)
453 self.RightBoxGridSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=10)
455 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
456 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
457 self._init_coll_MainSizer_Items(self.MainSizer)
458 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
459 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
460 self._init_coll_RightBoxSizer_Items(self.RightBoxSizer)
461 self._init_coll_RightBoxGridSizer_Items(self.RightBoxGridSizer)
462 self._init_coll_RightBoxGridSizer_Growables(self.RightBoxGridSizer)
464 self.SetSizer(self.flexGridSizer1)
466 def _init_ctrls(self, prnt):
467 wx.Dialog.__init__(self, id=ID_USERTYPEDIALOG, name='UserTypeDialog',
468 parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 210),
469 style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
470 self.SetClientSize(wx.Size(444, 210))
472 self.staticText1 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT1,
473 label='Type:', name='staticText1', parent=self,
474 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
476 self.Type = wx.Choice(choices=[], id=ID_USERTYPEDIALOGTYPE,
477 name='Type', parent=self, pos=wx.Point(0, 0),
478 size=wx.Size(0, 24), style=0)
479 self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice,
480 id=ID_USERTYPEDIALOGTYPE)
482 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
483 name='Spacer', parent=self, pos=wx.Point(0, 0),
484 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
486 self.staticBox1 = wx.StaticBox(id=ID_USERTYPEDIALOGSTATICBOX1,
487 label='Values', name='staticBox1', parent=self,
488 pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
490 self.staticText2 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT2,
491 label='Minimum:', name='staticText2', parent=self,
492 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
494 self.Min = wx.TextCtrl(id=ID_USERTYPEDIALOGMIN, name='Min',
495 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
496 style=wx.TE_RIGHT, value='0')
498 self.staticText3 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT3,
499 label='Maximum:', name='staticText3', parent=self,
500 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
502 self.Max = wx.TextCtrl(id=ID_USERTYPEDIALOGMAX, name='Max',
503 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
504 style=wx.TE_RIGHT, value='0')
506 self.staticText4 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT4,
507 label='Length:', name='staticText4', parent=self,
508 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
510 self.Length = wx.TextCtrl(id=ID_USERTYPEDIALOGLENGTH, name='Length',
511 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
512 style=wx.TE_RIGHT, value='0')
514 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
515 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
519 def __init__(self, parent):
520 self._init_ctrls(parent)
522 self.TypeDictionary = {}
524 def OnOK(self, event):
529 name = self.Type.GetStringSelection()
531 valuetype = self.TypeDictionary[name][1]
534 int(self.Min.GetValue(), 16)
536 error.append("Minimum")
539 int(self.Max.GetValue(), 16)
541 error.append("Maximum")
545 int(self.Length.GetValue(), 16)
547 error.append("Length")
551 for i, item in enumerate(error):
553 secondmessage += item
554 elif i == len(error) - 1:
555 secondmessage += " and %s"%item
557 secondmessage += ", %s"%item
558 secondmessage += " must be integer"
562 firstmessage = ". A type must be selected"
565 message = wx.MessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wx.OK|wx.ICON_ERROR)
570 self.EndModal(wx.ID_OK)
572 def SetValues(self, min = None, max = None, length = None):
574 self.Min.SetValue(str(min))
576 self.Max.SetValue(str(max))
578 self.Length.SetValue(str(length))
580 def SetTypeList(self, typedic, type = None):
583 for index, (name, valuetype) in typedic.iteritems():
584 self.TypeDictionary[name] = (index, valuetype)
585 list.append((index, name))
587 for index, name in list:
588 self.Type.Append(name)
590 self.Type.SetStringSelection(typedic[type][0])
593 def OnTypeChoice(self, event):
597 def RefreshValues(self):
598 name = self.Type.GetStringSelection()
600 valuetype = self.TypeDictionary[name][1]
602 self.staticText2.Enable(True)
603 self.staticText3.Enable(True)
604 self.staticText4.Enable(False)
605 self.Min.Enable(True)
606 self.Max.Enable(True)
607 self.Length.Enable(False)
609 self.staticText2.Enable(False)
610 self.staticText3.Enable(False)
611 self.staticText4.Enable(True)
612 self.Min.Enable(False)
613 self.Max.Enable(False)
614 self.Length.Enable(True)
616 self.staticText2.Enable(False)
617 self.staticText3.Enable(False)
618 self.staticText4.Enable(False)
619 self.Min.Enable(False)
620 self.Max.Enable(False)
621 self.Length.Enable(False)
624 name = self.Type.GetStringSelection()
625 type = self.TypeDictionary[name][0]
626 min = int(self.Min.GetValue())
627 max = int(self.Max.GetValue())
628 length = int(self.Length.GetValue())
629 return type, min, max, length
633 #-------------------------------------------------------------------------------
634 # Editing Node Infos Dialog
635 #-------------------------------------------------------------------------------
638 [ID_NODEINFOSDIALOG, ID_NODEINFOSDIALOGNAME,
639 ID_NODEINFOSDIALOGNODEID, ID_NODEINFOSDIALOGDESCRIPTION,
640 ID_NODEINFOSDIALOGTYPE, ID_NODEINFOSDIALOGSTATICTEXT1,
641 ID_NODEINFOSDIALOGSTATICTEXT2, ID_NODEINFOSDIALOGSTATICTEXT3,
642 ID_NODEINFOSDIALOGSTATICTEXT4,
643 ] = [wx.NewId() for _init_ctrls in range(9)]
645 class NodeInfosDialog(wx.Dialog):
646 def _init_coll_flexGridSizer1_Items(self, parent):
647 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
648 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
650 def _init_coll_flexGridSizer1_Growables(self, parent):
651 parent.AddGrowableCol(0)
652 parent.AddGrowableRow(0)
654 def _init_coll_MainSizer_Items(self, parent):
655 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
656 parent.AddWindow(self.Name, 0, border=0, flag=wx.GROW)
657 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
658 parent.AddWindow(self.NodeID, 0, border=0, flag=wx.GROW)
659 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
660 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
661 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
662 parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW)
664 def _init_coll_MainSizer_Growables(self, parent):
665 parent.AddGrowableCol(0)
667 def _init_sizers(self):
668 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
669 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5)
671 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
672 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
673 self._init_coll_MainSizer_Items(self.MainSizer)
674 self._init_coll_MainSizer_Growables(self.MainSizer)
676 self.SetSizer(self.flexGridSizer1)
678 def _init_ctrls(self, prnt):
679 wx.Dialog.__init__(self, id=ID_NODEINFOSDIALOG,
680 name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
681 size=wx.Size(300, 280), style=wx.DEFAULT_DIALOG_STYLE,
683 self.SetClientSize(wx.Size(300, 280))
685 self.staticText1 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT1,
686 label='Name:', name='staticText1', parent=self,
687 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
689 self.Name = wx.TextCtrl(id=ID_NODEINFOSDIALOGNAME, name='Name',
690 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
693 self.staticText2 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT2,
694 label='Node ID:', name='staticText2', parent=self,
695 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
697 self.NodeID = wx.TextCtrl(id=ID_NODEINFOSDIALOGNODEID, name='NodeID',
698 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
699 style=wx.TE_RIGHT, value='')
701 self.staticText3 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT3,
702 label='Type:', name='staticText3', parent=self,
703 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
705 self.Type = wx.Choice(choices=[], id=ID_NODEINFOSDIALOGTYPE,
706 name='Type', parent=self, pos=wx.Point(0, 0),
707 size=wx.Size(0, 25), style=0)
709 self.staticText4 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT4,
710 label='Description:', name='staticText4', parent=self,
711 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
713 self.Description = wx.TextCtrl(id=ID_NODEINFOSDIALOGDESCRIPTION,
714 name='Description', parent=self, pos=wx.Point(0, 0),
715 size=wx.Size(0, 24), style=0, value='')
717 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
718 name='Spacer', parent=self, pos=wx.Point(0, 0),
719 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
721 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
722 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
726 def __init__(self, parent):
727 self._init_ctrls(parent)
729 self.Type.Append("master")
730 self.Type.Append("slave")
732 def OnOK(self, event):
733 name = self.Name.GetValue()
736 good = not name[0].isdigit()
737 for item in name.split("_"):
738 good &= item.isalnum()
740 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
743 nodeid = int(self.NodeID.GetValue(), 16)
745 message = "Node ID must be integer!"
747 message = wx.MessageDialog(self, message, "ERROR", wx.OK|wx.ICON_ERROR)
752 self.EndModal(wx.ID_OK)
754 def SetValues(self, name, id, type, description):
755 self.Name.SetValue(name)
756 self.NodeID.SetValue("0x%02X"%id)
757 self.Type.SetStringSelection(type)
758 self.Description.SetValue(description)
761 name = self.Name.GetValue()
762 nodeid = int(self.NodeID.GetValue(), 16)
763 type = self.Type.GetStringSelection()
764 description = self.Description.GetValue()
765 return name, nodeid, type, description
769 #-------------------------------------------------------------------------------
770 # Create New Node Dialog
771 #-------------------------------------------------------------------------------
774 [ID_CREATENODEDIALOG, ID_CREATENODEDIALOGEMERGENCY,
775 ID_CREATENODEDIALOGGENSYNC, ID_CREATENODEDIALOGSPACER,
776 ID_CREATENODEDIALOGNAME, ID_CREATENODEDIALOGNMT_HEARTBEAT,
777 ID_CREATENODEDIALOGNMT_NODEGUARDING, ID_CREATENODEDIALOGNMT_NONE,
778 ID_CREATENODEDIALOGNODEID, ID_CREATENODEDIALOGPROFILE,
779 ID_CREATENODEDIALOGSAVECONFIG, ID_CREATENODEDIALOGSTATICTEXT1,
780 ID_CREATENODEDIALOGSTATICTEXT2, ID_CREATENODEDIALOGSTATICTEXT3,
781 ID_CREATENODEDIALOGSTATICTEXT4, ID_CREATENODEDIALOGSTATICTEXT5,
782 ID_CREATENODEDIALOGSTATICTEXT6, ID_CREATENODEDIALOGSTATICTEXT7,
783 ID_CREATENODEDIALOGSTOREEDS, ID_CREATENODEDIALOGDESCRIPTION,
784 ID_CREATENODEDIALOGTYPE,
785 ] = [wx.NewId() for _init_ctrls in range(21)]
787 class CreateNodeDialog(wx.Dialog):
788 def _init_coll_flexGridSizer1_Items(self, parent):
789 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
790 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
792 def _init_coll_flexGridSizer1_Growables(self, parent):
793 parent.AddGrowableCol(0)
794 parent.AddGrowableRow(0)
796 def _init_coll_MainSizer_Items(self, parent):
797 parent.AddSizer(self.TopBoxSizer, 0, border=0, flag=wx.GROW)
798 parent.AddWindow(self.staticText7, 0, border=0, flag=wx.GROW)
799 parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW)
801 def _init_coll_MainSizer_Growables(self, parent):
802 parent.AddGrowableCol(0)
803 parent.AddGrowableCol(0)
805 def _init_coll_TopBoxSizer_Items(self, parent):
806 parent.AddSizer(self.LeftBoxSizer, 1, border=10, flag=wx.GROW|wx.RIGHT)
807 parent.AddSizer(self.RightGridSizer, 1, border=10, flag=wx.GROW|wx.LEFT)
809 def _init_coll_LeftBoxSizer_Items(self, parent):
810 parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM)
811 parent.AddWindow(self.Type, 0, border=10, flag=wx.GROW|wx.BOTTOM)
812 parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM)
813 parent.AddWindow(self.Name, 0, border=10, flag=wx.GROW|wx.BOTTOM)
814 parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM)
815 parent.AddWindow(self.NodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM)
816 parent.AddWindow(self.staticText4, 0, border=5, flag=wx.GROW|wx.BOTTOM)
817 parent.AddWindow(self.Profile, 0, border=20, flag=wx.GROW|wx.BOTTOM)
819 def _init_coll_RightGridSizer_Items(self, parent):
820 parent.AddSizer(self.RightTopGridSizer, 0, border=0, flag=wx.GROW)
821 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
822 parent.AddSizer(self.RightBottomGridSizer, 0, border=0, flag=wx.GROW)
824 def _init_coll_RightGridSizer_Growables(self, parent):
825 parent.AddGrowableCol(0)
826 parent.AddGrowableRow(1)
828 def _init_coll_RightTopGridSizer_Items(self, parent):
829 parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW)
830 parent.AddWindow(self.NMT_None, 0, border=0, flag=wx.GROW)
831 parent.AddWindow(self.NMT_NodeGuarding, 0, border=0, flag=wx.GROW)
832 parent.AddWindow(self.NMT_Heartbeat, 0, border=0, flag=wx.GROW)
834 def _init_coll_RightTopGridSizer_Growables(self, parent):
835 parent.AddGrowableCol(0)
837 def _init_coll_RightBottomGridSizer_Items(self, parent):
838 parent.AddWindow(self.staticText6, 0, border=0, flag=wx.GROW)
839 parent.AddWindow(self.DS302, 0, border=0, flag=wx.GROW)
840 parent.AddWindow(self.GenSYNC, 0, border=0, flag=wx.GROW)
841 parent.AddWindow(self.Emergency, 0, border=0, flag=wx.GROW)
842 parent.AddWindow(self.SaveConfig, 0, border=0, flag=wx.GROW)
843 parent.AddWindow(self.StoreEDS, 0, border=0, flag=wx.GROW)
845 def _init_coll_RightBottomGridSizer_Growables(self, parent):
846 parent.AddGrowableCol(0)
848 def _init_sizers(self):
849 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
850 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=5, rows=3, vgap=0)
851 self.TopBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
852 self.LeftBoxSizer = wx.BoxSizer(wx.VERTICAL)
853 self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
854 self.RightTopGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=0)
855 self.RightBottomGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=0)
857 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
858 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
859 self._init_coll_MainSizer_Items(self.MainSizer)
860 self._init_coll_MainSizer_Growables(self.MainSizer)
861 self._init_coll_TopBoxSizer_Items(self.TopBoxSizer)
862 self._init_coll_LeftBoxSizer_Items(self.LeftBoxSizer)
863 self._init_coll_RightGridSizer_Items(self.RightGridSizer)
864 self._init_coll_RightGridSizer_Growables(self.RightGridSizer)
865 self._init_coll_RightTopGridSizer_Items(self.RightTopGridSizer)
866 self._init_coll_RightTopGridSizer_Growables(self.RightTopGridSizer)
867 self._init_coll_RightBottomGridSizer_Items(self.RightBottomGridSizer)
868 self._init_coll_RightBottomGridSizer_Growables(self.RightBottomGridSizer)
870 self.SetSizer(self.flexGridSizer1)
872 def _init_ctrls(self, prnt):
873 wx.Dialog.__init__(self, id=ID_CREATENODEDIALOG,
874 name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
875 size=wx.Size(450, 350), style=wx.DEFAULT_DIALOG_STYLE,
876 title='Create a new Node')
877 self.SetClientSize(wx.Size(450, 350))
879 self.staticText1 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT1,
880 label='Name:', name='staticText1', parent=self,
881 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
883 self.staticText2 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT2,
884 label='Node ID:', name='staticText2', parent=self,
885 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
887 self.staticText3 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT3,
888 label='Type:', name='staticText3', parent=self,
889 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
891 self.staticText4 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT4,
892 label='Profile:', name='staticText4', parent=self,
893 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
895 self.Type = wx.Choice(choices=[], id=ID_CREATENODEDIALOGTYPE,
896 name='Type', parent=self, pos=wx.Point(0, 0),
897 size=wx.Size(0, 25), style=0)
899 self.Name = wx.TextCtrl(id=ID_CREATENODEDIALOGNAME, name='Name',
900 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
903 self.NodeID = wx.TextCtrl(id=ID_CREATENODEDIALOGNODEID, name='NodeID',
904 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
905 style=wx.TE_RIGHT, value='')
907 self.Profile = wx.Choice(choices=[], id=ID_CREATENODEDIALOGPROFILE,
908 name='Profile', parent=self, pos=wx.Point(0, 0),
909 size=wx.Size(0, 24), style=0)
910 self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice,
911 id=ID_CREATENODEDIALOGPROFILE)
913 self.staticText5 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT5,
914 label='Network Management:', name='staticText5',
915 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
917 self.NMT_None = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NONE,
918 label='None', name='NMT_None', parent=self,
919 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
920 self.NMT_None.SetValue(True)
922 self.NMT_NodeGuarding = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NODEGUARDING,
923 label='Node Guarding', name='NMT_NodeGuarding', parent=self,
924 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
925 self.NMT_NodeGuarding.SetValue(False)
927 self.NMT_Heartbeat = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_HEARTBEAT,
928 label='Heartbeat', name='NMT_Heartbeat', parent=self,
929 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
930 self.NMT_Heartbeat.SetValue(False)
932 self.staticText6 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT6,
933 label='Options:', name='staticText6', parent=self,
934 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
936 self.DS302 = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC,
937 label='DS-302 Profile', name='DS302', parent=self,
938 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
939 self.DS302.SetValue(False)
940 #self.DS302.Enable(False)
942 self.GenSYNC = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC,
943 label='Generate SYNC', name='GenSYNC', parent=self,
944 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
945 self.GenSYNC.SetValue(False)
947 self.Emergency = wx.CheckBox(id=ID_CREATENODEDIALOGEMERGENCY,
948 label='Emergency support', name='Emergency',
949 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
950 self.Emergency.SetValue(False)
951 self.Emergency.Enable(False)
953 self.SaveConfig = wx.CheckBox(id=ID_CREATENODEDIALOGSAVECONFIG,
954 label='Save Configuration', name='SaveConfig', parent=self,
955 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
956 self.SaveConfig.SetValue(False)
957 self.SaveConfig.Enable(False)
959 self.StoreEDS = wx.CheckBox(id=ID_CREATENODEDIALOGSTOREEDS,
960 label='Store EDS', name='StoreEDS', parent=self,
961 pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0)
962 self.StoreEDS.SetValue(False)
965 self.staticText7 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT7,
966 label='Description:', name='staticText7', parent=self,
967 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
969 self.Description = wx.TextCtrl(id=ID_CREATENODEDIALOGDESCRIPTION,
970 name='Description', parent=self, pos=wx.Point(0, 0),
971 size=wx.Size(0, 24), style=0, value='')
973 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
974 name='Spacer', parent=self, pos=wx.Point(0, 0),
975 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
977 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
978 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
982 def __init__(self, parent, cwd):
983 self._init_ctrls(parent)
985 self.NodeID.SetValue("0x00")
986 self.Type.Append("master")
987 self.Type.Append("slave")
988 self.Type.SetStringSelection("slave")
989 self.Description.SetValue("")
990 self.ListProfile = {"None" : ""}
991 self.Profile.Append("None")
992 self.Directory = os.path.join(cwd, "config")
993 listfiles = os.listdir(self.Directory)
995 for item in listfiles:
996 name, extend = os.path.splitext(item)
997 if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302":
998 self.ListProfile[name] = os.path.join(self.Directory, item)
999 self.Profile.Append(name)
1000 self.Profile.Append("Other")
1001 self.Profile.SetStringSelection("None")
1002 self.Name.SetFocus()
1004 def OnOK(self, event):
1005 name = self.Name.GetValue()
1008 good = not name[0].isdigit()
1009 for item in name.split("_"):
1010 good &= item.isalnum()
1012 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
1015 nodeid = int(self.NodeID.GetValue(), 16)
1017 message = "Node ID must be an integer!"
1019 message = wx.MessageDialog(self, message, "ERROR", wx.OK|wx.ICON_ERROR)
1022 self.Name.SetFocus()
1024 self.EndModal(wx.ID_OK)
1026 def GetValues(self):
1027 name = self.Name.GetValue()
1029 if self.NodeID.GetValue() != "":
1030 nodeid = int(self.NodeID.GetValue(), 16)
1031 type = self.Type.GetStringSelection()
1032 description = self.Description.GetValue()
1033 return name, nodeid, type, description
1035 def GetProfile(self):
1036 name = self.Profile.GetStringSelection()
1037 return name, self.ListProfile[name]
1039 def GetNMTManagement(self):
1040 if self.NMT_None.GetValue():
1042 elif self.NMT_NodeGuarding.GetValue():
1043 return "NodeGuarding"
1044 elif self.NMT_Heartbeat.GetValue():
1048 def GetOptions(self):
1050 if self.DS302.GetValue():
1051 options.append("DS302")
1052 if self.GenSYNC.GetValue():
1053 options.append("GenSYNC")
1054 if self.Emergency.GetValue():
1055 options.append("Emergency")
1056 if self.SaveConfig.GetValue():
1057 options.append("SaveConfig")
1058 if self.StoreEDS.GetValue():
1059 options.append("StoreEDS")
1062 def OnProfileChoice(self, event):
1063 if self.Profile.GetStringSelection() == "Other":
1064 dialog = wx.FileDialog(self, "Choose a file", self.Directory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
1066 filepath = dialog.GetPath()
1068 if os.path.isfile(filepath):
1069 name = os.path.splitext(os.path.basename(filepath))[0]
1070 self.ListProfile[name] = filepath
1071 length = self.Profile.GetCount()
1072 self.Profile.Insert(name, length - 2)
1073 self.Profile.SetStringSelection(name)
1075 self.Profile.SetStringSelection("None")
1079 #-------------------------------------------------------------------------------
1080 # ADD Slave to NodeList Dialog
1081 #-------------------------------------------------------------------------------
1083 [ID_ADDSLAVEDIALOG, ID_ADDSLAVEDIALOGSLAVENAME,
1084 ID_ADDSLAVEDIALOGSLAVENODEID, ID_ADDSLAVEDIALOGEDSFILE,
1085 ID_ADDSLAVEDIALOGIMPORTEDS, ID_ADDSLAVEDIALOGSTATICTEXT1,
1086 ID_ADDSLAVEDIALOGSTATICTEXT2, ID_ADDSLAVEDIALOGSTATICTEXT3,
1087 ] = [wx.NewId() for _init_ctrls in range(8)]
1089 class AddSlaveDialog(wx.Dialog):
1090 def _init_coll_flexGridSizer1_Items(self, parent):
1091 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
1092 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
1094 def _init_coll_flexGridSizer1_Growables(self, parent):
1095 parent.AddGrowableCol(0)
1096 parent.AddGrowableRow(0)
1098 def _init_coll_MainSizer_Items(self, parent):
1099 parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1100 parent.AddWindow(self.SlaveName, 0, border=10, flag=wx.GROW|wx.BOTTOM)
1101 parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1102 parent.AddWindow(self.SlaveNodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM)
1103 parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM)
1104 parent.AddSizer(self.BottomSizer, 0, border=0, flag=wx.GROW)
1106 def _init_coll_BottomSizer_Items(self, parent):
1107 parent.AddWindow(self.EDSFile, 0, border=4, flag=wx.GROW|wx.TOP|wx.BOTTOM)
1108 parent.AddWindow(self.ImportEDS, 0, border=0, flag=0)
1110 def _init_coll_BottomSizer_Growables(self, parent):
1111 parent.AddGrowableCol(0)
1112 parent.AddGrowableRow(0)
1114 def _init_sizers(self):
1115 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
1116 self.MainSizer = wx.BoxSizer(wx.VERTICAL)
1117 self.BottomSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=0)
1119 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
1120 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
1121 self._init_coll_MainSizer_Items(self.MainSizer)
1122 self._init_coll_BottomSizer_Items(self.BottomSizer)
1123 self._init_coll_BottomSizer_Growables(self.BottomSizer)
1125 self.SetSizer(self.flexGridSizer1)
1127 def _init_ctrls(self, prnt):
1128 wx.Dialog.__init__(self, id=ID_ADDSLAVEDIALOG,
1129 name='AddSlaveDialog', parent=prnt, pos=wx.Point(376, 223),
1130 size=wx.Size(300, 250), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
1131 title='Add a slave to nodelist')
1132 self.SetClientSize(wx.Size(300, 250))
1134 self.staticText1 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT1,
1135 label='Slave Name:', name='staticText1', parent=self,
1136 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1138 self.SlaveName = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENAME,
1139 name='SlaveName', parent=self, pos=wx.Point(0, 0),
1140 size=wx.Size(0, 24), style=0)
1142 self.staticText2 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT2,
1143 label='Slave Node ID:', name='staticText2', parent=self,
1144 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1146 self.SlaveNodeID = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENODEID,
1147 name='SlaveName', parent=self, pos=wx.Point(0, 0),
1148 size=wx.Size(0, 24), style=wx.ALIGN_RIGHT)
1150 self.staticText3 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT3,
1151 label='EDS File:', name='staticText3', parent=self,
1152 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
1154 self.EDSFile = wx.Choice(id=ID_ADDSLAVEDIALOGEDSFILE,
1155 name='EDSFile', parent=self, pos=wx.Point(0, 0),
1156 size=wx.Size(0, 24), style=0)
1158 self.ImportEDS = wx.Button(id=ID_ADDSLAVEDIALOGIMPORTEDS, label='Import EDS',
1159 name='ImportEDS', parent=self, pos=wx.Point(0, 0),
1160 size=wx.Size(100, 32), style=0)
1161 self.ImportEDS.Bind(wx.EVT_BUTTON, self.OnImportEDSButton,
1162 id=ID_ADDSLAVEDIALOGIMPORTEDS)
1164 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
1165 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
1169 def __init__(self, parent):
1170 self._init_ctrls(parent)
1172 self.SlaveNodeID.SetValue("0x00")
1174 def OnOK(self, event):
1176 if self.SlaveName.GetValue() == "":
1177 error.append("Slave Name")
1178 if self.SlaveNodeID.GetValue() == "":
1179 error.append("Slave Node ID")
1180 if self.EDSFile.GetStringSelection() == "":
1181 error.append("EDS File")
1184 for i, item in enumerate(error):
1187 elif i == len(error) - 1:
1188 text += " and %s"%item
1191 message = wx.MessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wx.OK|wx.ICON_ERROR)
1196 nodeid = self.SlaveNodeID.GetValue()
1197 if nodeid.find("x") != -1:
1198 nodeid = int(nodeid, 16)
1200 nodeid = int(nodeid)
1202 message = wx.MessageDialog(self, "Slave Node ID must be a value in decimal or hexadecimal!", "Error", wx.OK|wx.ICON_ERROR)
1206 if not 0 <= nodeid <= 127:
1207 message = wx.MessageDialog(self, "Slave Node ID must be between 0 and 127!", "Error", wx.OK|wx.ICON_ERROR)
1210 elif nodeid == 0 or nodeid in self.NodeList.SlaveNodes.keys():
1211 message = wx.MessageDialog(self, "A Node with this ID already exist in the network!", "Error", wx.OK|wx.ICON_ERROR)
1215 self.EndModal(wx.ID_OK)
1217 def OnImportEDSButton(self, event):
1218 dialog = wx.FileDialog(self, "Choose an EDS file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
1219 if dialog.ShowModal() == wx.ID_OK:
1220 filepath = dialog.GetPath()
1221 if os.path.isfile(filepath):
1222 result = self.NodeList.ImportEDSFile(filepath)
1224 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
1228 self.RefreshEDSFile()
1231 def RefreshEDSFile(self):
1232 selection = self.EDSFile.GetStringSelection()
1233 self.EDSFile.Clear()
1234 for option in self.NodeList.EDSNodes.keys():
1235 self.EDSFile.Append(option)
1236 if self.EDSFile.FindString(selection) != wx.NOT_FOUND:
1237 self.EDSFile.SetStringSelection(selection)
1239 def SetNodeList(self, nodelist):
1240 self.NodeList = nodelist
1241 self.RefreshEDSFile()
1243 def GetValues(self):
1245 values["slaveName"] = self.SlaveName.GetValue()
1246 nodeid = self.SlaveNodeID.GetValue()
1247 if nodeid.find("x") != -1:
1248 values["slaveNodeID"] = int(nodeid, 16)
1250 values["slaveNodeID"] = int(nodeid)
1251 values["edsFile"] = self.EDSFile.GetStringSelection()