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 #------------------------------------------------------------------------------- |
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 |
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)) |
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 |
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 |