objdictgen/objdictedit.py
changeset 182 988f2b302aa6
parent 176 5d57fe1e3a5b
child 205 dac0f9b4e3f8
equal deleted inserted replaced
181:44d812a41d49 182:988f2b302aa6
   750             index = self.ListIndex[selected]
   750             index = self.ListIndex[selected]
   751             if self.Manager.IsCurrentEntry(index):
   751             if self.Manager.IsCurrentEntry(index):
   752                 dialog = wxTextEntryDialog(self, "Number of subindexes to add:",
   752                 dialog = wxTextEntryDialog(self, "Number of subindexes to add:",
   753                              "Add subindexes", "1", wxOK|wxCANCEL)
   753                              "Add subindexes", "1", wxOK|wxCANCEL)
   754                 if dialog.ShowModal() == wxID_OK:
   754                 if dialog.ShowModal() == wxID_OK:
   755                     number = eval(dialog.GetValue())
   755                     try:
   756                     if type(number) == IntType:
   756                         number = int(dialog.GetValue())
   757                         self.Manager.AddSubentriesToCurrent(index, number)
   757                         self.Manager.AddSubentriesToCurrent(index, number)
   758                         self.Parent.RefreshBufferState()
   758                         self.Parent.RefreshBufferState()
   759                         self.RefreshIndexList()
   759                         self.RefreshIndexList()
   760                     else:
   760                     except:
   761                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
   761                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
   762                         message.ShowModal()
   762                         message.ShowModal()
   763                         message.Destroy()
   763                         message.Destroy()
   764                 dialog.Destroy()
   764                 dialog.Destroy()
   765         event.Skip()
   765         event.Skip()
   770             index = self.ListIndex[selected]
   770             index = self.ListIndex[selected]
   771             if self.Manager.IsCurrentEntry(index):
   771             if self.Manager.IsCurrentEntry(index):
   772                 dialog = wxTextEntryDialog(self, "Number of subindexes to delete:",
   772                 dialog = wxTextEntryDialog(self, "Number of subindexes to delete:",
   773                              "Delete subindexes", "1", wxOK|wxCANCEL)
   773                              "Delete subindexes", "1", wxOK|wxCANCEL)
   774                 if dialog.ShowModal() == wxID_OK:
   774                 if dialog.ShowModal() == wxID_OK:
   775                     number = eval(dialog.GetValue())
   775                     try:
   776                     if type(number) == IntType:
   776                         number = int(dialog.GetValue())
   777                         self.Manager.RemoveSubentriesFromCurrent(index, number)
   777                         self.Manager.RemoveSubentriesFromCurrent(index, number)
   778                         self.Parent.RefreshBufferState()
   778                         self.Parent.RefreshBufferState()
   779                         self.RefreshIndexList()
   779                         self.RefreshIndexList()
   780                     else:
   780                     except:
   781                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
   781                         message = wxMessageDialog(self, "An integer is required!", "ERROR", wxOK|wxICON_ERROR)
   782                         message.ShowModal()
   782                         message.ShowModal()
   783                         message.Destroy()
   783                         message.Destroy()
   784                 dialog.Destroy()
   784                 dialog.Destroy()
   785         event.Skip()
   785         event.Skip()
   795 
   795 
   796 [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, 
   796 [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, 
   797  wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, 
   797  wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, 
   798  wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, 
   798  wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, 
   799  wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8,
   799  wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8,
   800 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(8)]
   800  wxID_OBJDICTEDITFILEMENUITEMS9,
       
   801 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)]
   801 
   802 
   802 [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, 
   803 [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, 
   803  wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, 
   804  wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, 
   804  wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, 
   805  wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, 
   805  wxID_OBJDICTEDITEDITMENUITEMS8, 
   806  wxID_OBJDICTEDITEDITMENUITEMS8, 
   883         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2,
   884         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2,
   884               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
   885               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
   885         parent.AppendSeparator()
   886         parent.AppendSeparator()
   886         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7,
   887         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7,
   887               kind=wx.ITEM_NORMAL, text='Import EDS file')
   888               kind=wx.ITEM_NORMAL, text='Import EDS file')
       
   889         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS9,
       
   890               kind=wx.ITEM_NORMAL, text='Export to EDS file')
   888         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8,
   891         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8,
   889               kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B')
   892               kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B')
   890         parent.AppendSeparator()
   893         parent.AppendSeparator()
   891         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4,
   894         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4,
   892               kind=wx.ITEM_NORMAL, text='Exit')
   895               kind=wx.ITEM_NORMAL, text='Exit')
   900               id=wxID_OBJDICTEDITFILEMENUITEMS4)
   903               id=wxID_OBJDICTEDITFILEMENUITEMS4)
   901         self.Bind(wx.EVT_MENU, self.OnNewMenu,
   904         self.Bind(wx.EVT_MENU, self.OnNewMenu,
   902               id=wxID_OBJDICTEDITFILEMENUITEMS5)
   905               id=wxID_OBJDICTEDITFILEMENUITEMS5)
   903         self.Bind(wx.EVT_MENU, self.OnSaveAsMenu,
   906         self.Bind(wx.EVT_MENU, self.OnSaveAsMenu,
   904               id=wxID_OBJDICTEDITFILEMENUITEMS6)
   907               id=wxID_OBJDICTEDITFILEMENUITEMS6)
   905         self.Bind(wx.EVT_MENU, self.OnImportMenu,
   908         self.Bind(wx.EVT_MENU, self.OnImportEDSMenu,
   906               id=wxID_OBJDICTEDITFILEMENUITEMS7)
   909               id=wxID_OBJDICTEDITFILEMENUITEMS7)
   907         self.Bind(wx.EVT_MENU, self.OnExportMenu,
   910         self.Bind(wx.EVT_MENU, self.OnExportCMenu,
   908               id=wxID_OBJDICTEDITFILEMENUITEMS8)
   911               id=wxID_OBJDICTEDITFILEMENUITEMS8)
       
   912         self.Bind(wx.EVT_MENU, self.OnExportEDSMenu,
       
   913               id=wxID_OBJDICTEDITFILEMENUITEMS9)
   909 
   914 
   910     def _init_coll_AddMenu_Items(self, parent):
   915     def _init_coll_AddMenu_Items(self, parent):
   911         # generated method, don't edit
   916         # generated method, don't edit
   912 
   917 
   913         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0,
   918         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0,
   987 
   992 
   988     def __init__(self, parent):
   993     def __init__(self, parent):
   989         self._init_ctrls(parent)
   994         self._init_ctrls(parent)
   990         self.HtmlFrameOpened = []
   995         self.HtmlFrameOpened = []
   991         
   996         
   992         self.Manager = NodeManager()
   997         self.Manager = NodeManager(ScriptDirectory)
   993         for filepath in filesOpen:
   998         for filepath in filesOpen:
   994             self.Manager.OpenFileInCurrent(filepath)
   999             self.Manager.OpenFileInCurrent(filepath)
   995             new_editingpanel = EditingPanel(self, self.Manager)
  1000             new_editingpanel = EditingPanel(self, self.Manager)
   996             self.FileOpened.AddPage(new_editingpanel, "")
  1001             self.FileOpened.AddPage(new_editingpanel, "")
   997             self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1002             self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1166         else:
  1171         else:
  1167             for i in xrange(3):
  1172             for i in xrange(3):
  1168                 self.HelpBar.SetStatusText("", i)
  1173                 self.HelpBar.SetStatusText("", i)
  1169 
  1174 
  1170     def RefreshMainMenu(self):
  1175     def RefreshMainMenu(self):
  1171         if self.FileOpened.GetPageCount() > 0:
  1176         if self.FileMenu:
  1172             self.menuBar1.EnableTop(1, True)
  1177             if self.FileOpened.GetPageCount() > 0:
  1173             self.menuBar1.EnableTop(2, True)
  1178                 self.menuBar1.EnableTop(1, True)
  1174             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True)
  1179                 self.menuBar1.EnableTop(2, True)
  1175             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True)
  1180                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True)
  1176             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True)
  1181                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True)
  1177             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True)
  1182                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True)
  1178         else:
  1183                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True)
  1179             self.menuBar1.EnableTop(1, False)      
  1184                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, True)
  1180             self.menuBar1.EnableTop(2, False)
  1185             else:
  1181             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False)
  1186                 self.menuBar1.EnableTop(1, False)      
  1182             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False)
  1187                 self.menuBar1.EnableTop(2, False)
  1183             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False)
  1188                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False)
  1184             self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False)
  1189                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False)
       
  1190                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False)
       
  1191                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False)
       
  1192                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, False)
  1185 
  1193 
  1186     def RefreshEditMenu(self):
  1194     def RefreshEditMenu(self):
  1187         if self.FileOpened.GetPageCount() > 0:
  1195         if self.FileMenu:
  1188             undo, redo = self.Manager.GetCurrentBufferState()
  1196             if self.FileOpened.GetPageCount() > 0:
  1189             self.EditMenu.FindItemByPosition(2).Enable(undo)
  1197                 undo, redo = self.Manager.GetCurrentBufferState()
  1190             self.EditMenu.FindItemByPosition(3).Enable(redo)
  1198                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, undo)
  1191         else:
  1199                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, redo)
  1192             self.EditMenu.FindItemByPosition(2).Enable(False)
  1200             else:
  1193             self.EditMenu.FindItemByPosition(3).Enable(False)
  1201                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, False)
       
  1202                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, False)
  1194 
  1203 
  1195     def RefreshProfileMenu(self):
  1204     def RefreshProfileMenu(self):
  1196         profile = self.Manager.GetCurrentProfileName()
  1205         if self.EditMenu:
  1197         edititem = self.EditMenu.FindItemByPosition(8)
  1206             profile = self.Manager.GetCurrentProfileName()
  1198         length = self.AddMenu.GetMenuItemCount()
  1207             edititem = self.EditMenu.FindItemById(wxID_OBJDICTEDITEDITMENUITEMS7)
  1199         for i in xrange(length-6):
  1208             if edititem:
  1200             additem = self.AddMenu.FindItemByPosition(6)
  1209                 length = self.AddMenu.GetMenuItemCount()
  1201             self.AddMenu.Delete(additem.GetId())
  1210                 for i in xrange(length-6):
  1202         if profile not in ("None", "DS-301"):
  1211                     additem = self.AddMenu.FindItemByPosition(6)
  1203             edititem.SetText("%s Profile"%profile)
  1212                     self.AddMenu.Delete(additem.GetId())
  1204             edititem.Enable(True)
  1213                 if profile not in ("None", "DS-301"):
  1205             self.AddMenu.AppendSeparator()
  1214                     edititem.SetText("%s Profile"%profile)
  1206             for text, indexes in self.Manager.GetCurrentSpecificMenu():
  1215                     edititem.Enable(True)
  1207                 new_id = wx.NewId()
  1216                     self.AddMenu.AppendSeparator()
  1208                 self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
  1217                     for text, indexes in self.Manager.GetCurrentSpecificMenu():
  1209                 self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
  1218                         new_id = wx.NewId()
  1210         else:
  1219                         self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text)
  1211             edititem.SetText("Other Profile")
  1220                         self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id)
  1212             edititem.Enable(False)
  1221                 else:
       
  1222                     edititem.SetText("Other Profile")
       
  1223                     edititem.Enable(False)
  1213         
  1224         
  1214 
  1225 
  1215 #-------------------------------------------------------------------------------
  1226 #-------------------------------------------------------------------------------
  1216 #                            Buffer Functions
  1227 #                            Buffer Functions
  1217 #-------------------------------------------------------------------------------
  1228 #-------------------------------------------------------------------------------
  1242 
  1253 
  1243     def OnNewMenu(self, event):
  1254     def OnNewMenu(self, event):
  1244         self.FilePath = ""
  1255         self.FilePath = ""
  1245         dialog = CreateNodeDialog(self)
  1256         dialog = CreateNodeDialog(self)
  1246         if dialog.ShowModal() == wxID_OK:
  1257         if dialog.ShowModal() == wxID_OK:
  1247             name, id, type = dialog.GetValues()
  1258             name, id, type, description = dialog.GetValues()
  1248             profile, filepath = dialog.GetProfile()
  1259             profile, filepath = dialog.GetProfile()
  1249             NMT = dialog.GetNMTManagement()
  1260             NMT = dialog.GetNMTManagement()
  1250             options = dialog.GetOptions()
  1261             options = dialog.GetOptions()
  1251             result = self.Manager.CreateNewNode(name, id, type, profile, filepath, NMT, options)
  1262             result = self.Manager.CreateNewNode(name, id, type, description, profile, filepath, NMT, options)
  1252             if not IsOfType(result, StringType):
  1263             if not IsOfType(result, StringType):
  1253                 new_editingpanel = EditingPanel(self, self.Manager)
  1264                 new_editingpanel = EditingPanel(self, self.Manager)
  1254                 self.FileOpened.AddPage(new_editingpanel, "")
  1265                 self.FileOpened.AddPage(new_editingpanel, "")
  1255                 self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1266                 self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1256                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
  1267                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
  1362 
  1373 
  1363 #-------------------------------------------------------------------------------
  1374 #-------------------------------------------------------------------------------
  1364 #                         Import and Export Functions
  1375 #                         Import and Export Functions
  1365 #-------------------------------------------------------------------------------
  1376 #-------------------------------------------------------------------------------
  1366 
  1377 
  1367     def OnImportMenu(self, event):
  1378     def OnImportEDSMenu(self, event):
  1368         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "",  "XML OD files (*.xml)|*.xml|All files|*.*", wxOPEN|wxCHANGE_DIR)
  1379         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "",  "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR)
  1369         if dialog.ShowModal() == wxID_OK:
  1380         if dialog.ShowModal() == wxID_OK:
  1370             filepath = dialog.GetPath()
  1381             filepath = dialog.GetPath()
  1371             if os.path.isfile(filepath):
  1382             if os.path.isfile(filepath):
  1372                 result = self.Manager.ImportCurrentFromFile(filepath)
  1383                 result = self.Manager.ImportCurrentFromEDSFile(filepath)
  1373                 if result:
  1384                 if not result:
  1374                     if self.FileOpened.GetPageCount() == 0:
  1385                     if self.FileOpened.GetPageCount() == 0:
  1375                         new_editingpanel = EditingPanel(self, self.Manager)
  1386                         new_editingpanel = EditingPanel(self, self.Manager)
  1376                         self.FileOpened.AddPage(new_editingpanel, "")
  1387                         self.FileOpened.AddPage(new_editingpanel, "")
  1377                         self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1388                         self.FileOpened.SetSelection(self.Manager.GetCurrentNodeIndex())
  1378                     self.RefreshBufferState()
  1389                     self.RefreshBufferState()
  1380                     self.RefreshProfileMenu()
  1391                     self.RefreshProfileMenu()
  1381                     self.RefreshMainMenu()
  1392                     self.RefreshMainMenu()
  1382                     message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION)
  1393                     message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION)
  1383                     message.ShowModal()
  1394                     message.ShowModal()
  1384                     message.Destroy()
  1395                     message.Destroy()
       
  1396                 else:
       
  1397                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
       
  1398                     message.ShowModal()
       
  1399                     message.Destroy()
       
  1400             else:
       
  1401                 message = wxMessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wxOK|wxICON_ERROR)
       
  1402                 message.ShowModal()
       
  1403                 message.Destroy()
  1385         dialog.Destroy()
  1404         dialog.Destroy()
  1386         event.Skip()
  1405         event.Skip()
  1387 
  1406 
  1388     def OnExportMenu(self, event):
  1407 
       
  1408     def OnExportEDSMenu(self, event):
       
  1409         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "EDS files (*.eds)|*.eds|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
       
  1410         if dialog.ShowModal() == wxID_OK:
       
  1411             filepath = dialog.GetPath()
       
  1412             if os.path.isdir(os.path.dirname(filepath)):
       
  1413                 path, extend = os.path.splitext(filepath)
       
  1414                 if extend in ("", "."):
       
  1415                     filepath = path + ".eds"
       
  1416                 result = self.Manager.ExportCurrentToEDSFile(filepath)
       
  1417                 if not result:
       
  1418                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
       
  1419                     message.ShowModal()
       
  1420                     message.Destroy()
       
  1421                 else:
       
  1422                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
       
  1423                     message.ShowModal()
       
  1424                     message.Destroy()
       
  1425             else:
       
  1426                 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
       
  1427                 message.ShowModal()
       
  1428                 message.Destroy()
       
  1429         dialog.Destroy()
       
  1430         event.Skip()
       
  1431 
       
  1432     def OnExportCMenu(self, event):
  1389         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
  1433         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
  1390         if dialog.ShowModal() == wxID_OK:
  1434         if dialog.ShowModal() == wxID_OK:
  1391             filepath = dialog.GetPath()
  1435             filepath = dialog.GetPath()
  1392             if os.path.isdir(os.path.dirname(filepath)):
  1436             if os.path.isdir(os.path.dirname(filepath)):
  1393                 path, extend = os.path.splitext(filepath)
  1437                 path, extend = os.path.splitext(filepath)
  1394                 if extend in ("", "."):
  1438                 if extend in ("", "."):
  1395                     filepath = path + ".c"
  1439                     filepath = path + ".c"
  1396                 result = self.Manager.ExportCurrentToFile(filepath)
  1440                 result = self.Manager.ExportCurrentToCFile(filepath)
  1397                 if result:
  1441                 if not result:
  1398                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
  1442                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
  1399                     message.ShowModal()
  1443                     message.ShowModal()
  1400                     message.Destroy()
  1444                     message.Destroy()
       
  1445                 else:
       
  1446                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
       
  1447                     message.ShowModal()
       
  1448                     message.Destroy()
  1401             else:
  1449             else:
  1402                 message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
  1450                 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
  1403                 message.ShowModal()
  1451                 message.ShowModal()
  1404                 message.Destroy()
  1452                 message.Destroy()
  1405         dialog.Destroy()
  1453         dialog.Destroy()
  1406         event.Skip()
  1454         event.Skip()
  1407 
  1455 
  1460 #                         Edit Node informations function
  1508 #                         Edit Node informations function
  1461 #-------------------------------------------------------------------------------
  1509 #-------------------------------------------------------------------------------
  1462 
  1510 
  1463     def OnNodeInfosMenu(self, event):
  1511     def OnNodeInfosMenu(self, event):
  1464         dialog = NodeInfosDialog(self)
  1512         dialog = NodeInfosDialog(self)
  1465         name,id,type = self.Manager.GetCurrentNodeInfos()
  1513         name, id, type, description = self.Manager.GetCurrentNodeInfos()
  1466         profile = self.Manager.GetCurrentProfileName()
  1514         dialog.SetValues(name, id, type, description)
  1467         dialog.SetProfiles([profile])
       
  1468         dialog.SetValues(name, id, type, profile)
       
  1469         if dialog.ShowModal() == wxID_OK:
  1515         if dialog.ShowModal() == wxID_OK:
  1470             name,id,type,profile = dialog.GetValues()
  1516             name, id, type, description = dialog.GetValues()
  1471             self.Manager.SetCurrentNodeInfos(name, id, type)
  1517             self.Manager.SetCurrentNodeInfos(name, id, type, description)
  1472             self.RefreshBufferState()
  1518             self.RefreshBufferState()
  1473             self.RefreshProfileMenu()
  1519             self.RefreshProfileMenu()
  1474         event.Skip()
  1520         event.Skip()
  1475 
  1521 
  1476 
  1522 
  1753         self._init_ctrls(parent)
  1799         self._init_ctrls(parent)
  1754         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  1800         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  1755         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  1801         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  1756         self.staticText4.Enable(False)
  1802         self.staticText4.Enable(False)
  1757         self.Number.Enable(False)
  1803         self.Number.Enable(False)
       
  1804         
       
  1805         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
  1758 
  1806 
  1759     def SetIndex(self, index):
  1807     def SetIndex(self, index):
  1760         self.Index.SetValue("0x%04X"%index)
  1808         self.Index.SetValue("0x%04X"%index)
  1761 
  1809 
       
  1810     def OnOK(self, event):
       
  1811         error = []
       
  1812         try:
       
  1813             int(self.Index.GetValue(), 16)
       
  1814         except:
       
  1815             error.append("Index")
       
  1816         if self.radioButton2.GetValue() or self.radioButton3.GetValue():
       
  1817             try:
       
  1818                 int(self.Number.GetValue())
       
  1819             except:
       
  1820                 error.append("Number")
       
  1821         if len(error) > 0:
       
  1822             text = ""
       
  1823             if len(error) > 1:
       
  1824                 suffix = "s"
       
  1825             else:
       
  1826                 suffix = ""
       
  1827             for i, item in enumerate(error):
       
  1828                 if i == 0:
       
  1829                     text += item
       
  1830                 elif i == len(error) - 1:
       
  1831                     text += " and %s"%item
       
  1832                 else:
       
  1833                     text += ", %s"%item
       
  1834             message = wxMessageDialog(self, "Form isn't valid. %s must be integer%s!"%(text,suffix), "Error", wxOK|wxICON_ERROR)
       
  1835             message.ShowModal()
       
  1836             message.Destroy()
       
  1837         else:
       
  1838             self.EndModal(wxID_OK)
       
  1839 
  1762     def GetValues(self):
  1840     def GetValues(self):
       
  1841         name = self.IndexName.GetValue()
       
  1842         index = int(self.Index.GetValue(), 16)
  1763         if self.radioButton1.GetValue():
  1843         if self.radioButton1.GetValue():
  1764             struct = 1
  1844             struct = 1
       
  1845             number = None
  1765         elif self.radioButton2.GetValue():
  1846         elif self.radioButton2.GetValue():
  1766             struct = 3
  1847             struct = 3
       
  1848             number = int(self.Number.GetValue())
  1767         elif self.radioButton3.GetValue():
  1849         elif self.radioButton3.GetValue():
  1768             struct = 7
  1850             struct = 7
  1769         name = self.IndexName.GetValue()
  1851             number = int(self.Number.GetValue())
  1770         index = eval(self.Index.GetValue())
       
  1771         number = eval(self.Number.GetValue())
       
  1772         return index, name, struct, number
  1852         return index, name, struct, number
  1773 
  1853 
  1774     def OnRadioButton1Click(self, event):
  1854     def OnRadioButton1Click(self, event):
  1775         self.EnableNumberTyping(False)
  1855         self.EnableNumberTyping(False)
  1776         event.Skip()
  1856         event.Skip()
  1869     def __init__(self, parent):
  1949     def __init__(self, parent):
  1870         self._init_ctrls(parent)
  1950         self._init_ctrls(parent)
  1871         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  1951         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  1872         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  1952         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  1873         self.TypeDictionary = {}
  1953         self.TypeDictionary = {}
  1874         
  1954 
       
  1955         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
       
  1956 
       
  1957     def OnOK(self, event):
       
  1958         error = []
       
  1959         good = True
       
  1960         firstmessage = ""
       
  1961         secondmessage = ""
       
  1962         name = self.Type.GetStringSelection()
       
  1963         if name != "":
       
  1964             valuetype = self.TypeDictionary[name][1]
       
  1965             if valuetype == 0:
       
  1966                 try:
       
  1967                     int(self.Min.GetValue(), 16)
       
  1968                 except:
       
  1969                     error.append("Minimum")
       
  1970                     good = False
       
  1971                 try:
       
  1972                     int(self.Max.GetValue(), 16)
       
  1973                 except:
       
  1974                     error.append("Maximum")
       
  1975                     good = False
       
  1976             elif valuetype == 1:
       
  1977                 try:
       
  1978                     int(self.Length.GetValue(), 16)
       
  1979                 except:
       
  1980                     error.append("Length")
       
  1981                     good = False
       
  1982             if len(error) > 0:
       
  1983                 secondmessage = ". "
       
  1984                 for i, item in enumerate(error):
       
  1985                     if i == 0:
       
  1986                         secondmessage += item
       
  1987                     elif i == len(error) - 1:
       
  1988                         secondmessage += " and %s"%item
       
  1989                     else:
       
  1990                         secondmessage += ", %s"%item
       
  1991                 secondmessage += " must be integer"
       
  1992                 if len(error) > 1:
       
  1993                     secondmessage += "s"
       
  1994         else:
       
  1995             firstmessage = ". A type must be selected"
       
  1996             good = False
       
  1997         if not good:
       
  1998             message = wxMessageDialog(self, "Form isn't valid%s%s%s!"%(firstmessage,secondmessage), "Error", wxOK|wxICON_ERROR)
       
  1999             message.ShowModal()
       
  2000             message.Destroy()
       
  2001             self.Name.SetFocus()
       
  2002         else:
       
  2003             self.EndModal(wxID_OK)
       
  2004 
  1875     def SetValues(self, min = None, max = None, length = None):
  2005     def SetValues(self, min = None, max = None, length = None):
  1876         if min != None:
  2006         if min != None:
  1877             self.Min.SetValue(str(min))
  2007             self.Min.SetValue(str(min))
  1878         if max != None:
  2008         if max != None:
  1879             self.Max.SetValue(str(max))
  2009             self.Max.SetValue(str(max))
  1924             self.Length.Enable(False)
  2054             self.Length.Enable(False)
  1925 
  2055 
  1926     def GetValues(self):
  2056     def GetValues(self):
  1927         name = self.Type.GetStringSelection()
  2057         name = self.Type.GetStringSelection()
  1928         type = self.TypeDictionary[name][0]
  2058         type = self.TypeDictionary[name][0]
  1929         min = eval(self.Min.GetValue())
  2059         min = int(self.Min.GetValue())
  1930         max = eval(self.Max.GetValue())
  2060         max = int(self.Max.GetValue())
  1931         length = eval(self.Length.GetValue())
  2061         length = int(self.Length.GetValue())
  1932         return type, min, max, length
  2062         return type, min, max, length
  1933 
  2063 
  1934 
  2064 
  1935 
  2065 
  1936 #-------------------------------------------------------------------------------
  2066 #-------------------------------------------------------------------------------
  1938 #-------------------------------------------------------------------------------
  2068 #-------------------------------------------------------------------------------
  1939 
  2069 
  1940 
  2070 
  1941 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, 
  2071 [wxID_NODEINFOSDIALOG, wxID_NODEINFOSDIALOGMAINPANEL, 
  1942  wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, 
  2072  wxID_NODEINFOSDIALOGNAME, wxID_NODEINFOSDIALOGNODEID, 
  1943  wxID_NODEINFOSDIALOGPROFILE, wxID_NODEINFOSDIALOGSTATICTEXT1, 
  2073  wxID_NODEINFOSDIALOGDESCRIPTION, wxID_NODEINFOSDIALOGSTATICTEXT1, 
  1944  wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, 
  2074  wxID_NODEINFOSDIALOGSTATICTEXT2, wxID_NODEINFOSDIALOGSTATICTEXT3, 
  1945  wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, 
  2075  wxID_NODEINFOSDIALOGSTATICTEXT4, wxID_NODEINFOSDIALOGTYPE, 
  1946 ] = [wx.NewId() for _init_ctrls in range(10)]
  2076 ] = [wx.NewId() for _init_ctrls in range(10)]
  1947 
  2077 
  1948 class NodeInfosDialog(wx.Dialog):
  2078 class NodeInfosDialog(wx.Dialog):
  1961 
  2091 
  1962     def _init_ctrls(self, prnt):
  2092     def _init_ctrls(self, prnt):
  1963         # generated method, don't edit
  2093         # generated method, don't edit
  1964         wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG,
  2094         wx.Dialog.__init__(self, id=wxID_NODEINFOSDIALOG,
  1965               name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
  2095               name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223),
  1966               size=wx.Size(249, 250), style=wx.DEFAULT_DIALOG_STYLE,
  2096               size=wx.Size(300, 300), style=wx.DEFAULT_DIALOG_STYLE,
  1967               title='Node Infos')
  2097               title='Node Infos')
  1968         self.SetClientSize(wx.Size(249, 250))
  2098         self.SetClientSize(wx.Size(300, 300))
  1969 
  2099 
  1970         self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL,
  2100         self.MainPanel = wx.Panel(id=wxID_NODEINFOSDIALOGMAINPANEL,
  1971               name='MainPanel', parent=self, pos=wx.Point(0, 0),
  2101               name='MainPanel', parent=self, pos=wx.Point(0, 0),
  1972               size=wx.Size(231, 264), style=wx.TAB_TRAVERSAL)
  2102               size=wx.Size(280, 264), style=wx.TAB_TRAVERSAL)
  1973         self.MainPanel.SetAutoLayout(True)
  2103         self.MainPanel.SetAutoLayout(True)
  1974 
  2104 
  1975         self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
  2105         self.staticText1 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT1,
  1976               label='Name:', 
  2106               label='Name:', 
  1977               name='staticText1', parent=self.MainPanel,
  2107               name='staticText1', parent=self.MainPanel,
  1978               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
  2108               pos=wx.Point(24, 24), size=wx.Size(156, 17), style=0)
  1979 
  2109 
  1980         self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name',
  2110         self.Name = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNAME, name='Name',
  1981               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(200,
  2111               parent=self.MainPanel, pos=wx.Point(24, 48), size=wx.Size(250,
  1982               25), style=0, value='')
  2112               25), style=0, value='')
  1983 
  2113 
  1984         self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2,
  2114         self.staticText2 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT2,
  1985               label='Node ID:', name='staticText2', parent=self.MainPanel,
  2115               label='Node ID:', name='staticText2', parent=self.MainPanel,
  1986               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
  2116               pos=wx.Point(24, 80), size=wx.Size(67, 17), style=0)
  1987 
  2117 
  1988         self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID',
  2118         self.NodeID = wx.TextCtrl(id=wxID_NODEINFOSDIALOGNODEID, name='NodeID',
  1989               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(200,
  2119               parent=self.MainPanel, pos=wx.Point(24, 104), size=wx.Size(250,
  1990               25), style=wx.TE_RIGHT, value='')
  2120               25), style=wx.TE_RIGHT, value='')
  1991 
  2121 
  1992         self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3,
  2122         self.staticText3 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT3,
  1993               label='Type:', name='staticText3', parent=self.MainPanel,
  2123               label='Type:', name='staticText3', parent=self.MainPanel,
  1994               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
  2124               pos=wx.Point(24, 136), size=wx.Size(71, 17), style=0)
  1995 
  2125 
  1996         self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE,
  2126         self.Type = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGTYPE,
  1997               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
  2127               name='Type', parent=self.MainPanel, pos=wx.Point(24, 160),
  1998               size=wx.Size(200, 25), style=0)
  2128               size=wx.Size(250, 25), style=0)
  1999 
  2129 
  2000         self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4,
  2130         self.staticText4 = wx.StaticText(id=wxID_NODEINFOSDIALOGSTATICTEXT4,
  2001               label='Profile:', name='staticText4', parent=self.MainPanel,
  2131               label='Description:', name='staticText4', parent=self.MainPanel,
  2002               pos=wx.Point(24, 192), size=wx.Size(47, 17), style=0)
  2132               pos=wx.Point(24, 192), size=wx.Size(71, 17), style=0)
  2003 
  2133 
  2004         self.Profile = wx.Choice(choices=[], id=wxID_NODEINFOSDIALOGPROFILE,
  2134         self.Description = wx.TextCtrl(id=wxID_NODEINFOSDIALOGDESCRIPTION, 
  2005               name='Profile', parent=self.MainPanel, pos=wx.Point(24, 216),
  2135               name='Description', parent=self.MainPanel, pos=wx.Point(24, 216), 
  2006               size=wx.Size(200, 25), style=0)
  2136               size=wx.Size(250, 25), style=0, value='')
  2007 
  2137 
  2008         self._init_sizers()
  2138         self._init_sizers()
  2009 
  2139 
  2010     def __init__(self, parent):
  2140     def __init__(self, parent):
  2011         self._init_ctrls(parent)
  2141         self._init_ctrls(parent)
  2012         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  2142         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  2013         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  2143         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  2014         self.Type.Append("master")
  2144         self.Type.Append("master")
  2015         self.Type.Append("slave")
  2145         self.Type.Append("slave")
  2016         self.staticText4.Hide()
       
  2017         self.Profile.Hide()
       
  2018 
  2146 
  2019         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
  2147         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
  2020 
  2148 
  2021     def OnOK(self, event):
  2149     def OnOK(self, event):
  2022         name = self.Name.GetValue()
  2150         name = self.Name.GetValue()
       
  2151         message = ""
  2023         if name != "":
  2152         if name != "":
  2024             good = not name[0].isdigit()
  2153             good = not name[0].isdigit()
  2025             for item in name.split("_"):
  2154             for item in name.split("_"):
  2026                 good &= item.isalnum()
  2155                 good &= item.isalnum()
  2027         else:
  2156             if not good:
  2028             good = False
  2157                 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
  2029         if not good:
  2158         if message != "":
  2030             message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR)
  2159             try:
       
  2160                 nodeid = int(self.NodeID.GetValue(), 16)
       
  2161             except:
       
  2162                 message = "Node ID must be integer!"
       
  2163         if message != "":
       
  2164             message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
  2031             message.ShowModal()
  2165             message.ShowModal()
  2032             message.Destroy()
  2166             message.Destroy()
  2033             self.Name.SetFocus()
  2167             self.Name.SetFocus()
  2034         else:
  2168         else:
  2035             self.EndModal(wxID_OK)
  2169             self.EndModal(wxID_OK)
  2036     
  2170     
  2037     def SetProfiles(self, profiles):
  2171     def SetValues(self, name, id, type, description):
  2038         for profile in profiles:
       
  2039             self.Profile.Append(profile)
       
  2040     
       
  2041     def SetValues(self, name, id, type, profile):
       
  2042         self.Name.SetValue(name)
  2172         self.Name.SetValue(name)
  2043         self.NodeID.SetValue("0x%02X"%id)
  2173         self.NodeID.SetValue("0x%02X"%id)
  2044         self.Type.SetStringSelection(type)
  2174         self.Type.SetStringSelection(type)
  2045         self.Profile.SetStringSelection(profile)
  2175         self.Description.SetValue(description)
  2046 
  2176 
  2047     def GetValues(self):
  2177     def GetValues(self):
  2048         name = self.Name.GetValue()
  2178         name = self.Name.GetValue()
  2049         nodeid = eval(self.NodeID.GetValue())
  2179         nodeid = int(self.NodeID.GetValue(), 16)
  2050         type = self.Type.GetStringSelection()
  2180         type = self.Type.GetStringSelection()
  2051         profile = self.Profile.GetStringSelection()
  2181         description = self.Description.GetValue()
  2052         return name, nodeid, type, profile
  2182         return name, nodeid, type, description
  2053 
  2183 
  2054 
  2184 
  2055 
  2185 
  2056 #-------------------------------------------------------------------------------
  2186 #-------------------------------------------------------------------------------
  2057 #                          Create New Node Dialog
  2187 #                          Create New Node Dialog
  2064  wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, 
  2194  wxID_CREATENODEDIALOGNMT_NODEGUARDING, wxID_CREATENODEDIALOGNMT_NONE, 
  2065  wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, 
  2195  wxID_CREATENODEDIALOGNODEID, wxID_CREATENODEDIALOGPROFILE, 
  2066  wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, 
  2196  wxID_CREATENODEDIALOGSAVECONFIG, wxID_CREATENODEDIALOGSTATICTEXT1, 
  2067  wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, 
  2197  wxID_CREATENODEDIALOGSTATICTEXT2, wxID_CREATENODEDIALOGSTATICTEXT3, 
  2068  wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, 
  2198  wxID_CREATENODEDIALOGSTATICTEXT4, wxID_CREATENODEDIALOGSTATICTEXT5, 
  2069  wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTOREEDS, 
  2199  wxID_CREATENODEDIALOGSTATICTEXT6, wxID_CREATENODEDIALOGSTATICTEXT7,
       
  2200  wxID_CREATENODEDIALOGSTOREEDS, wxID_CREATENODEDIALOGDESCRIPTION,
  2070  wxID_CREATENODEDIALOGTYPE, 
  2201  wxID_CREATENODEDIALOGTYPE, 
  2071 ] = [wx.NewId() for _init_ctrls in range(19)]
  2202 ] = [wx.NewId() for _init_ctrls in range(21)]
  2072 
  2203 
  2073 class CreateNodeDialog(wx.Dialog):
  2204 class CreateNodeDialog(wx.Dialog):
  2074     def _init_coll_flexGridSizer1_Items(self, parent):
  2205     def _init_coll_flexGridSizer1_Items(self, parent):
  2075         # generated method, don't edit
  2206         # generated method, don't edit
  2076 
  2207 
  2086 
  2217 
  2087     def _init_ctrls(self, prnt):
  2218     def _init_ctrls(self, prnt):
  2088         # generated method, don't edit
  2219         # generated method, don't edit
  2089         wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG,
  2220         wx.Dialog.__init__(self, id=wxID_CREATENODEDIALOG,
  2090               name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
  2221               name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223),
  2091               size=wx.Size(451, 316), style=wx.DEFAULT_DIALOG_STYLE,
  2222               size=wx.Size(451, 376), style=wx.DEFAULT_DIALOG_STYLE,
  2092               title='Create a new Node')
  2223               title='Create a new Node')
  2093         self.SetClientSize(wx.Size(451, 316))
  2224         self.SetClientSize(wx.Size(451, 376))
  2094 
  2225 
  2095         self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL,
  2226         self.MainPanel = wx.Panel(id=wxID_CREATENODEDIALOGMAINPANEL,
  2096               name='MainPanel', parent=self, pos=wx.Point(0, 0),
  2227               name='MainPanel', parent=self, pos=wx.Point(0, 0),
  2097               size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL)
  2228               size=wx.Size(440, 278), style=wx.TAB_TRAVERSAL)
  2098         self.MainPanel.SetAutoLayout(True)
  2229         self.MainPanel.SetAutoLayout(True)
  2183 
  2314 
  2184 #        self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS,
  2315 #        self.StoreEDS = wx.CheckBox(id=wxID_CREATENODEDIALOGSTOREEDS,
  2185 #              label='Store EDS', name='StoreEDS', parent=self.MainPanel,
  2316 #              label='Store EDS', name='StoreEDS', parent=self.MainPanel,
  2186 #              pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0)
  2317 #              pos=wx.Point(256, 240), size=wx.Size(144, 24), style=0)
  2187 #        self.StoreEDS.SetValue(False)
  2318 #        self.StoreEDS.SetValue(False)
  2188  
  2319 
       
  2320         self.staticText7 = wx.StaticText(id=wxID_CREATENODEDIALOGSTATICTEXT7,
       
  2321               label='Description:', name='staticText7', parent=self.MainPanel,
       
  2322               pos=wx.Point(24, 248), size=wx.Size(71, 17), style=0)
       
  2323 
       
  2324         self.Description = wx.TextCtrl(id=wxID_CREATENODEDIALOGDESCRIPTION, 
       
  2325               name='Description', parent=self.MainPanel, pos=wx.Point(24, 272), 
       
  2326               size=wx.Size(400, 25), style=0, value='')
       
  2327 
  2189         self._init_sizers()
  2328         self._init_sizers()
  2190 
  2329 
  2191     def __init__(self, parent):
  2330     def __init__(self, parent):
  2192         self._init_ctrls(parent)
  2331         self._init_ctrls(parent)
  2193         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  2332         self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
  2194         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  2333         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_CENTER)
  2195         self.NodeID.SetValue("0x00")
  2334         self.NodeID.SetValue("0x00")
  2196         self.Type.Append("master")
  2335         self.Type.Append("master")
  2197         self.Type.Append("slave")
  2336         self.Type.Append("slave")
  2198         self.Type.SetStringSelection("slave")
  2337         self.Type.SetStringSelection("slave")
       
  2338         self.Description.SetValue("")
  2199         self.ListProfile = {"None" : ""}
  2339         self.ListProfile = {"None" : ""}
  2200         self.Profile.Append("None")
  2340         self.Profile.Append("None")
  2201         self.Directory = os.path.join(ScriptDirectory, "config")
  2341         self.Directory = os.path.join(ScriptDirectory, "config")
  2202         listfiles = os.listdir(self.Directory)
  2342         listfiles = os.listdir(self.Directory)
  2203         listfiles.sort()
  2343         listfiles.sort()
  2212         
  2352         
  2213         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
  2353         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
  2214 
  2354 
  2215     def OnOK(self, event):
  2355     def OnOK(self, event):
  2216         name = self.Name.GetValue()
  2356         name = self.Name.GetValue()
       
  2357         message = ""
  2217         if name != "":
  2358         if name != "":
  2218             good = not name[0].isdigit()
  2359             good = not name[0].isdigit()
  2219             for item in name.split("_"):
  2360             for item in name.split("_"):
  2220                 good &= item.isalnum()
  2361                 good &= item.isalnum()
  2221         else:
  2362             if not good:
  2222             good = False
  2363                 message = "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!"
  2223         if not good:
  2364         if message != "":
  2224             message = wxMessageDialog(self, "Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!", "ERROR", wxOK|wxICON_ERROR)
  2365             try:
       
  2366                 nodeid = int(self.NodeID.GetValue(), 16)
       
  2367             except:
       
  2368                 message = "Node ID must be an integer!"
       
  2369         if message != "":
       
  2370             message = wxMessageDialog(self, message, "ERROR", wxOK|wxICON_ERROR)
  2225             message.ShowModal()
  2371             message.ShowModal()
  2226             message.Destroy()
  2372             message.Destroy()
  2227             self.Name.SetFocus()
  2373             self.Name.SetFocus()
  2228         else:
  2374         else:
  2229             self.EndModal(wxID_OK)
  2375             self.EndModal(wxID_OK)
  2230 
  2376 
  2231     def GetValues(self):
  2377     def GetValues(self):
  2232         name = self.Name.GetValue()
  2378         name = self.Name.GetValue()
  2233         nodeid = 0
  2379         nodeid = 0
  2234         if self.NodeID.GetValue() != "":
  2380         if self.NodeID.GetValue() != "":
  2235             nodeid = eval(self.NodeID.GetValue())
  2381             nodeid = int(self.NodeID.GetValue(), 16)
  2236         type = self.Type.GetStringSelection()
  2382         type = self.Type.GetStringSelection()
  2237         return name, nodeid, type
  2383         description = self.Description.GetValue()
       
  2384         return name, nodeid, type, description
  2238 
  2385 
  2239     def GetProfile(self):
  2386     def GetProfile(self):
  2240         name = self.Profile.GetStringSelection()
  2387         name = self.Profile.GetStringSelection()
  2241         return name, self.ListProfile[name]
  2388         return name, self.ListProfile[name]
  2242 
  2389