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