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
24 from wxPython.wx import *
25 from wxPython.grid import *
30 #-------------------------------------------------------------------------------
31 # Editing Communication Dialog
32 #-------------------------------------------------------------------------------
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)]
41 class CommunicationDialog(wx.Dialog):
42 def _init_coll_flexGridSizer1_Items(self, parent):
43 # generated method, don't edit
45 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
47 def _init_sizers(self):
48 # generated method, don't edit
49 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
51 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
53 self.SetSizer(self.flexGridSizer1)
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))
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)
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)
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)
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)
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)
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,
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,
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)
111 self.CurrentList = []
112 self.IndexDictionary = {}
114 def SetIndexDictionary(self, dictionary):
115 self.IndexDictionary = dictionary
117 def SetCurrentList(self, list):
118 self.CurrentList = []
119 self.CurrentList.extend(list)
120 self.CurrentList.sort()
122 def GetCurrentList(self):
123 return self.CurrentList
125 def RefreshLists(self):
126 self.PossibleIndexes.Clear()
127 self.CurrentIndexes.Clear()
129 for index in self.IndexDictionary.iterkeys():
130 if index not in self.CurrentList:
131 self.AllList.append(index)
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]))
139 def OnPossibleIndexesDClick(self, event):
140 self.SelectPossible()
143 def OnCurrentIndexesDClick(self, event):
144 self.UnselectCurrent()
147 def OnSelectButton(self, event):
148 self.SelectPossible()
151 def OnUnselectButton(self, event):
152 self.UnselectCurrent()
155 def SelectPossible(self):
156 selected = self.PossibleIndexes.GetSelections()
158 self.CurrentList.append(self.AllList[i])
159 self.CurrentList.sort()
162 def UnselectCurrent(self):
163 selected = self.CurrentIndexes.GetSelections()
165 if not self.IndexDictionary[self.CurrentList[i]][1]:
166 self.CurrentList.pop(i)
167 self.CurrentList.sort()
172 #-------------------------------------------------------------------------------
173 # Create Map Variable Dialog
174 #-------------------------------------------------------------------------------
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)]
185 class MapVariableDialog(wx.Dialog):
186 def _init_coll_flexGridSizer1_Items(self, parent):
187 # generated method, don't edit
189 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
191 def _init_sizers(self):
192 # generated method, don't edit
193 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
195 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
197 self.SetSizer(self.flexGridSizer1)
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))
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)
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)
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')
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)
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')
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)
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)
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)
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)
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)
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')
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)
270 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
272 def SetIndex(self, index):
273 self.Index.SetValue("0x%04X"%index)
275 def OnOK(self, event):
278 int(self.Index.GetValue(), 16)
280 error.append("Index")
281 if self.radioButton2.GetValue() or self.radioButton3.GetValue():
283 int(self.Number.GetValue())
285 error.append("Number")
292 for i, item in enumerate(error):
295 elif i == len(error) - 1:
296 text += " and %s"%item
299 message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR)
303 self.EndModal(wxID_OK)
306 name = self.IndexName.GetValue()
307 index = int(self.Index.GetValue(), 16)
308 if self.radioButton1.GetValue():
311 elif self.radioButton2.GetValue():
313 number = int(self.Number.GetValue())
314 elif self.radioButton3.GetValue():
316 number = int(self.Number.GetValue())
317 return index, name, struct, number
319 def OnRadioButton1Click(self, event):
320 self.EnableNumberTyping(False)
323 def OnRadioButton2Click(self, event):
324 self.EnableNumberTyping(True)
327 def OnRadioButton3Click(self, event):
328 self.EnableNumberTyping(True)
331 def EnableNumberTyping(self, enable):
332 self.staticText4.Enable(enable)
333 self.Number.Enable(enable)
336 #-------------------------------------------------------------------------------
337 # Create User Type Dialog
338 #-------------------------------------------------------------------------------
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)]
348 class UserTypeDialog(wx.Dialog):
349 def _init_coll_flexGridSizer1_Items(self, parent):
350 # generated method, don't edit
352 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
354 def _init_sizers(self):
355 # generated method, don't edit
356 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
358 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
360 self.SetSizer(self.flexGridSizer1)
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))
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)
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)
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)
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)
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)
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')
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)
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')
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)
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')
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 = {}
420 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
422 def OnOK(self, event):
427 name = self.Type.GetStringSelection()
429 valuetype = self.TypeDictionary[name][1]
432 int(self.Min.GetValue(), 16)
434 error.append("Minimum")
437 int(self.Max.GetValue(), 16)
439 error.append("Maximum")
443 int(self.Length.GetValue(), 16)
445 error.append("Length")
449 for i, item in enumerate(error):
451 secondmessage += item
452 elif i == len(error) - 1:
453 secondmessage += " and %s"%item
455 secondmessage += ", %s"%item
456 secondmessage += " must be integer"
460 firstmessage = ". A type must be selected"
463 message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR)
468 self.EndModal(wxID_OK)
470 def SetValues(self, min = None, max = None, length = None):
472 self.Min.SetValue(str(min))
474 self.Max.SetValue(str(max))
476 self.Length.SetValue(str(length))
478 def SetTypeList(self, typedic, type = None):
481 for index, (name, valuetype) in typedic.iteritems():
482 self.TypeDictionary[name] = (index, valuetype)
483 list.append((index, name))
485 for index, name in list:
486 self.Type.Append(name)
488 self.Type.SetStringSelection(typedic[type][0])
491 def OnTypeChoice(self, event):
495 def RefreshValues(self):
496 name = self.Type.GetStringSelection()
498 valuetype = self.TypeDictionary[name][1]
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)
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)
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)
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
531 #-------------------------------------------------------------------------------
532 # Editing Node Infos Dialog
533 #-------------------------------------------------------------------------------
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)]
543 class NodeInfosDialog(wx.Dialog):
544 def _init_coll_flexGridSizer1_Items(self, parent):
545 # generated method, don't edit
547 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
549 def _init_sizers(self):
550 # generated method, don't edit
551 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
553 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
555 self.SetSizer(self.flexGridSizer1)
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,
563 self.SetClientSize(wx.Size(300, 300))
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)
570 self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
572 name='staticText1', parent=self.MainPanel,
573 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
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='')
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)
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='')
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)
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)
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)
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='')
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")
612 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
614 def OnOK(self, event):
615 name = self.Name.GetValue()
618 good = not name[0].isdigit()
619 for item in name.split("_"):
620 good &= item.isalnum()
622 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
625 nodeid = int(self.NodeID.GetValue(), 16)
627 message = "Node ID must be integer!"
629 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
634 self.EndModal(wxID_OK)
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)
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
651 #-------------------------------------------------------------------------------
652 # Create New Node Dialog
653 #-------------------------------------------------------------------------------
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)]
669 class CreateNodeDialog(wx.Dialog):
670 def _init_coll_flexGridSizer1_Items(self, parent):
671 # generated method, don't edit
673 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
675 def _init_sizers(self):
676 # generated method, don't edit
677 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
679 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
681 self.SetSizer(self.flexGridSizer1)
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))
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)
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)
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)
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)
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)
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='')
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='')
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)
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)
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,
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)
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,
744 self.NMT_NodeGuarding.SetValue(False)
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)
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)
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)
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)
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,
770 self.Emergency.SetValue(False)
771 self.Emergency.Enable(False)
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,
777 self.SaveConfig.SetValue(False)
778 self.SaveConfig.Enable(False)
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)
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)
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='')
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)
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")
818 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
820 def OnOK(self, event):
821 name = self.Name.GetValue()
824 good = not name[0].isdigit()
825 for item in name.split("_"):
826 good &= item.isalnum()
828 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
831 nodeid = int(self.NodeID.GetValue(), 16)
833 message = "Node ID must be an integer!"
835 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
840 self.EndModal(wxID_OK)
843 name = self.Name.GetValue()
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
851 def GetProfile(self):
852 name = self.Profile.GetStringSelection()
853 return name, self.ListProfile[name]
855 def GetNMTManagement(self):
856 if self.NMT_None.GetValue():
858 elif self.NMT_NodeGuarding.GetValue():
859 return "NodeGuarding"
860 elif self.NMT_Heartbeat.GetValue():
864 def GetOptions(self):
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")
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)
882 filepath = dialog.GetPath()
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)
891 self.Profile.SetStringSelection("None")
895 #-------------------------------------------------------------------------------
896 # ADD Slave to NodeList Dialog
897 #-------------------------------------------------------------------------------
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)]
905 class AddSlaveDialog(wx.Dialog):
906 def _init_coll_flexGridSizer1_Items(self, parent):
907 # generated method, don't edit
909 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
911 def _init_sizers(self):
912 # generated method, don't edit
913 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
915 self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
917 self.SetSizer(self.flexGridSizer1)
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))
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)
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)
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)
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)
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)
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)
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)
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)
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)
969 self.SlaveNodeID.SetValue("0x00")
971 EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
973 def OnOK(self, event):
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")
983 for i, item in enumerate(error):
986 elif i == len(error) - 1:
987 text += " and %s"%item
990 message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR)
995 nodeid = self.SlaveNodeID.GetValue()
996 if nodeid.find("x") != -1:
997 nodeid = int(nodeid, 16)
1001 message = wxMessageDialog(self, "Slave Node ID must be a value in decimal or hexadecimal!", "Error", wxOK|wxICON_ERROR)
1005 if not 0 <= nodeid <= 127:
1006 message = wxMessageDialog(self, "Slave Node ID must be between 0 and 127!", "Error", wxOK|wxICON_ERROR)
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)
1014 self.EndModal(wxID_OK)
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)
1023 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
1027 self.RefreshEDSFile()
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)
1038 def SetNodeList(self, nodelist):
1039 self.NodeList = nodelist
1040 self.RefreshEDSFile()
1042 def GetValues(self):
1044 values["slaveName"] = self.SlaveName.GetValue()
1045 nodeid = self.SlaveNodeID.GetValue()
1046 if nodeid.find("x") != -1:
1047 values["slaveNodeID"] = int(nodeid, 16)
1049 values["slaveNodeID"] = int(nodeid)
1050 values["edsFile"] = self.EDSFile.GetStringSelection()