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.Bind(wx.EVT_LISTBOX_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.Bind(wx.EVT_LISTBOX_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_MAPVARIABLEDIALOGSPACER2, ID_MAPVARIABLEDIALOGNUMBER,
224 ID_MAPVARIABLEDIALOGRADIOBUTTON1, ID_MAPVARIABLEDIALOGRADIOBUTTON2,
225 ID_MAPVARIABLEDIALOGRADIOBUTTON3, ID_MAPVARIABLEDIALOGSTATICTEXT1,
226 ID_MAPVARIABLEDIALOGSTATICTEXT2, ID_MAPVARIABLEDIALOGSTATICTEXT3,
227 ID_MAPVARIABLEDIALOGSTATICTEXT4,
228 ] = [wx.NewId() for _init_ctrls in range(13)]
230 class MapVariableDialog(wx.Dialog):
231 def _init_coll_flexGridSizer1_Items(self, parent):
232 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
233 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
235 def _init_coll_flexGridSizer1_Growables(self, parent):
236 parent.AddGrowableCol(0)
237 parent.AddGrowableRow(0)
239 def _init_coll_MainSizer_Items(self, parent):
240 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
241 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
242 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
243 parent.AddWindow(self.Index, 0, border=0, flag=wx.GROW)
244 parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW)
245 parent.AddWindow(self.Spacer2, 0, border=0, flag=wx.GROW)
246 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
247 parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW)
248 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
249 parent.AddWindow(self.IndexName, 0, border=0, flag=wx.GROW)
250 parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW)
251 parent.AddWindow(self.Number, 0, border=0, flag=wx.GROW)
253 def _init_coll_MainSizer_Growables(self, parent):
254 parent.AddGrowableCol(0)
255 parent.AddGrowableCol(2)
257 def _init_sizers(self):
258 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
259 self.MainSizer = wx.FlexGridSizer(cols=3, hgap=30, rows=4, vgap=5)
261 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
262 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
263 self._init_coll_MainSizer_Items(self.MainSizer)
264 self._init_coll_MainSizer_Growables(self.MainSizer)
266 self.SetSizer(self.flexGridSizer1)
268 def _init_ctrls(self, prnt):
269 wx.Dialog.__init__(self, id=ID_MAPVARIABLEDIALOG,
270 name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
271 size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
272 title='Add Map Variable')
273 self.SetClientSize(wx.Size(444, 186))
275 self.staticText1 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT1,
276 label='Index:', name='staticText1', parent=self,
277 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
279 self.staticText2 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT2,
280 label='Type:', name='staticText2', parent=self,
281 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
283 self.staticText3 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT3,
284 label='Name:', name='staticText3', parent=self,
285 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
287 self.staticText4 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT4,
288 label='Number:', name='staticText4', parent=self,
289 pos=wx.Point(0, 0), size=wx.Size(0, 16), style=0)
291 self.radioButton1 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON1,
292 label='VAR', name='radioButton1', parent=self,
293 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_GROUP)
294 self.radioButton1.SetValue(True)
295 self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click,
296 id=ID_MAPVARIABLEDIALOGRADIOBUTTON1)
298 self.radioButton2 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON2,
299 label='ARRAY', name='radioButton2', parent=self,
300 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
301 self.radioButton2.SetValue(False)
302 self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click,
303 id=ID_MAPVARIABLEDIALOGRADIOBUTTON2)
305 self.radioButton3 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON3,
306 label='REC', name='radioButton3', parent=self,
307 pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_SINGLE)
308 self.radioButton3.SetValue(False)
309 self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click,
310 id=ID_MAPVARIABLEDIALOGRADIOBUTTON3)
312 self.Index = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEX, name='Index',
313 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
314 style=0, value='0x2000')
316 self.IndexName = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEXNAME,
317 name='IndexName', parent=self, pos=wx.Point(0, 0),
318 size=wx.Size(0, 24), style=0, value='Undefined')
320 self.Number = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGNUMBER,
321 name='Number', parent=self, pos=wx.Point(0, 0),
322 size=wx.Size(0, 24), style=wx.TE_RIGHT, value='0')
324 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
325 name='Spacer', parent=self, pos=wx.Point(0, 0),
326 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
328 self.Spacer2 = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER2,
329 name='Spacer2', parent=self, pos=wx.Point(0, 0),
330 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
332 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
333 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
337 def __init__(self, parent):
338 self._init_ctrls(parent)
339 self.staticText4.Enable(False)
340 self.Number.Enable(False)
342 def SetIndex(self, index):
343 self.Index.SetValue("0x%04X"%index)
345 def OnOK(self, event):
348 int(self.Index.GetValue(), 16)
350 error.append("Index")
351 if self.radioButton2.GetValue() or self.radioButton3.GetValue():
353 int(self.Number.GetValue())
355 error.append("Number")
362 for i, item in enumerate(error):
365 elif i == len(error) - 1:
366 text += " and %s"%item
369 message = wx.MessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wx.OK|wx.ICON_ERROR)
373 self.EndModal(wx.ID_OK)
376 name = self.IndexName.GetValue()
377 index = int(self.Index.GetValue(), 16)
378 if self.radioButton1.GetValue():
381 elif self.radioButton2.GetValue():
383 number = int(self.Number.GetValue())
384 elif self.radioButton3.GetValue():
386 number = int(self.Number.GetValue())
387 return index, name, struct, number
389 def OnRadioButton1Click(self, event):
390 self.EnableNumberTyping(False)
393 def OnRadioButton2Click(self, event):
394 self.EnableNumberTyping(True)
397 def OnRadioButton3Click(self, event):
398 self.EnableNumberTyping(True)
401 def EnableNumberTyping(self, enable):
402 self.staticText4.Enable(enable)
403 self.Number.Enable(enable)
406 #-------------------------------------------------------------------------------
407 # Create User Type Dialog
408 #-------------------------------------------------------------------------------
411 [ID_USERTYPEDIALOG, ID_USERTYPEDIALOGSPACER,
412 ID_USERTYPEDIALOGTYPE, ID_USERTYPEDIALOGMAX,
413 ID_USERTYPEDIALOGMIN, ID_USERTYPEDIALOGLENGTH,
414 ID_USERTYPEDIALOGSTATICBOX1, ID_USERTYPEDIALOGSTATICTEXT1,
415 ID_USERTYPEDIALOGSTATICTEXT2, ID_USERTYPEDIALOGSTATICTEXT3,
416 ID_USERTYPEDIALOGSTATICTEXT4,
417 ] = [wx.NewId() for _init_ctrls in range(11)]
419 class UserTypeDialog(wx.Dialog):
420 def _init_coll_flexGridSizer1_Items(self, parent):
421 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
422 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
424 def _init_coll_flexGridSizer1_Growables(self, parent):
425 parent.AddGrowableCol(0)
426 parent.AddGrowableRow(0)
428 def _init_coll_MainSizer_Items(self, parent):
429 parent.AddSizer(self.LeftGridSizer, 2, border=5, flag=wx.GROW|wx.RIGHT)
430 parent.AddSizer(self.RightBoxSizer, 3, border=5, flag=wx.GROW|wx.LEFT)
432 def _init_coll_LeftGridSizer_Items(self, parent):
433 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
434 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
435 parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW)
437 def _init_coll_LeftGridSizer_Growables(self, parent):
438 parent.AddGrowableCol(0)
439 parent.AddGrowableRow(2)
441 def _init_coll_RightBoxSizer_Items(self, parent):
442 parent.AddSizer(self.RightBoxGridSizer, 0, border=10, flag=wx.GROW|wx.ALL)
444 def _init_coll_RightBoxGridSizer_Items(self, parent):
445 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
446 parent.AddWindow(self.Min, 0, border=0, flag=wx.GROW)
447 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
448 parent.AddWindow(self.Max, 0, border=0, flag=wx.GROW)
449 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
450 parent.AddWindow(self.Length, 0, border=0, flag=wx.GROW)
452 def _init_coll_RightBoxGridSizer_Growables(self, parent):
453 parent.AddGrowableCol(1)
455 def _init_sizers(self):
456 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
457 self.MainSizer = wx.BoxSizer(wx.HORIZONTAL)
458 self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5)
459 self.RightBoxSizer = wx.StaticBoxSizer(self.staticBox1, wx.VERTICAL)
460 self.RightBoxGridSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=10)
462 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
463 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
464 self._init_coll_MainSizer_Items(self.MainSizer)
465 self._init_coll_LeftGridSizer_Items(self.LeftGridSizer)
466 self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer)
467 self._init_coll_RightBoxSizer_Items(self.RightBoxSizer)
468 self._init_coll_RightBoxGridSizer_Items(self.RightBoxGridSizer)
469 self._init_coll_RightBoxGridSizer_Growables(self.RightBoxGridSizer)
471 self.SetSizer(self.flexGridSizer1)
473 def _init_ctrls(self, prnt):
474 wx.Dialog.__init__(self, id=ID_USERTYPEDIALOG, name='UserTypeDialog',
475 parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 210),
476 style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
477 self.SetClientSize(wx.Size(444, 210))
479 self.staticText1 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT1,
480 label='Type:', name='staticText1', parent=self,
481 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
483 self.Type = wx.Choice(choices=[], id=ID_USERTYPEDIALOGTYPE,
484 name='Type', parent=self, pos=wx.Point(0, 0),
485 size=wx.Size(0, 24), style=0)
486 self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice,
487 id=ID_USERTYPEDIALOGTYPE)
489 self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER,
490 name='Spacer', parent=self, pos=wx.Point(0, 0),
491 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
493 self.staticBox1 = wx.StaticBox(id=ID_USERTYPEDIALOGSTATICBOX1,
494 label='Values', name='staticBox1', parent=self,
495 pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0)
497 self.staticText2 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT2,
498 label='Minimum:', name='staticText2', parent=self,
499 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
501 self.Min = wx.TextCtrl(id=ID_USERTYPEDIALOGMIN, name='Min',
502 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
503 style=wx.TE_RIGHT, value='0')
505 self.staticText3 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT3,
506 label='Maximum:', name='staticText3', parent=self,
507 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
509 self.Max = wx.TextCtrl(id=ID_USERTYPEDIALOGMAX, name='Max',
510 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
511 style=wx.TE_RIGHT, value='0')
513 self.staticText4 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT4,
514 label='Length:', name='staticText4', parent=self,
515 pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0)
517 self.Length = wx.TextCtrl(id=ID_USERTYPEDIALOGLENGTH, name='Length',
518 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
519 style=wx.TE_RIGHT, value='0')
521 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
522 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
526 def __init__(self, parent):
527 self._init_ctrls(parent)
529 self.TypeDictionary = {}
531 def OnOK(self, event):
536 name = self.Type.GetStringSelection()
538 valuetype = self.TypeDictionary[name][1]
541 int(self.Min.GetValue(), 16)
543 error.append("Minimum")
546 int(self.Max.GetValue(), 16)
548 error.append("Maximum")
552 int(self.Length.GetValue(), 16)
554 error.append("Length")
558 for i, item in enumerate(error):
560 secondmessage += item
561 elif i == len(error) - 1:
562 secondmessage += " and %s"%item
564 secondmessage += ", %s"%item
565 secondmessage += " must be integer"
569 firstmessage = ". A type must be selected"
572 message = wx.MessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wx.OK|wx.ICON_ERROR)
576 self.EndModal(wx.ID_OK)
578 def SetValues(self, min = None, max = None, length = None):
580 self.Min.SetValue(str(min))
582 self.Max.SetValue(str(max))
584 self.Length.SetValue(str(length))
586 def SetTypeList(self, typedic, type = None):
589 for index, (name, valuetype) in typedic.iteritems():
590 self.TypeDictionary[name] = (index, valuetype)
591 list.append((index, name))
593 for index, name in list:
594 self.Type.Append(name)
596 self.Type.SetStringSelection(typedic[type][0])
599 def OnTypeChoice(self, event):
603 def RefreshValues(self):
604 name = self.Type.GetStringSelection()
606 valuetype = self.TypeDictionary[name][1]
608 self.staticText2.Enable(True)
609 self.staticText3.Enable(True)
610 self.staticText4.Enable(False)
611 self.Min.Enable(True)
612 self.Max.Enable(True)
613 self.Length.Enable(False)
615 self.staticText2.Enable(False)
616 self.staticText3.Enable(False)
617 self.staticText4.Enable(True)
618 self.Min.Enable(False)
619 self.Max.Enable(False)
620 self.Length.Enable(True)
622 self.staticText2.Enable(False)
623 self.staticText3.Enable(False)
624 self.staticText4.Enable(False)
625 self.Min.Enable(False)
626 self.Max.Enable(False)
627 self.Length.Enable(False)
630 name = self.Type.GetStringSelection()
631 type = self.TypeDictionary[name][0]
632 min = int(self.Min.GetValue())
633 max = int(self.Max.GetValue())
634 length = int(self.Length.GetValue())
635 return type, min, max, length
639 #-------------------------------------------------------------------------------
640 # Editing Node Infos Dialog
641 #-------------------------------------------------------------------------------
644 [ID_NODEINFOSDIALOG, ID_NODEINFOSDIALOGNAME,
645 ID_NODEINFOSDIALOGNODEID, ID_NODEINFOSDIALOGDESCRIPTION,
646 ID_NODEINFOSDIALOGTYPE, ID_NODEINFOSDIALOGSTATICTEXT1,
647 ID_NODEINFOSDIALOGSTATICTEXT2, ID_NODEINFOSDIALOGSTATICTEXT3,
648 ID_NODEINFOSDIALOGSTATICTEXT4,
649 ] = [wx.NewId() for _init_ctrls in range(9)]
651 class NodeInfosDialog(wx.Dialog):
652 def _init_coll_flexGridSizer1_Items(self, parent):
653 parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
654 parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
656 def _init_coll_flexGridSizer1_Growables(self, parent):
657 parent.AddGrowableCol(0)
658 parent.AddGrowableRow(0)
660 def _init_coll_MainSizer_Items(self, parent):
661 parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
662 parent.AddWindow(self.NodeName, 0, border=0, flag=wx.GROW)
663 parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW)
664 parent.AddWindow(self.NodeID, 0, border=0, flag=wx.GROW)
665 parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW)
666 parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW)
667 parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW)
668 parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW)
670 def _init_coll_MainSizer_Growables(self, parent):
671 parent.AddGrowableCol(0)
673 def _init_sizers(self):
674 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
675 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5)
677 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
678 self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
679 self._init_coll_MainSizer_Items(self.MainSizer)
680 self._init_coll_MainSizer_Growables(self.MainSizer)
682 self.SetSizer(self.flexGridSizer1)
684 def _init_ctrls(self, prnt):
685 wx.Dialog.__init__(self, id=ID_NODEINFOSDIALOG,
686 name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
687 size=wx.Size(300, 280), style=wx.DEFAULT_DIALOG_STYLE,
689 self.SetClientSize(wx.Size(300, 280))
691 self.staticText1 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT1,
692 label='Name:', name='staticText1', parent=self,
693 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
695 self.NodeName = wx.TextCtrl(id=ID_NODEINFOSDIALOGNAME, name='NodeName',
696 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24),
699 self.staticText2 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT2,
700 label='Node ID:', name='staticText2', parent=self,
701 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
703 self.NodeID = wx.TextCtrl(id=ID_NODEINFOSDIALOGNODEID, name='NodeID',
704 parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25),
705 style=wx.TE_RIGHT, value='')
707 self.staticText3 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT3,
708 label='Type:', name='staticText3', parent=self,
709 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
711 self.Type = wx.Choice(choices=[], id=ID_NODEINFOSDIALOGTYPE,
712 name='Type', parent=self, pos=wx.Point(0, 0),
713 size=wx.Size(0, 25), style=0)
715 self.staticText4 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT4,
716 label='Description:', name='staticText4', parent=self,
717 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
719 self.Description = wx.TextCtrl(id=ID_NODEINFOSDIALOGDESCRIPTION,
720 name='Description', parent=self, pos=wx.Point(0, 0),
721 size=wx.Size(0, 24), style=0, value='')
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.NodeName.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)
752 self.NodeName.SetFocus()
754 self.EndModal(wx.ID_OK)
756 def SetValues(self, name, id, type, description):
757 self.NodeName.SetValue(name)
758 self.NodeID.SetValue("0x%02X"%id)
759 self.Type.SetStringSelection(type)
760 self.Description.SetValue(description)
763 name = self.NodeName.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.NodeName, 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='Type:', 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='Name:', 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='Node ID:', 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.NodeName = wx.TextCtrl(id=ID_CREATENODEDIALOGNAME, name='NodeName',
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_CREATENODEDIALOGSPACER,
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.NodeName.SetFocus()
1006 def OnOK(self, event):
1007 name = self.NodeName.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.NodeName.SetFocus()
1026 self.EndModal(wx.ID_OK)
1028 def GetValues(self):
1029 name = self.NodeName.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()