00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 from wxPython.wx import *
00025 from wxPython.grid import *
00026 import wx
00027
00028 import os
00029
00030
00031
00032
00033
00034
00035 [wxID_COMMUNICATIONDIALOG, wxID_COMMUNICATIONDIALOGMAINPANEL,
00036 wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, wxID_COMMUNICATIONDIALOGCURRENTINDEXES,
00037 wxID_COMMUNICATIONDIALOGSELECT, wxID_COMMUNICATIONDIALOGUNSELECT,
00038 wxID_COMMUNICATIONDIALOGSTATICTEXT1, wxID_COMMUNICATIONDIALOGSTATICTEXT2
00039 ] = [wx.NewId() for _init_ctrls in range(8)]
00040
00041 class CommunicationDialog(wx.Dialog):
00042 def _init_coll_flexGridSizer1_Items(self, parent):
00043
00044
00045 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00046
00047 def _init_sizers(self):
00048
00049 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00050
00051 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00052
00053 self.SetSizer(self.flexGridSizer1)
00054
00055 def _init_ctrls(self, prnt):
00056
00057 wx.Dialog.__init__(self, id=wxID_COMMUNICATIONDIALOG,
00058 name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216),
00059 size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE,
00060 title='Edit Communication Profile')
00061 self.SetClientSize(wx.Size(726, 437))
00062
00063 self.MainPanel = wx.Panel(id=wxID_COMMUNICATIONDIALOGMAINPANEL,
00064 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00065 size=wx.Size(688, 382), style=wx.TAB_TRAVERSAL)
00066 self.MainPanel.SetAutoLayout(True)
00067
00068 self.PossibleIndexes = wx.ListBox(choices=[],
00069 id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES,
00070 name='PossibleIndexes', parent=self.MainPanel, pos=wx.Point(40,
00071 48), size=wx.Size(280, 320), style=wxLB_EXTENDED)
00072 self.PossibleIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnPossibleIndexesDClickOnPossibleIndexesDClick,
00073 id=wxID_COMMUNICATIONDIALOGPOSSIBLEINDEXES)
00074
00075 self.CurrentIndexes = wx.ListBox(choices=[],
00076 id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes',
00077 parent=self.MainPanel, pos=wx.Point(400, 48), size=wx.Size(280,
00078 320), style=wxLB_EXTENDED)
00079 self.CurrentIndexes.Bind(wx.EVT_LEFT_DCLICK, self.OnCurrentIndexesDClickOnCurrentIndexesDClick,
00080 id=wxID_COMMUNICATIONDIALOGCURRENTINDEXES)
00081
00082 self.Select = wx.Button(id=wxID_COMMUNICATIONDIALOGSELECT, label='>>',
00083 name='Select', parent=self.MainPanel, pos=wx.Point(345, 136),
00084 size=wx.Size(32, 32), style=0)
00085 self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButtonOnSelectButton,
00086 id=wxID_COMMUNICATIONDIALOGSELECT)
00087
00088 self.Unselect = wx.Button(id=wxID_COMMUNICATIONDIALOGUNSELECT,
00089 label='<<', name='Unselect', parent=self.MainPanel,
00090 pos=wx.Point(345, 216), size=wx.Size(32, 30), style=0)
00091 self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButtonOnUnselectButton,
00092 id=wxID_COMMUNICATIONDIALOGUNSELECT)
00093
00094 self.staticText1 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT1,
00095 label='Possible Profile Indexes:', name='staticText1',
00096 parent=self.MainPanel, pos=wx.Point(40, 24), size=wx.Size(156,
00097 17), style=0)
00098
00099 self.staticText2 = wx.StaticText(id=wxID_COMMUNICATIONDIALOGSTATICTEXT2,
00100 label='Current Profile Indexes:', name='staticText2',
00101 parent=self.MainPanel, pos=wx.Point(400, 24), size=wx.Size(152,
00102 17), style=0)
00103
00104 self._init_sizers_init_sizers()
00105
00106 def __init__(self, parent):
00107 self._init_ctrls_init_ctrls(parent)
00108 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
00109 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_CENTER)
00110 self.AllListAllList = []
00111 self.CurrentListCurrentList = []
00112 self.IndexDictionaryIndexDictionary = {}
00113
00114 def SetIndexDictionary(self, dictionary):
00115 self.IndexDictionaryIndexDictionary = dictionary
00116
00117 def SetCurrentList(self, list):
00118 self.CurrentListCurrentList = []
00119 self.CurrentListCurrentList.extend(list)
00120 self.CurrentListCurrentList.sort()
00121
00122 def GetCurrentList(self):
00123 return self.CurrentListCurrentList
00124
00125 def RefreshLists(self):
00126 self.PossibleIndexes.Clear()
00127 self.CurrentIndexes.Clear()
00128 self.AllListAllList = []
00129 for index in self.IndexDictionaryIndexDictionary.iterkeys():
00130 if index not in self.CurrentListCurrentList:
00131 self.AllListAllList.append(index)
00132 self.AllListAllList.sort()
00133 for index in self.AllListAllList:
00134 self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionaryIndexDictionary[index][0]))
00135 for index in self.CurrentListCurrentList:
00136 if index in self.IndexDictionaryIndexDictionary:
00137 self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionaryIndexDictionary[index][0]))
00138
00139 def OnPossibleIndexesDClick(self, event):
00140 self.SelectPossibleSelectPossible()
00141 event.Skip()
00142
00143 def OnCurrentIndexesDClick(self, event):
00144 self.UnselectCurrentUnselectCurrent()
00145 event.Skip()
00146
00147 def OnSelectButton(self, event):
00148 self.SelectPossibleSelectPossible()
00149 event.Skip()
00150
00151 def OnUnselectButton(self, event):
00152 self.UnselectCurrentUnselectCurrent()
00153 event.Skip()
00154
00155 def SelectPossible(self):
00156 selected = self.PossibleIndexes.GetSelections()
00157 for i in selected:
00158 self.CurrentListCurrentList.append(self.AllListAllList[i])
00159 self.CurrentListCurrentList.sort()
00160 self.RefreshListsRefreshLists()
00161
00162 def UnselectCurrent(self):
00163 selected = self.CurrentIndexes.GetSelections()
00164 for i in selected:
00165 if not self.IndexDictionaryIndexDictionary[self.CurrentListCurrentList[i]][1]:
00166 self.CurrentListCurrentList.pop(i)
00167 self.CurrentListCurrentList.sort()
00168 self.RefreshListsRefreshLists()
00169
00170
00171
00172
00173
00174
00175
00176
00177 [wxID_MAPVARIABLEDIALOG, wxID_MAPVARIABLEDIALOGINDEX,
00178 wxID_MAPVARIABLEDIALOGINDEXNAME, wxID_MAPVARIABLEDIALOGMAINPANEL,
00179 wxID_MAPVARIABLEDIALOGNUMBER, wxID_MAPVARIABLEDIALOGRADIOBUTTON1,
00180 wxID_MAPVARIABLEDIALOGRADIOBUTTON2, wxID_MAPVARIABLEDIALOGRADIOBUTTON3,
00181 wxID_MAPVARIABLEDIALOGSTATICTEXT1, wxID_MAPVARIABLEDIALOGSTATICTEXT2,
00182 wxID_MAPVARIABLEDIALOGSTATICTEXT3, wxID_MAPVARIABLEDIALOGSTATICTEXT4,
00183 ] = [wx.NewId() for _init_ctrls in range(12)]
00184
00185 class MapVariableDialog(wx.Dialog):
00186 def _init_coll_flexGridSizer1_Items(self, parent):
00187
00188
00189 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00190
00191 def _init_sizers(self):
00192
00193 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00194
00195 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00196
00197 self.SetSizer(self.flexGridSizer1)
00198
00199 def _init_ctrls(self, prnt):
00200
00201 wx.Dialog.__init__(self, id=wxID_MAPVARIABLEDIALOG,
00202 name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223),
00203 size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE,
00204 title='Add Map Variable')
00205 self.SetClientSize(wx.Size(444, 186))
00206
00207 self.MainPanel = wx.Panel(id=wxID_MAPVARIABLEDIALOGMAINPANEL,
00208 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00209 size=wx.Size(431, 142), style=wx.TAB_TRAVERSAL)
00210 self.MainPanel.SetAutoLayout(True)
00211
00212 self.staticText1 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT1,
00213 label='Index:', name='staticText1', parent=self.MainPanel,
00214 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
00215
00216 self.Index = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEX, name='Index',
00217 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(152,
00218 25), style=0, value='0x2000')
00219
00220 self.staticText3 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT3,
00221 label='Name:', name='staticText3', parent=self.MainPanel,
00222 pos=wx.Point(24, 80), size=wx.Size(47, 17), style=0)
00223
00224 self.IndexName = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGINDEXNAME,
00225 name='IndexName', parent=self.MainPanel, pos=wx.Point(24, 104),
00226 size=wx.Size(152, 24), style=0, value='Undefined')
00227
00228 self.staticText2 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT2,
00229 label='Type:', name='staticText2', parent=self.MainPanel,
00230 pos=wx.Point(208, 24), size=wx.Size(38, 17), style=0)
00231
00232 self.radioButton1 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1,
00233 label='VAR', name='radioButton1', parent=self.MainPanel,
00234 pos=wx.Point(208, 48), size=wx.Size(72, 24), style=wxRB_GROUP)
00235 self.radioButton1.SetValue(True)
00236 self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1ClickOnRadioButton1Click,
00237 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON1)
00238
00239 self.radioButton2 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2,
00240 label='ARRAY', name='radioButton2', parent=self.MainPanel,
00241 pos=wx.Point(208, 72), size=wx.Size(80, 24), style=wxRB_SINGLE)
00242 self.radioButton2.SetValue(False)
00243 self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2ClickOnRadioButton2Click,
00244 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON2)
00245
00246 self.radioButton3 = wx.RadioButton(id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3,
00247 label='REC', name='radioButton3', parent=self.MainPanel,
00248 pos=wx.Point(208, 96), size=wx.Size(96, 24), style=wxRB_SINGLE)
00249 self.radioButton3.SetValue(False)
00250 self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3ClickOnRadioButton3Click,
00251 id=wxID_MAPVARIABLEDIALOGRADIOBUTTON3)
00252
00253 self.staticText4 = wx.StaticText(id=wxID_MAPVARIABLEDIALOGSTATICTEXT4,
00254 label='Number:', name='staticText4', parent=self.MainPanel,
00255 pos=wx.Point(312, 80), size=wx.Size(88, 16), style=0)
00256
00257 self.Number = wx.TextCtrl(id=wxID_MAPVARIABLEDIALOGNUMBER,
00258 name='Number', parent=self.MainPanel, pos=wx.Point(312, 104),
00259 size=wx.Size(112, 24), style=wx.TE_RIGHT, value='0')
00260
00261 self._init_sizers_init_sizers()
00262
00263 def __init__(self, parent):
00264 self._init_ctrls_init_ctrls(parent)
00265 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
00266 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_CENTER)
00267 self.staticText4.Enable(False)
00268 self.Number.Enable(False)
00269
00270 EVT_BUTTON(self, self.ButtonSizerButtonSizer.GetAffirmativeButton().GetId(), self.OnOKOnOK)
00271
00272 def SetIndex(self, index):
00273 self.Index.SetValue("0x%04X"%index)
00274
00275 def OnOK(self, event):
00276 error = []
00277 try:
00278 int(self.Index.GetValue(), 16)
00279 except:
00280 error.append("Index")
00281 if self.radioButton2.GetValue() or self.radioButton3.GetValue():
00282 try:
00283 int(self.Number.GetValue())
00284 except:
00285 error.append("Number")
00286 if len(error) > 0:
00287 text = ""
00288 if len(error) > 1:
00289 suffix = "s"
00290 else:
00291 suffix = ""
00292 for i, item in enumerate(error):
00293 if i == 0:
00294 text += item
00295 elif i == len(error) - 1:
00296 text += " and %s"%item
00297 else:
00298 text += ", %s"%item
00299 message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR)
00300 message.ShowModal()
00301 message.Destroy()
00302 else:
00303 self.EndModal(wxID_OK)
00304
00305 def GetValues(self):
00306 name = self.IndexName.GetValue()
00307 index = int(self.Index.GetValue(), 16)
00308 if self.radioButton1.GetValue():
00309 struct = 1
00310 number = None
00311 elif self.radioButton2.GetValue():
00312 struct = 3
00313 number = int(self.Number.GetValue())
00314 elif self.radioButton3.GetValue():
00315 struct = 7
00316 number = int(self.Number.GetValue())
00317 return index, name, struct, number
00318
00319 def OnRadioButton1Click(self, event):
00320 self.EnableNumberTypingEnableNumberTyping(False)
00321 event.Skip()
00322
00323 def OnRadioButton2Click(self, event):
00324 self.EnableNumberTypingEnableNumberTyping(True)
00325 event.Skip()
00326
00327 def OnRadioButton3Click(self, event):
00328 self.EnableNumberTypingEnableNumberTyping(True)
00329 event.Skip()
00330
00331 def EnableNumberTyping(self, enable):
00332 self.staticText4.Enable(enable)
00333 self.Number.Enable(enable)
00334
00335
00336
00337
00338
00339
00340
00341 [wxID_USERTYPEDIALOG, wxID_USERTYPEDIALOGLENGTH, wxID_USERTYPEDIALOGMAINPANEL,
00342 wxID_USERTYPEDIALOGMAX, wxID_USERTYPEDIALOGMIN,
00343 wxID_USERTYPEDIALOGSTATICBOX1, wxID_USERTYPEDIALOGSTATICTEXT1,
00344 wxID_USERTYPEDIALOGSTATICTEXT2, wxID_USERTYPEDIALOGSTATICTEXT3,
00345 wxID_USERTYPEDIALOGSTATICTEXT4, wxID_USERTYPEDIALOGTYPE,
00346 ] = [wx.NewId() for _init_ctrls in range(11)]
00347
00348 class UserTypeDialog(wx.Dialog):
00349 def _init_coll_flexGridSizer1_Items(self, parent):
00350
00351
00352 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00353
00354 def _init_sizers(self):
00355
00356 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00357
00358 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00359
00360 self.SetSizer(self.flexGridSizer1)
00361
00362 def _init_ctrls(self, prnt):
00363
00364 wx.Dialog.__init__(self, id=wxID_USERTYPEDIALOG, name='UserTypeDialog',
00365 parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 228),
00366 style=wx.DEFAULT_DIALOG_STYLE, title='Add User Type')
00367 self.SetClientSize(wx.Size(444, 228))
00368
00369 self.MainPanel = wx.Panel(id=wxID_USERTYPEDIALOGMAINPANEL,
00370 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00371 size=wx.Size(431, 182), style=wx.TAB_TRAVERSAL)
00372 self.MainPanel.SetAutoLayout(True)
00373
00374 self.staticText1 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT1,
00375 label='Type:', name='staticText1', parent=self.MainPanel,
00376 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
00377
00378 self.Type = wx.Choice(choices=[], id=wxID_USERTYPEDIALOGTYPE,
00379 name='Type', parent=self.MainPanel, pos=wx.Point(24, 48),
00380 size=wx.Size(160, 24), style=0)
00381 self.Type.Bind(wx.EVT_CHOICE, self.OnTypeChoiceOnTypeChoice,
00382 id=wxID_USERTYPEDIALOGTYPE)
00383
00384 self.staticBox1 = wx.StaticBox(id=wxID_USERTYPEDIALOGSTATICBOX1,
00385 label='Values', name='staticBox1', parent=self.MainPanel,
00386 pos=wx.Point(200, 24), size=wx.Size(224, 144), style=0)
00387
00388 self.staticText2 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT2,
00389 label='Minimum:', name='staticText2', parent=self.MainPanel,
00390 pos=wx.Point(216, 48), size=wx.Size(67, 17), style=0)
00391
00392 self.Min = wx.TextCtrl(id=wxID_USERTYPEDIALOGMIN, name='Min',
00393 parent=self.MainPanel, pos=wx.Point(296, 48), size=wx.Size(112,
00394 24), style=wx.TE_RIGHT, value='0')
00395
00396 self.staticText3 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT3,
00397 label='Maximum:', name='staticText3', parent=self.MainPanel,
00398 pos=wx.Point(216, 88), size=wx.Size(71, 17), style=0)
00399
00400 self.Max = wx.TextCtrl(id=wxID_USERTYPEDIALOGMAX, name='Max',
00401 parent=self.MainPanel, pos=wx.Point(296, 88), size=wx.Size(112,
00402 25), style=wx.TE_RIGHT, value='0')
00403
00404 self.staticText4 = wx.StaticText(id=wxID_USERTYPEDIALOGSTATICTEXT4,
00405 label='Length:', name='staticText4', parent=self.MainPanel,
00406 pos=wx.Point(216, 128), size=wx.Size(52, 17), style=0)
00407
00408 self.Length = wx.TextCtrl(id=wxID_USERTYPEDIALOGLENGTH, name='Length',
00409 parent=self.MainPanel, pos=wx.Point(296, 128), size=wx.Size(112,
00410 25), style=wx.TE_RIGHT, value='0')
00411
00412 self._init_sizers_init_sizers()
00413
00414 def __init__(self, parent):
00415 self._init_ctrls_init_ctrls(parent)
00416 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
00417 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_CENTER)
00418 self.TypeDictionaryTypeDictionary = {}
00419
00420 EVT_BUTTON(self, self.ButtonSizerButtonSizer.GetAffirmativeButton().GetId(), self.OnOKOnOK)
00421
00422 def OnOK(self, event):
00423 error = []
00424 good = True
00425 firstmessage = ""
00426 secondmessage = ""
00427 name = self.Type.GetStringSelection()
00428 if name != "":
00429 valuetype = self.TypeDictionaryTypeDictionary[name][1]
00430 if valuetype == 0:
00431 try:
00432 int(self.Min.GetValue(), 16)
00433 except:
00434 error.append("Minimum")
00435 good = False
00436 try:
00437 int(self.Max.GetValue(), 16)
00438 except:
00439 error.append("Maximum")
00440 good = False
00441 elif valuetype == 1:
00442 try:
00443 int(self.Length.GetValue(), 16)
00444 except:
00445 error.append("Length")
00446 good = False
00447 if len(error) > 0:
00448 secondmessage = ". "
00449 for i, item in enumerate(error):
00450 if i == 0:
00451 secondmessage += item
00452 elif i == len(error) - 1:
00453 secondmessage += " and %s"%item
00454 else:
00455 secondmessage += ", %s"%item
00456 secondmessage += " must be integer"
00457 if len(error) > 1:
00458 secondmessage += "s"
00459 else:
00460 firstmessage = ". A type must be selected"
00461 good = False
00462 if not good:
00463 message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR)
00464 message.ShowModal()
00465 message.Destroy()
00466 self.Name.SetFocus()
00467 else:
00468 self.EndModal(wxID_OK)
00469
00470 def SetValues(self, min = None, max = None, length = None):
00471 if min != None:
00472 self.Min.SetValue(str(min))
00473 if max != None:
00474 self.Max.SetValue(str(max))
00475 if length != None:
00476 self.Length.SetValue(str(length))
00477
00478 def SetTypeList(self, typedic, type = None):
00479 self.Type.Clear()
00480 list = []
00481 for index, (name, valuetype) in typedic.iteritems():
00482 self.TypeDictionaryTypeDictionary[name] = (index, valuetype)
00483 list.append((index, name))
00484 list.sort()
00485 for index, name in list:
00486 self.Type.Append(name)
00487 if type != None:
00488 self.Type.SetStringSelection(typedic[type][0])
00489 self.RefreshValuesRefreshValues()
00490
00491 def OnTypeChoice(self, event):
00492 self.RefreshValuesRefreshValues()
00493 event.Skip()
00494
00495 def RefreshValues(self):
00496 name = self.Type.GetStringSelection()
00497 if name != "":
00498 valuetype = self.TypeDictionaryTypeDictionary[name][1]
00499 if valuetype == 0:
00500 self.staticText2.Enable(True)
00501 self.staticText3.Enable(True)
00502 self.staticText4.Enable(False)
00503 self.Min.Enable(True)
00504 self.Max.Enable(True)
00505 self.Length.Enable(False)
00506 elif valuetype == 1:
00507 self.staticText2.Enable(False)
00508 self.staticText3.Enable(False)
00509 self.staticText4.Enable(True)
00510 self.Min.Enable(False)
00511 self.Max.Enable(False)
00512 self.Length.Enable(True)
00513 else:
00514 self.staticText2.Enable(False)
00515 self.staticText3.Enable(False)
00516 self.staticText4.Enable(False)
00517 self.Min.Enable(False)
00518 self.Max.Enable(False)
00519 self.Length.Enable(False)
00520
00521 def GetValues(self):
00522 name = self.Type.GetStringSelection()
00523 type = self.TypeDictionaryTypeDictionary[name][0]
00524 min = int(self.Min.GetValue())
00525 max = int(self.Max.GetValue())
00526 length = int(self.Length.GetValue())
00527 return type, min, max, length
00528
00529
00530
00531
00532
00533
00534
00535
00536 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL,
00537 wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID,
00538 wxID_NODEINFOSDIALOGDESCRIPTION, wxID_NODEINFOSDIALOGSTATICTEXT1,
00539 wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3,
00540 wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE,
00541 ] = [wx.NewId() for _init_ctrls in range(10)]
00542
00543 class NodeInfosDialog(wx.Dialog):
00544 def _init_coll_flexGridSizer1_Items(self, parent):
00545
00546
00547 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00548
00549 def _init_sizers(self):
00550
00551 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00552
00553 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00554
00555 self.SetSizer(self.flexGridSizer1)
00556
00557 def _init_ctrls(self, prnt):
00558
00559 wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG,
00560 name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
00561 size=wx.Size(300, 300), style=wx.DEFAULT_DIALOG_STYLE,
00562 title='Node Infos')
00563 self.SetClientSize(wx.Size(300, 300))
00564
00565 self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL,
00566 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00567 size=wx.Size(280, 264), style=wx.TAB_TRAVERSAL)
00568 self.MainPanel.SetAutoLayout(True)
00569
00570 self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
00571 label='Name:',
00572 name='staticText1', parent=self.MainPanel,
00573 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
00574
00575 self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name',
00576 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(250,
00577 25), style=0, value='')
00578
00579 self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2,
00580 label='Node ID:', name='staticText2', parent=self.MainPanel,
00581 pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
00582
00583 self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID',
00584 parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(250,
00585 25), style=wx.TE_RIGHT, value='')
00586
00587 self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3,
00588 label='Type:', name='staticText3', parent=self.MainPanel,
00589 pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
00590
00591 self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE,
00592 name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
00593 size=wx.Size(250, 25), style=0)
00594
00595 self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4,
00596 label='Description:', name='staticText4', parent=self.MainPanel,
00597 pos=wx.Point(24, 192), size=wx.Size(71, 17), style=0)
00598
00599 self.Description = wx.TextCtrl(id=wxID_NODEINFOSDIALOGDESCRIPTION,
00600 name='Description', parent=self.MainPanel, pos=wx.Point(24, 216),
00601 size=wx.Size(250, 25), style=0, value='')
00602
00603 self._init_sizers_init_sizers()
00604
00605 def __init__(self, parent):
00606 self._init_ctrls_init_ctrls(parent)
00607 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
00608 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_CENTER)
00609 self.Type.Append("master")
00610 self.Type.Append("slave")
00611
00612 EVT_BUTTON(self, self.ButtonSizerButtonSizer.GetAffirmativeButton().GetId(), self.OnOKOnOK)
00613
00614 def OnOK(self, event):
00615 name = self.Name.GetValue()
00616 message = ""
00617 if name != "":
00618 good = not name[0].isdigit()
00619 for item in name.split("_"):
00620 good &= item.isalnum()
00621 if not good:
00622 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
00623 if message != "":
00624 try:
00625 nodeid = int(self.NodeID.GetValue(), 16)
00626 except:
00627 message = "Node ID must be integer!"
00628 if message != "":
00629 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
00630 message.ShowModal()
00631 message.Destroy()
00632 self.Name.SetFocus()
00633 else:
00634 self.EndModal(wxID_OK)
00635
00636 def SetValues(self, name, id, type, description):
00637 self.Name.SetValue(name)
00638 self.NodeID.SetValue("0x%02X"%id)
00639 self.Type.SetStringSelection(type)
00640 self.Description.SetValue(description)
00641
00642 def GetValues(self):
00643 name = self.Name.GetValue()
00644 nodeid = int(self.NodeID.GetValue(), 16)
00645 type = self.Type.GetStringSelection()
00646 description = self.Description.GetValue()
00647 return name, nodeid, type, description
00648
00649
00650
00651
00652
00653
00654
00655
00656 [wxID_CREATENODEDIALOG, wxID_CREATENODEDIALOGEMERGENCY,
00657 wxID_CREATENODEDIALOGGENSYNC, wxID_CREATENODEDIALOGMAINPANEL,
00658 wxID_CREATENODEDIALOGNAME, wxID_CREATENODEDIALOGNMT_HEARTBEAT,
00659 wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE,
00660 wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE,
00661 wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1,
00662 wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3,
00663 wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5,
00664 wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTATICTEXT7,
00665 wxID_CREATENODEDIALOGSTOREEDS, wxID_CREATENODEDIALOGDESCRIPTION,
00666 wxID_CREATENODEDIALOGTYPE,
00667 ] = [wx.NewId() for _init_ctrls in range(21)]
00668
00669 class CreateNodeDialog(wx.Dialog):
00670 def _init_coll_flexGridSizer1_Items(self, parent):
00671
00672
00673 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00674
00675 def _init_sizers(self):
00676
00677 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00678
00679 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00680
00681 self.SetSizer(self.flexGridSizer1)
00682
00683 def _init_ctrls(self, prnt):
00684
00685 wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG,
00686 name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
00687 size=wx.Size(451, 376), style=wx.DEFAULT_DIALOG_STYLE,
00688 title='Create a new Node')
00689 self.SetClientSize(wx.Size(451, 376))
00690
00691 self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL,
00692 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00693 size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL)
00694 self.MainPanel.SetAutoLayout(True)
00695
00696 self.staticText1 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT1,
00697 label='Name:', name='staticText1', parent=self.MainPanel,
00698 pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
00699
00700 self.staticText2 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT2,
00701 label='Node ID:', name='staticText2', parent=self.MainPanel,
00702 pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
00703
00704 self.staticText3 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT3,
00705 label='Type:', name='staticText3', parent=self.MainPanel,
00706 pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
00707
00708 self.Type = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGTYPE,
00709 name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
00710 size=wx.Size(200, 24), style=0)
00711
00712 self.Name = wx.TextCtrl(id=wxID_CREATENODEDIALOGNAME, name='Name',
00713 parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200,
00714 25), style=0, value='')
00715
00716 self.NodeID = wx.TextCtrl(id=wxID_CREATENODEDIALOGNODEID, name='NodeID',
00717 parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200,
00718 25), style=wx.TE_RIGHT, value='')
00719
00720 self.staticText4 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT4,
00721 label='Profile:', name='staticText4', parent=self.MainPanel,
00722 pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0)
00723
00724 self.Profile = wx.Choice(choices=[], id=wxID_CREATENODEDIALOGPROFILE,
00725 name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216),
00726 size=wx.Size(200, 24), style=0)
00727 self.Profile.Bind(wx.EVT_CHOICE, self.OnProfileChoiceOnProfileChoice,
00728 id=wxID_CREATENODEDIALOGPROFILE)
00729
00730 self.staticText5 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT5,
00731 label='Network Management:', name='staticText5',
00732 parent=self.MainPanel, pos=wx.Point(256, 24), size=wx.Size(152,
00733 16), style=0)
00734
00735 self.NMT_None = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NONE,
00736 label='None', name='NMT_None', parent=self.MainPanel,
00737 pos=wx.Point(256, 40), size=wx.Size(114, 24), style=0)
00738 self.NMT_None.SetValue(True)
00739
00740 self.NMT_NodeGuarding = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_NODEGUARDING,
00741 label='Node Guarding', name='NMT_NodeGuarding',
00742 parent=self.MainPanel, pos=wx.Point(256, 64), size=wx.Size(128,
00743 24), style=0)
00744 self.NMT_NodeGuarding.SetValue(False)
00745
00746 self.NMT_Heartbeat = wx.RadioButton(id=wxID_CREATENODEDIALOGNMT_HEARTBEAT,
00747 label='Heartbeat', name='NMT_Heartbeat', parent=self.MainPanel,
00748 pos=wx.Point(256, 88), size=wx.Size(114, 24), style=0)
00749 self.NMT_Heartbeat.SetValue(False)
00750
00751 self.staticText6 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT6,
00752 label='Options:', name='staticText6', parent=self.MainPanel,
00753 pos=wx.Point(256, 128), size=wx.Size(72, 17), style=0)
00754
00755 self.DS302 = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
00756 label='DS-302 Profile', name='DS302', parent=self.MainPanel,
00757 pos=wx.Point(256, 144), size=wx.Size(128, 24), style=0)
00758 self.DS302.SetValue(False)
00759
00760
00761 self.GenSYNC = wx.CheckBox(id=wxID_CREATENODEDIALOGGENSYNC,
00762 label='Generate SYNC', name='GenSYNC', parent=self.MainPanel,
00763 pos=wx.Point(256, 168), size=wx.Size(128, 24), style=0)
00764 self.GenSYNC.SetValue(False)
00765
00766 self.Emergency = wx.CheckBox(id=wxID_CREATENODEDIALOGEMERGENCY,
00767 label='Emergency support', name='Emergency',
00768 parent=self.MainPanel, pos=wx.Point(256, 192), size=wx.Size(152,
00769 24), style=0)
00770 self.Emergency.SetValue(False)
00771 self.Emergency.Enable(False)
00772
00773 self.SaveConfig = wx.CheckBox(id=wxID_CREATENODEDIALOGSAVECONFIG,
00774 label='Save Configuration', name='SaveConfig',
00775 parent=self.MainPanel, pos=wx.Point(256, 216), size=wx.Size(152,
00776 24), style=0)
00777 self.SaveConfig.SetValue(False)
00778 self.SaveConfig.Enable(False)
00779
00780
00781
00782
00783
00784
00785 self.staticText7 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT7,
00786 label='Description:', name='staticText7', parent=self.MainPanel,
00787 pos=wx.Point(24, 248), size=wx.Size(71, 17), style=0)
00788
00789 self.Description = wx.TextCtrl(id=wxID_CREATENODEDIALOGDESCRIPTION,
00790 name='Description', parent=self.MainPanel, pos=wx.Point(24, 272),
00791 size=wx.Size(400, 25), style=0, value='')
00792
00793 self._init_sizers_init_sizers()
00794
00795 def __init__(self, parent, cwd):
00796 self._init_ctrls_init_ctrls(parent)
00797 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
00798 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_CENTER)
00799 self.NodeID.SetValue("0x00")
00800 self.Type.Append("master")
00801 self.Type.Append("slave")
00802 self.Type.SetStringSelection("slave")
00803 self.Description.SetValue("")
00804 self.ListProfileListProfile = {"None" : ""}
00805 self.Profile.Append("None")
00806 self.DirectoryDirectory = os.path.join(cwd, "config")
00807 listfiles = os.listdir(self.DirectoryDirectory)
00808 listfiles.sort()
00809 for item in listfiles:
00810 name, extend = os.path.splitext(item)
00811 if os.path.isfile(os.path.join(self.DirectoryDirectory, item)) and extend == ".prf" and name != "DS-302":
00812 self.ListProfileListProfile[name] = os.path.join(self.DirectoryDirectory, item)
00813 self.Profile.Append(name)
00814 self.Profile.Append("Other")
00815 self.Profile.SetStringSelection("None")
00816 self.Name.SetFocus()
00817
00818 EVT_BUTTON(self, self.ButtonSizerButtonSizer.GetAffirmativeButton().GetId(), self.OnOKOnOK)
00819
00820 def OnOK(self, event):
00821 name = self.Name.GetValue()
00822 message = ""
00823 if name != "":
00824 good = not name[0].isdigit()
00825 for item in name.split("_"):
00826 good &= item.isalnum()
00827 if not good:
00828 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
00829 if message != "":
00830 try:
00831 nodeid = int(self.NodeID.GetValue(), 16)
00832 except:
00833 message = "Node ID must be an integer!"
00834 if message != "":
00835 message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
00836 message.ShowModal()
00837 message.Destroy()
00838 self.Name.SetFocus()
00839 else:
00840 self.EndModal(wxID_OK)
00841
00842 def GetValues(self):
00843 name = self.Name.GetValue()
00844 nodeid = 0
00845 if self.NodeID.GetValue() != "":
00846 nodeid = int(self.NodeID.GetValue(), 16)
00847 type = self.Type.GetStringSelection()
00848 description = self.Description.GetValue()
00849 return name, nodeid, type, description
00850
00851 def GetProfile(self):
00852 name = self.Profile.GetStringSelection()
00853 return name, self.ListProfileListProfile[name]
00854
00855 def GetNMTManagement(self):
00856 if self.NMT_None.GetValue():
00857 return "None"
00858 elif self.NMT_NodeGuarding.GetValue():
00859 return "NodeGuarding"
00860 elif self.NMT_Heartbeat.GetValue():
00861 return "Heartbeat"
00862 return None
00863
00864 def GetOptions(self):
00865 options = []
00866 if self.DS302.GetValue():
00867 options.append("DS302")
00868 if self.GenSYNC.GetValue():
00869 options.append("GenSYNC")
00870 if self.Emergency.GetValue():
00871 options.append("Emergency")
00872 if self.SaveConfig.GetValue():
00873 options.append("SaveConfig")
00874
00875
00876 return options
00877
00878 def OnProfileChoice(self, event):
00879 if self.Profile.GetStringSelection() == "Other":
00880 dialog = wxFileDialog(self, "Choose a file", self.DirectoryDirectory, "", "OD Profile files (*.prf)|*.prf|All files|*.*", wxOPEN|wxCHANGE_DIR)
00881 dialog.ShowModal()
00882 filepath = dialog.GetPath()
00883 dialog.Destroy()
00884 if os.path.isfile(filepath):
00885 name = os.path.splitext(os.path.basename(filepath))[0]
00886 self.ListProfileListProfile[name] = filepath
00887 length = self.Profile.GetCount()
00888 self.Profile.Insert(name, length - 2)
00889 self.Profile.SetStringSelection(name)
00890 else:
00891 self.Profile.SetStringSelection("None")
00892 event.Skip()
00893
00894
00895
00896
00897
00898
00899 [wxID_ADDSLAVEDIALOG, wxID_ADDSLAVEDIALOGMAINPANEL, wxID_ADDSLAVEDIALOGSLAVENAME,
00900 wxID_ADDSLAVEDIALOGSLAVENODEID, wxID_ADDSLAVEDIALOGEDSFILE,
00901 wxID_ADDSLAVEDIALOGIMPORTEDS, wxID_ADDSLAVEDIALOGSTATICTEXT1,
00902 wxID_ADDSLAVEDIALOGSTATICTEXT2, wxID_ADDSLAVEDIALOGSTATICTEXT3,
00903 ] = [wx.NewId() for _init_ctrls in range(9)]
00904
00905 class AddSlaveDialog(wx.Dialog):
00906 def _init_coll_flexGridSizer1_Items(self, parent):
00907
00908
00909 parent.AddWindow(self.MainPanel, 0, border=0, flag=0)
00910
00911 def _init_sizers(self):
00912
00913 self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
00914
00915 self._init_coll_flexGridSizer1_Items_init_coll_flexGridSizer1_Items(self.flexGridSizer1)
00916
00917 self.SetSizer(self.flexGridSizer1)
00918
00919 def _init_ctrls(self, prnt):
00920
00921 wx.Dialog.__init__(self, id=wxID_ADDSLAVEDIALOG,
00922 name='AddSlaveDialog', parent=prnt, pos=wx.Point(376, 223),
00923 size=wx.Size(300, 250), style=wx.DEFAULT_DIALOG_STYLE,
00924 title='Add a slave to nodelist')
00925 self.SetClientSize(wx.Size(300, 250))
00926
00927 self.MainPanel = wx.Panel(id=wxID_ADDSLAVEDIALOGMAINPANEL,
00928 name='MainPanel', parent=self, pos=wx.Point(0, 0),
00929 size=wx.Size(350, 250), style=wx.TAB_TRAVERSAL)
00930 self.MainPanel.SetAutoLayout(True)
00931
00932 self.staticText1 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT1,
00933 label='Slave Name:', name='staticText1', parent=self.MainPanel,
00934 pos=wx.Point(24, 24), size=wx.Size(150, 17), style=0)
00935
00936 self.SlaveName = wx.TextCtrl(id=wxID_ADDSLAVEDIALOGSLAVENAME,
00937 name='SlaveName', parent=self.MainPanel, pos=wx.Point(24, 48),
00938 size=wx.Size(250, 24), style=0)
00939
00940 self.staticText2 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT2,
00941 label='Slave Node ID:', name='staticText2', parent=self.MainPanel,
00942 pos=wx.Point(24, 80), size=wx.Size(150, 17), style=0)
00943
00944 self.SlaveNodeID = wx.TextCtrl(id=wxID_ADDSLAVEDIALOGSLAVENODEID,
00945 name='SlaveName', parent=self.MainPanel, pos=wx.Point(24, 104),
00946 size=wx.Size(250, 24), style=wxALIGN_RIGHT)
00947
00948 self.staticText3 = wx.StaticText(id=wxID_ADDSLAVEDIALOGSTATICTEXT3,
00949 label='EDS File:', name='staticText3', parent=self.MainPanel,
00950 pos=wx.Point(24, 136), size=wx.Size(155, 17), style=0)
00951
00952 self.EDSFile = wx.Choice(id=wxID_ADDSLAVEDIALOGEDSFILE,
00953 name='EDSFile', parent=self.MainPanel, pos=wx.Point(24, 160),
00954 size=wx.Size(145, 24), style=0)
00955
00956 self.ImportEDS = wxButton(id=wxID_ADDSLAVEDIALOGIMPORTEDS, label='Import EDS',
00957 name='ImportEDS', parent=self.MainPanel, pos=wx.Point(174, 160),
00958 size=wx.Size(100, 32), style=0)
00959 self.ImportEDS.Bind(wx.EVT_BUTTON, self.OnImportEDSButtonOnImportEDSButton,
00960 id=wxID_ADDSLAVEDIALOGIMPORTEDS)
00961
00962 self._init_sizers_init_sizers()
00963
00964 def __init__(self, parent):
00965 self._init_ctrls_init_ctrls(parent)
00966 self.ButtonSizerButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
00967 self.flexGridSizer1.Add(self.ButtonSizerButtonSizer, 1, wxALIGN_RIGHT)
00968
00969 self.SlaveNodeID.SetValue("0x00")
00970
00971 EVT_BUTTON(self, self.ButtonSizerButtonSizer.GetAffirmativeButton().GetId(), self.OnOKOnOK)
00972
00973 def OnOK(self, event):
00974 error = []
00975 if self.SlaveName.GetValue() == "":
00976 error.append("Slave Name")
00977 if self.SlaveNodeID.GetValue() == "":
00978 error.append("Slave Node ID")
00979 if self.EDSFile.GetStringSelection() == "":
00980 error.append("EDS File")
00981 if len(error) > 0:
00982 text = ""
00983 for i, item in enumerate(error):
00984 if i == 0:
00985 text += item
00986 elif i == len(error) - 1:
00987 text += " and %s"%item
00988 else:
00989 text += ", %s"%item
00990 message = wxMessageDialog(self, "Form isn't complete. %s must be filled!"%text, "Error", wxOK|wxICON_ERROR)
00991 message.ShowModal()
00992 message.Destroy()
00993 else:
00994 try:
00995 nodeid = self.SlaveNodeID.GetValue()
00996 if nodeid.find("x") != -1:
00997 nodeid = int(nodeid, 16)
00998 else:
00999 nodeid = int(nodeid)
01000 except:
01001 message = wxMessageDialog(self, "Slave Node ID must be a value in decimal or hexadecimal!", "Error", wxOK|wxICON_ERROR)
01002 message.ShowModal()
01003 message.Destroy()
01004 return
01005 if not 0 <= nodeid <= 127:
01006 message = wxMessageDialog(self, "Slave Node ID must be between 0 and 127!", "Error", wxOK|wxICON_ERROR)
01007 message.ShowModal()
01008 message.Destroy()
01009 elif nodeid == 0 or nodeid in self.NodeListNodeList.SlaveNodes.keys():
01010 message = wxMessageDialog(self, "A Node with this ID already exist in the network!", "Error", wxOK|wxICON_ERROR)
01011 message.ShowModal()
01012 message.Destroy()
01013 else:
01014 self.EndModal(wxID_OK)
01015
01016 def OnImportEDSButton(self, event):
01017 dialog = wxFileDialog(self, "Choose an EDS file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR)
01018 if dialog.ShowModal() == wxID_OK:
01019 filepath = dialog.GetPath()
01020 if os.path.isfile(filepath):
01021 result = self.NodeListNodeList.ImportEDSFile(filepath)
01022 if result:
01023 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
01024 message.ShowModal()
01025 message.Destroy()
01026 dialog.Destroy()
01027 self.RefreshEDSFileRefreshEDSFile()
01028 event.Skip()
01029
01030 def RefreshEDSFile(self):
01031 selection = self.EDSFile.GetStringSelection()
01032 self.EDSFile.Clear()
01033 for option in self.NodeListNodeList.EDSNodes.keys():
01034 self.EDSFile.Append(option)
01035 if self.EDSFile.FindString(selection) != wxNOT_FOUND:
01036 self.EDSFile.SetStringSelection(selection)
01037
01038 def SetNodeList(self, nodelist):
01039 self.NodeListNodeList = nodelist
01040 self.RefreshEDSFileRefreshEDSFile()
01041
01042 def GetValues(self):
01043 values = {}
01044 values["slaveName"] = self.SlaveName.GetValue()
01045 nodeid = self.SlaveNodeID.GetValue()
01046 if nodeid.find("x") != -1:
01047 values["slaveNodeID"] = int(nodeid, 16)
01048 else:
01049 values["slaveNodeID"] = int(nodeid)
01050 values["edsFile"] = self.EDSFile.GetStringSelection()
01051 return values