]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - objdictgen/commondialogs.py
Adding program for network management
[CanFestival-3.git] / objdictgen / commondialogs.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 #This file is part of CanFestival, a library implementing CanOpen Stack. 
5 #
6 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
7 #
8 #See COPYING file for copyrights details.
9 #
10 #This library is free software; you can redistribute it and/or
11 #modify it under the terms of the GNU Lesser General Public
12 #License as published by the Free Software Foundation; either
13 #version 2.1 of the License, or (at your option) any later version.
14 #
15 #This library is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 #Lesser General Public License for more details.
19 #
20 #You should have received a copy of the GNU Lesser General Public
21 #License along with this library; if not, write to the Free Software
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24 from wxPython.wx import *
25 from wxPython.grid import *
26 import wx
27
28 import os
29
30 #-------------------------------------------------------------------------------
31 #                          Editing Communication Dialog
32 #-------------------------------------------------------------------------------
33
34
35 [wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL,
36  wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES,
37  wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT, 
38  wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2
39 ] = [wx.NewId() for _init_ctrls in range(8)]
40
41 class CommunicationDialog(wx.Dialog):
42     def _init_coll_flexGridSizer1_Items(self, parent):
43         # generated method, don't edit
44
45         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
46
47     def _init_sizers(self):
48         # generated method, don't edit
49         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
50
51         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
52
53         self.SetSizer(self.flexGridSizer1)
54
55     def _init_ctrls(self, prnt):
56         # generated method, don't edit
57         wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG,
58               name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216),
59               size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE,
60               title='Edit Communication Profile')
61         self.SetClientSize(wx.Size(726, 437))
62
63         self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL,
64               name='MainPanel', parent=self, pos=wx.Point(0, 0),
65               size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL)
66         self.MainPanel.SetAutoLayout(True)
67
68         self.PossibleIndexes = wx.ListBox(choices=[],
69               id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
70               name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40,
71               48), size=wx.Size(280, 320), style=wxLB_EXTENDED)
72         self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClick,
73               id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES)
74
75         self.CurrentIndexes = wx.ListBox(choices=[],
76               id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes',
77               parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280,
78               320), style=wxLB_EXTENDED)
79         self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClick,
80               id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES)
81
82         self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>',
83               name='Select', parent=self.MainPanel, pos=wx.Point(345, 136),
84               size=wx.Size(32, 32), style=0)
85         self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton,
86               id=wxID_COMMUNICATIONDIALOGSELECT)
87
88         self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT,
89               label='<<', name='Unselect', parent=self.MainPanel,
90               pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0)
91         self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton,
92               id=wxID_COMMUNICATIONDIALOGUNSELECT)
93
94         self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1,
95               label='Possible Profile Indexes:', name='staticText1',
96               parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156,
97               17), style=0)
98
99         self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2,
100               label='Current Profile Indexes:', name='staticText2',
101               parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152,
102               17), style=0)
103
104         self._init_sizers()
105
106     def __init__(self, parent):
107         self._init_ctrls(parent)
108         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
109         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
110         self.AllList = []
111         self.CurrentList = []
112         self.IndexDictionary = {}
113
114     def SetIndexDictionary(self, dictionary):
115         self.IndexDictionary = dictionary
116         
117     def SetCurrentList(self, list):
118         self.CurrentList = []
119         self.CurrentList.extend(list)
120         self.CurrentList.sort()
121         
122     def GetCurrentList(self):
123         return self.CurrentList
124         
125     def RefreshLists(self):
126         self.PossibleIndexes.Clear()
127         self.CurrentIndexes.Clear()
128         self.AllList = []
129         for index in self.IndexDictionary.iterkeys():
130             if index not in self.CurrentList:
131                 self.AllList.append(index)
132         self.AllList.sort()
133         for index in self.AllList:
134             self.PossibleIndexes.Append("0x%04X   %s"%(index, self.IndexDictionary[index][0]))
135         for index in self.CurrentList:
136             if index in self.IndexDictionary:
137                 self.CurrentIndexes.Append("0x%04X   %s"%(index, self.IndexDictionary[index][0]))
138
139     def OnPossibleIndexesDClick(self, event):
140         self.SelectPossible()
141         event.Skip()
142
143     def OnCurrentIndexesDClick(self, event):
144         self.UnselectCurrent()
145         event.Skip()
146
147     def OnSelectButton(self, event):
148         self.SelectPossible()
149         event.Skip()
150
151     def OnUnselectButton(self, event):
152         self.UnselectCurrent()
153         event.Skip()
154
155     def SelectPossible(self):
156         selected = self.PossibleIndexes.GetSelections()
157         for i in selected:
158             self.CurrentList.append(self.AllList[i])
159         self.CurrentList.sort()
160         self.RefreshLists()
161
162     def UnselectCurrent(self):
163         selected = self.CurrentIndexes.GetSelections()
164         for i in selected:
165             if not self.IndexDictionary[self.CurrentList[i]][1]:
166                 self.CurrentList.pop(i)
167         self.CurrentList.sort()
168         self.RefreshLists()
169
170
171
172 #-------------------------------------------------------------------------------
173 #                          Create Map Variable Dialog
174 #-------------------------------------------------------------------------------
175
176
177 [wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX, 
178  wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL, 
179  wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1, 
180  wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3, 
181  wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2, 
182  wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4, 
183 ] = [wx.NewId() for _init_ctrls in range(12)]
184
185 class MapVariableDialog(wx.Dialog):
186     def _init_coll_flexGridSizer1_Items(self, parent):
187         # generated method, don't edit
188
189         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
190
191     def _init_sizers(self):
192         # generated method, don't edit
193         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
194
195         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
196
197         self.SetSizer(self.flexGridSizer1)
198
199     def _init_ctrls(self, prnt):
200         # generated method, don't edit
201         wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG,
202               name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
203               size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
204               title='Add Map Variable')
205         self.SetClientSize(wx.Size(444, 186))
206
207         self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL,
208               name='MainPanel', parent=self, pos=wx.Point(0, 0),
209               size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL)
210         self.MainPanel.SetAutoLayout(True)
211
212         self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1,
213               label='Index:', name='staticText1', parent=self.MainPanel,
214               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
215
216         self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index',
217               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152,
218               25), style=0, value='0x2000')
219
220         self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3,
221               label='Name:', name='staticText3', parent=self.MainPanel,
222               pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0)
223
224         self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME,
225               name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104),
226               size=wx.Size(152, 24), style=0, value='Undefined')
227
228         self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2,
229               label='Type:', name='staticText2', parent=self.MainPanel,
230               pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0)
231
232         self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1,
233               label='VAR', name='radioButton1', parent=self.MainPanel,
234               pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP)
235         self.radioButton1.SetValue(True)
236         self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click,
237               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1)
238
239         self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2,
240               label='ARRAY', name='radioButton2', parent=self.MainPanel,
241               pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE)
242         self.radioButton2.SetValue(False)
243         self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click,
244               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2)
245
246         self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3,
247               label='REC', name='radioButton3', parent=self.MainPanel,
248               pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE)
249         self.radioButton3.SetValue(False)
250         self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click,
251               id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3)
252
253         self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4,
254               label='Number:', name='staticText4', parent=self.MainPanel,
255               pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0)
256
257         self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER,
258               name='Number', parent=self.MainPanel, pos=wx.Point(312, 104),
259               size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0')
260
261         self._init_sizers()
262
263     def __init__(self, parent):
264         self._init_ctrls(parent)
265         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
266         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
267         self.staticText4.Enable(False)
268         self.Number.Enable(False)
269         
270         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
271
272     def SetIndex(self, index):
273         self.Index.SetValue("0x%04X"%index)
274
275     def OnOK(self, event):
276         error = []
277         try:
278             int(self.Index.GetValue(), 16)
279         except:
280             error.append("Index")
281         if self.radioButton2.GetValue() or self.radioButton3.GetValue():
282             try:
283                 int(self.Number.GetValue())
284             except:
285                 error.append("Number")
286         if len(error) > 0:
287             text = ""
288             if len(error) > 1:
289                 suffix = "s"
290             else:
291                 suffix = ""
292             for i, item in enumerate(error):
293                 if i == 0:
294                     text += item
295                 elif i == len(error) - 1:
296                     text += " and %s"%item
297                 else:
298                     text += ", %s"%item
299             message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR)
300             message.ShowModal()
301             message.Destroy()
302         else:
303             self.EndModal(wxID_OK)
304
305     def GetValues(self):
306         name = self.IndexName.GetValue()
307         index = int(self.Index.GetValue(), 16)
308         if self.radioButton1.GetValue():
309             struct = 1
310             number = None
311         elif self.radioButton2.GetValue():
312             struct = 3
313             number = int(self.Number.GetValue())
314         elif self.radioButton3.GetValue():
315             struct = 7
316             number = int(self.Number.GetValue())
317         return index, name, struct, number
318
319     def OnRadioButton1Click(self, event):
320         self.EnableNumberTyping(False)
321         event.Skip()
322
323     def OnRadioButton2Click(self, event):
324         self.EnableNumberTyping(True)
325         event.Skip()
326
327     def OnRadioButton3Click(self, event):
328         self.EnableNumberTyping(True)
329         event.Skip()
330
331     def EnableNumberTyping(self, enable):
332         self.staticText4.Enable(enable)
333         self.Number.Enable(enable)
334
335
336 #-------------------------------------------------------------------------------
337 #                          Create User Type Dialog
338 #-------------------------------------------------------------------------------
339
340
341 [wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL, 
342  wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN, 
343  wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1, 
344  wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3, 
345  wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE, 
346 ] = [wx.NewId() for _init_ctrls in range(11)]
347
348 class UserTypeDialog(wx.Dialog):
349     def _init_coll_flexGridSizer1_Items(self, parent):
350         # generated method, don't edit
351
352         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
353
354     def _init_sizers(self):
355         # generated method, don't edit
356         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
357
358         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
359
360         self.SetSizer(self.flexGridSizer1)
361
362     def _init_ctrls(self, prnt):
363         # generated method, don't edit
364         wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog',
365               parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228),
366               style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
367         self.SetClientSize(wx.Size(444, 228))
368
369         self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL,
370               name='MainPanel', parent=self, pos=wx.Point(0, 0),
371               size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL)
372         self.MainPanel.SetAutoLayout(True)
373
374         self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1,
375               label='Type:', name='staticText1', parent=self.MainPanel,
376               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
377
378         self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE,
379               name='Type', parent=self.MainPanel, pos=wx.Point(24, 48),
380               size=wx.Size(160, 24), style=0)
381         self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoice,
382               id=wxID_USERTYPEDIALOGTYPE)
383
384         self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1,
385               label='Values', name='staticBox1', parent=self.MainPanel,
386               pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0)
387
388         self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2,
389               label='Minimum:', name='staticText2', parent=self.MainPanel,
390               pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0)
391
392         self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min',
393               parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112,
394               24), style=wx.TE_RIGHT, value='0')
395
396         self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3,
397               label='Maximum:', name='staticText3', parent=self.MainPanel,
398               pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0)
399
400         self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max',
401               parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112,
402               25), style=wx.TE_RIGHT, value='0')
403
404         self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4,
405               label='Length:', name='staticText4', parent=self.MainPanel,
406               pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0)
407
408         self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length',
409               parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112,
410               25), style=wx.TE_RIGHT, value='0')
411
412         self._init_sizers()
413
414     def __init__(self, parent):
415         self._init_ctrls(parent)
416         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
417         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
418         self.TypeDictionary = {}
419
420         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
421
422     def OnOK(self, event):
423         error = []
424         good = True
425         firstmessage = ""
426         secondmessage = ""
427         name = self.Type.GetStringSelection()
428         if name != "":
429             valuetype = self.TypeDictionary[name][1]
430             if valuetype == 0:
431                 try:
432                     int(self.Min.GetValue(), 16)
433                 except:
434                     error.append("Minimum")
435                     good = False
436                 try:
437                     int(self.Max.GetValue(), 16)
438                 except:
439                     error.append("Maximum")
440                     good = False
441             elif valuetype == 1:
442                 try:
443                     int(self.Length.GetValue(), 16)
444                 except:
445                     error.append("Length")
446                     good = False
447             if len(error) > 0:
448                 secondmessage = ". "
449                 for i, item in enumerate(error):
450                     if i == 0:
451                         secondmessage += item
452                     elif i == len(error) - 1:
453                         secondmessage += " and %s"%item
454                     else:
455                         secondmessage += ", %s"%item
456                 secondmessage += " must be integer"
457                 if len(error) > 1:
458                     secondmessage += "s"
459         else:
460             firstmessage = ". A type must be selected"
461             good = False
462         if not good:
463             message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR)
464             message.ShowModal()
465             message.Destroy()
466             self.Name.SetFocus()
467         else:
468             self.EndModal(wxID_OK)
469
470     def SetValues(self, min = None, max = None, length = None):
471         if min != None:
472             self.Min.SetValue(str(min))
473         if max != None:
474             self.Max.SetValue(str(max))
475         if length != None:
476             self.Length.SetValue(str(length))
477
478     def SetTypeList(self, typedic, type = None):
479         self.Type.Clear()
480         list = []
481         for index, (name, valuetype) in typedic.iteritems():
482             self.TypeDictionary[name] = (index, valuetype)
483             list.append((index, name))
484         list.sort()
485         for index, name in list:
486             self.Type.Append(name)
487         if type != None:
488             self.Type.SetStringSelection(typedic[type][0])
489         self.RefreshValues()
490
491     def OnTypeChoice(self, event):
492         self.RefreshValues()
493         event.Skip()
494     
495     def RefreshValues(self):
496         name = self.Type.GetStringSelection()
497         if name != "":
498             valuetype = self.TypeDictionary[name][1]
499             if valuetype == 0:
500                 self.staticText2.Enable(True)
501                 self.staticText3.Enable(True)
502                 self.staticText4.Enable(False)
503                 self.Min.Enable(True)
504                 self.Max.Enable(True)
505                 self.Length.Enable(False)
506             elif valuetype == 1:
507                 self.staticText2.Enable(False)
508                 self.staticText3.Enable(False)
509                 self.staticText4.Enable(True)
510                 self.Min.Enable(False)
511                 self.Max.Enable(False)
512                 self.Length.Enable(True)
513         else:
514             self.staticText2.Enable(False)
515             self.staticText3.Enable(False)
516             self.staticText4.Enable(False)
517             self.Min.Enable(False)
518             self.Max.Enable(False)
519             self.Length.Enable(False)
520
521     def GetValues(self):
522         name = self.Type.GetStringSelection()
523         type = self.TypeDictionary[name][0]
524         min = int(self.Min.GetValue())
525         max = int(self.Max.GetValue())
526         length = int(self.Length.GetValue())
527         return type, min, max, length
528
529
530
531 #-------------------------------------------------------------------------------
532 #                          Editing Node Infos Dialog
533 #-------------------------------------------------------------------------------
534
535
536 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, 
537  wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, 
538  wxID_NODEINFOSDIALOGDESCRIPTION, wxID_NODEINFOSDIALOGSTATICTEXT1, 
539  wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, 
540  wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, 
541 ] = [wx.NewId() for _init_ctrls in range(10)]
542
543 class NodeInfosDialog(wx.Dialog):
544     def _init_coll_flexGridSizer1_Items(self, parent):
545         # generated method, don't edit
546
547         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
548
549     def _init_sizers(self):
550         # generated method, don't edit
551         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
552
553         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
554
555         self.SetSizer(self.flexGridSizer1)
556
557     def _init_ctrls(self, prnt):
558         # generated method, don't edit
559         wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG,
560               name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
561               size=wx.Size(300, 300), style=wx.DEFAULT_DIALOG_STYLE,
562               title='Node Infos')
563         self.SetClientSize(wx.Size(300, 300))
564
565         self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL,
566               name='MainPanel', parent=self, pos=wx.Point(0, 0),
567               size=wx.Size(280, 264), style=wx.TAB_TRAVERSAL)
568         self.MainPanel.SetAutoLayout(True)
569
570         self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
571               label='Name:', 
572               name='staticText1', parent=self.MainPanel,
573               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
574
575         self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name',
576               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(250,
577               25), style=0, value='')
578
579         self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2,
580               label='Node ID:', name='staticText2', parent=self.MainPanel,
581               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
582
583         self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID',
584               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(250,
585               25), style=wx.TE_RIGHT, value='')
586
587         self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3,
588               label='Type:', name='staticText3', parent=self.MainPanel,
589               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
590
591         self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE,
592               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
593               size=wx.Size(250, 25), style=0)
594
595         self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4,
596               label='Description:', name='staticText4', parent=self.MainPanel,
597               pos=wx.Point(24, 192), size=wx.Size(71, 17), style=0)
598
599         self.Description = wx.TextCtrl(id=wxID_NODEINFOSDIALOGDESCRIPTION, 
600               name='Description', parent=self.MainPanel, pos=wx.Point(24, 216), 
601               size=wx.Size(250, 25), style=0, value='')
602
603         self._init_sizers()
604
605     def __init__(self, parent):
606         self._init_ctrls(parent)
607         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
608         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
609         self.Type.Append("master")
610         self.Type.Append("slave")
611
612         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
613
614     def OnOK(self, event):
615         name = self.Name.GetValue()
616         message = ""
617         if name != "":
618             good = not name[0].isdigit()
619             for item in name.split("_"):
620                 good &= item.isalnum()
621             if not good:
622                 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
623         if message != "":
624             try:
625                 nodeid = int(self.NodeID.GetValue(), 16)
626             except:
627                 message = "Node ID must be integer!"
628         if message != "":
629             message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
630             message.ShowModal()
631             message.Destroy()
632             self.Name.SetFocus()
633         else:
634             self.EndModal(wxID_OK)
635     
636     def SetValues(self, name, id, type, description):
637         self.Name.SetValue(name)
638         self.NodeID.SetValue("0x%02X"%id)
639         self.Type.SetStringSelection(type)
640         self.Description.SetValue(description)
641
642     def GetValues(self):
643         name = self.Name.GetValue()
644         nodeid = int(self.NodeID.GetValue(), 16)
645         type = self.Type.GetStringSelection()
646         description = self.Description.GetValue()
647         return name, nodeid, type, description
648
649
650
651 #-------------------------------------------------------------------------------
652 #                          Create New Node Dialog
653 #-------------------------------------------------------------------------------
654
655
656 [wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY, 
657  wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL, 
658  wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT, 
659  wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, 
660  wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, 
661  wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, 
662  wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, 
663  wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, 
664  wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTATICTEXT7,
665  wxID_CREATENODEDIALOGSTOREEDS, wxID_CREATENODEDIALOGDESCRIPTION,
666  wxID_CREATENODEDIALOGTYPE, 
667 ] = [wx.NewId() for _init_ctrls in range(21)]
668
669 class CreateNodeDialog(wx.Dialog):
670     def _init_coll_flexGridSizer1_Items(self, parent):
671         # generated method, don't edit
672
673         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
674
675     def _init_sizers(self):
676         # generated method, don't edit
677         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
678
679         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
680
681         self.SetSizer(self.flexGridSizer1)
682
683     def _init_ctrls(self, prnt):
684         # generated method, don't edit
685         wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG,
686               name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
687               size=wx.Size(451, 376), style=wx.DEFAULT_DIALOG_STYLE,
688               title='Create a new Node')
689         self.SetClientSize(wx.Size(451, 376))
690
691         self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL,
692               name='MainPanel', parent=self, pos=wx.Point(0, 0),
693               size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL)
694         self.MainPanel.SetAutoLayout(True)
695
696         self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1,
697               label='Name:', name='staticText1', parent=self.MainPanel,
698               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
699
700         self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2,
701               label='Node ID:', name='staticText2', parent=self.MainPanel,
702               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
703
704         self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3,
705               label='Type:', name='staticText3', parent=self.MainPanel,
706               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
707
708         self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE,
709               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
710               size=wx.Size(200, 24), style=0)
711
712         self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name',
713               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200,
714               25), style=0, value='')
715
716         self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID',
717               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200,
718               25), style=wx.TE_RIGHT, value='')
719
720         self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4,
721               label='Profile:', name='staticText4', parent=self.MainPanel,
722               pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0)
723
724         self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE,
725               name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216),
726               size=wx.Size(200, 24), style=0)
727         self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoice,
728               id=wxID_CREATENODEDIALOGPROFILE)
729
730         self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5,
731               label='Network Management:', name='staticText5',
732               parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152,
733               16), style=0)
734
735         self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE,
736               label='None', name='NMT_None', parent=self.MainPanel,
737               pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0)
738         self.NMT_None.SetValue(True)
739
740         self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING,
741               label='Node Guarding', name='NMT_NodeGuarding',
742               parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128,
743               24), style=0)
744         self.NMT_NodeGuarding.SetValue(False)
745
746         self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT,
747               label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel,
748               pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0)
749         self.NMT_Heartbeat.SetValue(False)
750
751         self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6,
752               label='Options:', name='staticText6', parent=self.MainPanel,
753               pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0)
754
755         self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
756               label='DS-302 Profile', name='DS302', parent=self.MainPanel,
757               pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0)
758         self.DS302.SetValue(False)
759         #self.DS302.Enable(False)
760
761         self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
762               label='Generate SYNC', name='GenSYNC', parent=self.MainPanel,
763               pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0)
764         self.GenSYNC.SetValue(False)
765
766         self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY,
767               label='Emergency support', name='Emergency',
768               parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152,
769               24), style=0)
770         self.Emergency.SetValue(False)
771         self.Emergency.Enable(False)
772
773         self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG,
774               label='Save Configuration', name='SaveConfig',
775               parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152,
776               24), style=0)
777         self.SaveConfig.SetValue(False)
778         self.SaveConfig.Enable(False)
779
780 #        self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS,
781 #              label='Store EDS', name='StoreEDS', parent=self.MainPanel,
782 #              pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0)
783 #        self.StoreEDS.SetValue(False)
784
785         self.staticText7 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT7,
786               label='Description:', name='staticText7', parent=self.MainPanel,
787               pos=wx.Point(24, 248), size=wx.Size(71, 17), style=0)
788
789         self.Description = wx.TextCtrl(id=wxID_CREATENODEDIALOGDESCRIPTION, 
790               name='Description', parent=self.MainPanel, pos=wx.Point(24, 272), 
791               size=wx.Size(400, 25), style=0, value='')
792
793         self._init_sizers()
794
795     def __init__(self, parent):
796         self._init_ctrls(parent)
797         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
798         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
799         self.NodeID.SetValue("0x00")
800         self.Type.Append("master")
801         self.Type.Append("slave")
802         self.Type.SetStringSelection("slave")
803         self.Description.SetValue("")
804         self.ListProfile = {"None" : ""}
805         self.Profile.Append("None")
806         self.Directory = os.path.join(ScriptDirectory, "config")
807         listfiles = os.listdir(self.Directory)
808         listfiles.sort()
809         for item in listfiles:
810             name, extend = os.path.splitext(item)
811             if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302":
812                 self.ListProfile[name] = os.path.join(self.Directory, item)
813                 self.Profile.Append(name)
814         self.Profile.Append("Other")
815         self.Profile.SetStringSelection("None")
816         self.Name.SetFocus()
817         
818         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
819
820     def OnOK(self, event):
821         name = self.Name.GetValue()
822         message = ""
823         if name != "":
824             good = not name[0].isdigit()
825             for item in name.split("_"):
826                 good &= item.isalnum()
827             if not good:
828                 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
829         if message != "":
830             try:
831                 nodeid = int(self.NodeID.GetValue(), 16)
832             except:
833                 message = "Node ID must be an integer!"
834         if message != "":
835             message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
836             message.ShowModal()
837             message.Destroy()
838             self.Name.SetFocus()
839         else:
840             self.EndModal(wxID_OK)
841
842     def GetValues(self):
843         name = self.Name.GetValue()
844         nodeid = 0
845         if self.NodeID.GetValue() != "":
846             nodeid = int(self.NodeID.GetValue(), 16)
847         type = self.Type.GetStringSelection()
848         description = self.Description.GetValue()
849         return name, nodeid, type, description
850
851     def GetProfile(self):
852         name = self.Profile.GetStringSelection()
853         return name, self.ListProfile[name]
854
855     def GetNMTManagement(self):
856         if self.NMT_None.GetValue():
857             return "None"
858         elif self.NMT_NodeGuarding.GetValue():
859             return "NodeGuarding"
860         elif self.NMT_Heartbeat.GetValue():
861             return "Heartbeat"
862         return None
863     
864     def GetOptions(self):
865         options = []
866         if self.DS302.GetValue():
867             options.append("DS302")
868         if self.GenSYNC.GetValue():
869             options.append("GenSYNC")
870         if self.Emergency.GetValue():
871             options.append("Emergency")
872         if self.SaveConfig.GetValue():
873             options.append("SaveConfig")
874 #        if self.StoreEDS.GetValue():
875 #            options.append("StoreEDS")
876         return options
877
878     def OnProfileChoice(self, event):
879         if self.Profile.GetStringSelection() == "Other":
880             dialog = wxFileDialog(self, "Choose a file", self.Directory, "",  "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR)
881             dialog.ShowModal()
882             filepath = dialog.GetPath()
883             dialog.Destroy()
884             if os.path.isfile(filepath):
885                 name = os.path.splitext(os.path.basename(filepath))[0]
886                 self.ListProfile[name] = filepath
887                 length = self.Profile.GetCount()
888                 self.Profile.Insert(name, length - 2)
889                 self.Profile.SetStringSelection(name)
890             else:
891                 self.Profile.SetStringSelection("None")
892         event.Skip()
893
894
895 #-------------------------------------------------------------------------------
896 #                            ADD Slave to NodeList Dialog
897 #-------------------------------------------------------------------------------
898
899 [wxID_ADDSLAVEDIALOG, wxID_ADDSLAVEDIALOGMAINPANEL, wxID_ADDSLAVEDIALOGSLAVENAME, 
900  wxID_ADDSLAVEDIALOGSLAVENODEID, wxID_ADDSLAVEDIALOGEDSFILE, 
901  wxID_ADDSLAVEDIALOGIMPORTEDS, wxID_ADDSLAVEDIALOGSTATICTEXT1, 
902  wxID_ADDSLAVEDIALOGSTATICTEXT2, wxID_ADDSLAVEDIALOGSTATICTEXT3, 
903 ] = [wx.NewId() for _init_ctrls in range(9)]
904
905 class AddSlaveDialog(wx.Dialog):
906     def _init_coll_flexGridSizer1_Items(self, parent):
907         # generated method, don't edit
908
909         parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
910
911     def _init_sizers(self):
912         # generated method, don't edit
913         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
914
915         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
916
917         self.SetSizer(self.flexGridSizer1)
918
919     def _init_ctrls(self, prnt):
920         # generated method, don't edit
921         wx.Dialog.__init__(self, id=wxID_ADDSLAVEDIALOG,
922               name='AddSlaveDialog', parent=prnt, pos=wx.Point(376, 223),
923               size=wx.Size(300, 250), style=wx.DEFAULT_DIALOG_STYLE,
924               title='Add a slave to nodelist')
925         self.SetClientSize(wx.Size(300, 250))
926
927         self.MainPanel = wx.Panel(id=wxID_ADDSLAVEDIALOGMAINPANEL,
928               name='MainPanel', parent=self, pos=wx.Point(0, 0),
929               size=wx.Size(350, 250), style=wx.TAB_TRAVERSAL)
930         self.MainPanel.SetAutoLayout(True)
931
932         self.staticText1 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT1,
933               label='Slave Name:', name='staticText1', parent=self.MainPanel,
934               pos=wx.Point(24, 24), size=wx.Size(150, 17), style=0)
935
936         self.SlaveName = wx.TextCtrl(id=wxID_ADDSLAVEDIALOGSLAVENAME,
937               name='SlaveName', parent=self.MainPanel, pos=wx.Point(24, 48), 
938               size=wx.Size(250, 24), style=0)
939
940         self.staticText2 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT2,
941               label='Slave Node ID:', name='staticText2', parent=self.MainPanel,
942               pos=wx.Point(24, 80), size=wx.Size(150, 17), style=0)
943
944         self.SlaveNodeID = wx.TextCtrl(id=wxID_ADDSLAVEDIALOGSLAVENODEID,
945               name='SlaveName', parent=self.MainPanel, pos=wx.Point(24, 104), 
946               size=wx.Size(250, 24), style=wxALIGN_RIGHT)
947
948         self.staticText3 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT3,
949               label='EDS File:', name='staticText3', parent=self.MainPanel,
950               pos=wx.Point(24, 136), size=wx.Size(155, 17), style=0)
951
952         self.EDSFile = wx.Choice(id=wxID_ADDSLAVEDIALOGEDSFILE,
953               name='EDSFile', parent=self.MainPanel, pos=wx.Point(24, 160),
954               size=wx.Size(145, 24), style=0)
955         
956         self.ImportEDS = wxButton(id=wxID_ADDSLAVEDIALOGIMPORTEDS, label='Import EDS',
957               name='ImportEDS', parent=self.MainPanel, pos=wx.Point(174, 160),
958               size=wx.Size(100, 32), style=0)
959         self.ImportEDS.Bind(wx.EVT_BUTTON, self.OnImportEDSButton,
960               id=wxID_ADDSLAVEDIALOGIMPORTEDS)
961         
962         self._init_sizers()
963
964     def __init__(self, parent):
965         self._init_ctrls(parent)
966         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
967         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
968         
969         self.SlaveNodeID.SetValue("0x00")
970         
971         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
972     
973     def OnOK(self, event):
974         error = []
975         if self.SlaveName.GetValue() == "":
976             error.append("Slave Name")
977         if self.SlaveNodeID.GetValue() == "":
978             error.append("Slave Node ID")
979         if self.EDSFile.GetStringSelection() == "":
980             error.append("EDS File")
981         if len(error) > 0:
982             text = ""
983             for i, item in enumerate(error):
984                 if i == 0:
985                     text += item
986                 elif i == len(error) - 1:
987                     text += " and %s"%item
988                 else:
989                     text += ", %s"%item 
990             message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR)
991             message.ShowModal()
992             message.Destroy()
993         else:
994             try:
995                 nodeid = self.SlaveNodeID.GetValue()
996                 if nodeid.find("x") != -1:
997                     nodeid = int(nodeid, 16)
998                 else:
999                     nodeid = int(nodeid)
1000             except:
1001                 message = wxMessageDialog(self, "Slave Node ID must be a value in decimal or hexadecimal!", "Error", wxOK|wxICON_ERROR)
1002                 message.ShowModal()
1003                 message.Destroy()
1004                 return
1005             if not 0 <= nodeid <= 127:
1006                 message = wxMessageDialog(self, "Slave Node ID must be between 0 and 127!", "Error", wxOK|wxICON_ERROR)
1007                 message.ShowModal()
1008                 message.Destroy()
1009             elif nodeid == 0 or nodeid in self.NodeList.SlaveNodes.keys():
1010                 message = wxMessageDialog(self, "A Node with this ID already exist in the network!", "Error", wxOK|wxICON_ERROR)
1011                 message.ShowModal()
1012                 message.Destroy()
1013             else:
1014                 self.EndModal(wxID_OK)
1015
1016     def OnImportEDSButton(self, event):
1017         dialog = wxFileDialog(self, "Choose an EDS file", os.getcwd(), "",  "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR)
1018         if dialog.ShowModal() == wxID_OK:
1019             filepath = dialog.GetPath()
1020             if os.path.isfile(filepath):
1021                 result = self.NodeList.ImportEDSFile(filepath)
1022                 if result:
1023                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1024                     message.ShowModal()
1025                     message.Destroy()
1026         dialog.Destroy()
1027         self.RefreshEDSFile()
1028         event.Skip()
1029
1030     def RefreshEDSFile(self):
1031         selection = self.EDSFile.GetStringSelection()
1032         self.EDSFile.Clear()
1033         for option in self.NodeList.EDSNodes.keys():
1034             self.EDSFile.Append(option)
1035         if self.EDSFile.FindString(selection) != wxNOT_FOUND:
1036             self.EDSFile.SetStringSelection(selection)
1037     
1038     def SetNodeList(self, nodelist):
1039         self.NodeList = nodelist
1040         self.RefreshEDSFile()
1041     
1042     def GetValues(self):
1043         values = {}
1044         values["slaveName"] = self.SlaveName.GetValue()
1045         nodeid = self.SlaveNodeID.GetValue()
1046         if nodeid.find("x") != -1:
1047             values["slaveNodeID"] = int(nodeid, 16)
1048         else:
1049             values["slaveNodeID"] = int(nodeid)
1050         values["edsFile"] = self.EDSFile.GetStringSelection()
1051         return values