lbessard@205: #!/usr/bin/env python lbessard@205: # -*- coding: utf-8 -*- lbessard@205: lbessard@205: #This file is part of CanFestival, a library implementing CanOpen Stack. lbessard@205: # lbessard@205: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD lbessard@205: # lbessard@205: #See COPYING file for copyrights details. lbessard@205: # lbessard@205: #This library is free software; you can redistribute it and/or lbessard@205: #modify it under the terms of the GNU Lesser General Public lbessard@205: #License as published by the Free Software Foundation; either lbessard@205: #version 2.1 of the License, or (at your option) any later version. lbessard@205: # lbessard@205: #This library is distributed in the hope that it will be useful, lbessard@205: #but WITHOUT ANY WARRANTY; without even the implied warranty of lbessard@205: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU lbessard@205: #Lesser General Public License for more details. lbessard@205: # lbessard@205: #You should have received a copy of the GNU Lesser General Public lbessard@205: #License along with this library; if not, write to the Free Software lbessard@205: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lbessard@205: lbessard@205: import wx lbessard@359: import wx.grid lbessard@205: lbessard@205: import os lbessard@205: lbessard@327: from node import BE_to_LE, LE_to_BE lbessard@327: lbessard@258: ScriptDirectory = os.path.split(__file__)[0] lbessard@258: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Editing Communication Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: lbessard@254: [ID_COMMUNICATIONDIALOG, ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, lbessard@254: ID_COMMUNICATIONDIALOGCURRENTINDEXES, ID_COMMUNICATIONDIALOGSELECT, lbessard@254: ID_COMMUNICATIONDIALOGUNSELECT, ID_COMMUNICATIONDIALOGSTATICTEXT1, lbessard@254: ID_COMMUNICATIONDIALOGSTATICTEXT2 lbessard@254: ] = [wx.NewId() for _init_ctrls in range(7)] lbessard@205: lbessard@205: class CommunicationDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.LeftGridSizer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddSizer(self.MiddleGridSizer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddSizer(self.RightGridSizer, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_MainSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableCol(2) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.PossibleIndexes, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(1) lbessard@254: lbessard@254: def _init_coll_MiddleGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.Select, 0, border=0, flag=wx.ALIGN_BOTTOM) lbessard@254: parent.AddWindow(self.Unselect, 0, border=0, flag=wx.ALIGN_TOP) lbessard@254: lbessard@254: def _init_coll_MiddleGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: parent.AddGrowableRow(1) lbessard@254: lbessard@254: def _init_coll_RightGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.CurrentIndexes, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(1) lbessard@205: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.FlexGridSizer(cols=3, hgap=15, rows=1, vgap=0) lbessard@254: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@254: self.MiddleGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=40) lbessard@254: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@254: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@254: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@254: self._init_coll_MiddleGridSizer_Items(self.MiddleGridSizer) lbessard@254: self._init_coll_MiddleGridSizer_Growables(self.MiddleGridSizer) lbessard@254: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@254: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@205: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Dialog.__init__(self, id=ID_COMMUNICATIONDIALOG, lbessard@205: name='CommunicationDialog', parent=prnt, pos=wx.Point(234, 216), lbessard@254: size=wx.Size(726, 437), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, laurent@580: title=_('Edit Communication Profile')) lbessard@205: self.SetClientSize(wx.Size(726, 437)) lbessard@205: lbessard@254: self.staticText1 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT1, laurent@580: label=_('Possible Profile Indexes:'), name='staticText1', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, lbessard@254: 17), style=0) lbessard@205: lbessard@205: self.PossibleIndexes = wx.ListBox(choices=[], lbessard@254: id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES, lbessard@254: name='PossibleIndexes', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 0), style=wx.LB_EXTENDED) lbessard@266: self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnPossibleIndexesDClick, lbessard@254: id=ID_COMMUNICATIONDIALOGPOSSIBLEINDEXES) lbessard@254: lbessard@254: self.Select = wx.Button(id=ID_COMMUNICATIONDIALOGSELECT, label='>>', lbessard@254: name='Select', parent=self, pos=wx.Point(0, 0), lbessard@205: size=wx.Size(32, 32), style=0) lbessard@205: self.Select.Bind(wx.EVT_BUTTON, self.OnSelectButton, lbessard@254: id=ID_COMMUNICATIONDIALOGSELECT) lbessard@254: lbessard@254: self.Unselect = wx.Button(id=ID_COMMUNICATIONDIALOGUNSELECT, lbessard@254: label='<<', name='Unselect', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(32, 32), style=0) lbessard@205: self.Unselect.Bind(wx.EVT_BUTTON, self.OnUnselectButton, lbessard@254: id=ID_COMMUNICATIONDIALOGUNSELECT) lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_COMMUNICATIONDIALOGSTATICTEXT2, laurent@580: label=_('Current Profile Indexes:'), name='staticText2', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, lbessard@205: 17), style=0) lbessard@205: lbessard@254: self.CurrentIndexes = wx.ListBox(choices=[], lbessard@254: id=ID_COMMUNICATIONDIALOGCURRENTINDEXES, name='CurrentIndexes', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 0), lbessard@254: style=wx.LB_EXTENDED) lbessard@266: self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnCurrentIndexesDClick, lbessard@254: id=ID_COMMUNICATIONDIALOGCURRENTINDEXES) lbessard@254: lbessard@254: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: lbessard@205: def __init__(self, parent): lbessard@205: self._init_ctrls(parent) lbessard@205: self.AllList = [] lbessard@205: self.CurrentList = [] lbessard@205: self.IndexDictionary = {} lbessard@205: lbessard@205: def SetIndexDictionary(self, dictionary): lbessard@205: self.IndexDictionary = dictionary lbessard@205: lbessard@205: def SetCurrentList(self, list): lbessard@205: self.CurrentList = [] lbessard@205: self.CurrentList.extend(list) lbessard@205: self.CurrentList.sort() lbessard@205: lbessard@205: def GetCurrentList(self): lbessard@205: return self.CurrentList lbessard@205: lbessard@205: def RefreshLists(self): lbessard@205: self.PossibleIndexes.Clear() lbessard@205: self.CurrentIndexes.Clear() lbessard@205: self.AllList = [] lbessard@205: for index in self.IndexDictionary.iterkeys(): lbessard@205: if index not in self.CurrentList: lbessard@205: self.AllList.append(index) lbessard@205: self.AllList.sort() lbessard@205: for index in self.AllList: lbessard@205: self.PossibleIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) lbessard@205: for index in self.CurrentList: lbessard@205: if index in self.IndexDictionary: lbessard@205: self.CurrentIndexes.Append("0x%04X %s"%(index, self.IndexDictionary[index][0])) lbessard@205: lbessard@205: def OnPossibleIndexesDClick(self, event): lbessard@205: self.SelectPossible() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnCurrentIndexesDClick(self, event): lbessard@205: self.UnselectCurrent() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnSelectButton(self, event): lbessard@205: self.SelectPossible() lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnUnselectButton(self, event): lbessard@205: self.UnselectCurrent() lbessard@205: event.Skip() lbessard@205: lbessard@205: def SelectPossible(self): lbessard@205: selected = self.PossibleIndexes.GetSelections() lbessard@205: for i in selected: lbessard@205: self.CurrentList.append(self.AllList[i]) lbessard@205: self.CurrentList.sort() lbessard@205: self.RefreshLists() lbessard@205: lbessard@205: def UnselectCurrent(self): lbessard@205: selected = self.CurrentIndexes.GetSelections() lbessard@205: for i in selected: lbessard@205: if not self.IndexDictionary[self.CurrentList[i]][1]: lbessard@205: self.CurrentList.pop(i) lbessard@205: self.CurrentList.sort() lbessard@205: self.RefreshLists() lbessard@205: lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Create Map Variable Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: lbessard@254: [ID_MAPVARIABLEDIALOG, ID_MAPVARIABLEDIALOGINDEX, lbessard@254: ID_MAPVARIABLEDIALOGINDEXNAME, ID_MAPVARIABLEDIALOGSPACER, lbessard@259: ID_MAPVARIABLEDIALOGSPACER2, ID_MAPVARIABLEDIALOGNUMBER, lbessard@259: ID_MAPVARIABLEDIALOGRADIOBUTTON1, ID_MAPVARIABLEDIALOGRADIOBUTTON2, lbessard@259: ID_MAPVARIABLEDIALOGRADIOBUTTON3, ID_MAPVARIABLEDIALOGSTATICTEXT1, lbessard@259: ID_MAPVARIABLEDIALOGSTATICTEXT2, ID_MAPVARIABLEDIALOGSTATICTEXT3, lbessard@259: ID_MAPVARIABLEDIALOGSTATICTEXT4, lbessard@259: ] = [wx.NewId() for _init_ctrls in range(13)] lbessard@205: lbessard@205: class MapVariableDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Index, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.radioButton1, 0, border=0, flag=wx.GROW) lbessard@259: parent.AddWindow(self.Spacer2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.radioButton2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.IndexName, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.radioButton3, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Number, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_MainSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableCol(2) lbessard@205: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.FlexGridSizer(cols=3, hgap=30, rows=4, vgap=5) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@205: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Dialog.__init__(self, id=ID_MAPVARIABLEDIALOG, lbessard@205: name='CommunicationDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@205: size=wx.Size(444, 186), style=wx.DEFAULT_DIALOG_STYLE, laurent@580: title=_('Add Map Variable')) lbessard@205: self.SetClientSize(wx.Size(444, 186)) lbessard@205: lbessard@254: self.staticText1 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT1, laurent@580: label=_('Index:'), name='staticText1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT2, laurent@580: label=_('Type:'), name='staticText2', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText3 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT3, laurent@580: label=_('Name:'), name='staticText3', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText4 = wx.StaticText(id=ID_MAPVARIABLEDIALOGSTATICTEXT4, laurent@580: label=_('Number:'), name='staticText4', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 16), style=0) lbessard@254: lbessard@254: self.radioButton1 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON1, lbessard@254: label='VAR', name='radioButton1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(80, 24), style=wx.RB_GROUP) lbessard@205: self.radioButton1.SetValue(True) lbessard@205: self.radioButton1.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton1Click, lbessard@254: id=ID_MAPVARIABLEDIALOGRADIOBUTTON1) lbessard@254: lbessard@254: self.radioButton2 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON2, lbessard@254: label='ARRAY', name='radioButton2', parent=self, lbessard@543: pos=wx.Point(0, 0), size=wx.Size(80, 24), style=0) lbessard@205: self.radioButton2.SetValue(False) lbessard@205: self.radioButton2.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton2Click, lbessard@254: id=ID_MAPVARIABLEDIALOGRADIOBUTTON2) lbessard@254: lbessard@254: self.radioButton3 = wx.RadioButton(id=ID_MAPVARIABLEDIALOGRADIOBUTTON3, lbessard@254: label='REC', name='radioButton3', parent=self, lbessard@543: pos=wx.Point(0, 0), size=wx.Size(80, 24), style=0) lbessard@205: self.radioButton3.SetValue(False) lbessard@205: self.radioButton3.Bind(wx.EVT_RADIOBUTTON, self.OnRadioButton3Click, lbessard@254: id=ID_MAPVARIABLEDIALOGRADIOBUTTON3) lbessard@254: lbessard@254: self.Index = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEX, name='Index', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25), lbessard@254: style=0, value='0x2000') lbessard@254: lbessard@254: self.IndexName = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGINDEXNAME, lbessard@254: name='IndexName', parent=self, pos=wx.Point(0, 0), laurent@580: size=wx.Size(0, 24), style=0, value=_('Undefined')) lbessard@254: lbessard@254: self.Number = wx.TextCtrl(id=ID_MAPVARIABLEDIALOGNUMBER, lbessard@254: name='Number', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 24), style=wx.TE_RIGHT, value='0') lbessard@254: lbessard@254: self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER, lbessard@254: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@254: lbessard@259: self.Spacer2 = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER2, lbessard@259: name='Spacer2', parent=self, pos=wx.Point(0, 0), lbessard@259: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@259: lbessard@254: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) lbessard@254: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: lbessard@205: def __init__(self, parent): lbessard@205: self._init_ctrls(parent) lbessard@205: self.staticText4.Enable(False) lbessard@205: self.Number.Enable(False) lbessard@205: lbessard@205: def SetIndex(self, index): lbessard@205: self.Index.SetValue("0x%04X"%index) lbessard@205: lbessard@205: def OnOK(self, event): lbessard@205: error = [] lbessard@205: try: lbessard@205: int(self.Index.GetValue(), 16) lbessard@205: except: laurent@580: error.append(_("Index")) lbessard@205: if self.radioButton2.GetValue() or self.radioButton3.GetValue(): lbessard@205: try: lbessard@205: int(self.Number.GetValue()) lbessard@205: except: laurent@580: error.append(_("Number")) lbessard@205: if len(error) > 0: lbessard@205: text = "" lbessard@205: for i, item in enumerate(error): lbessard@205: if i == 0: lbessard@205: text += item lbessard@205: elif i == len(error) - 1: laurent@580: text += (" and %s")%item + _(" must be integers!") lbessard@205: else: laurent@580: text += _(", %s")%item + _(" must be integer!") laurent@580: message = wx.MessageDialog(self, _("Form isn't valid. %s")%text, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: else: lbessard@254: self.EndModal(wx.ID_OK) lbessard@205: lbessard@205: def GetValues(self): lbessard@205: name = self.IndexName.GetValue() lbessard@205: index = int(self.Index.GetValue(), 16) lbessard@205: if self.radioButton1.GetValue(): lbessard@205: struct = 1 lbessard@205: number = None lbessard@205: elif self.radioButton2.GetValue(): lbessard@452: struct = 7 lbessard@205: number = int(self.Number.GetValue()) lbessard@205: elif self.radioButton3.GetValue(): lbessard@452: struct = 3 lbessard@205: number = int(self.Number.GetValue()) lbessard@205: return index, name, struct, number lbessard@205: lbessard@205: def OnRadioButton1Click(self, event): lbessard@205: self.EnableNumberTyping(False) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnRadioButton2Click(self, event): lbessard@205: self.EnableNumberTyping(True) lbessard@205: event.Skip() lbessard@205: lbessard@205: def OnRadioButton3Click(self, event): lbessard@205: self.EnableNumberTyping(True) lbessard@205: event.Skip() lbessard@205: lbessard@205: def EnableNumberTyping(self, enable): lbessard@205: self.staticText4.Enable(enable) lbessard@205: self.Number.Enable(enable) lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Create User Type Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: lbessard@254: [ID_USERTYPEDIALOG, ID_USERTYPEDIALOGSPACER, lbessard@254: ID_USERTYPEDIALOGTYPE, ID_USERTYPEDIALOGMAX, lbessard@254: ID_USERTYPEDIALOGMIN, ID_USERTYPEDIALOGLENGTH, lbessard@254: ID_USERTYPEDIALOGSTATICBOX1, ID_USERTYPEDIALOGSTATICTEXT1, lbessard@254: ID_USERTYPEDIALOGSTATICTEXT2, ID_USERTYPEDIALOGSTATICTEXT3, lbessard@254: ID_USERTYPEDIALOGSTATICTEXT4, lbessard@205: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@205: lbessard@205: class UserTypeDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.LeftGridSizer, 2, border=5, flag=wx.GROW|wx.RIGHT) lbessard@254: parent.AddSizer(self.RightBoxSizer, 3, border=5, flag=wx.GROW|wx.LEFT) lbessard@254: lbessard@254: def _init_coll_LeftGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_LeftGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(2) lbessard@254: lbessard@254: def _init_coll_RightBoxSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.RightBoxGridSizer, 0, border=10, flag=wx.GROW|wx.ALL) lbessard@254: lbessard@254: def _init_coll_RightBoxGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Min, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Max, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Length, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_RightBoxGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(1) lbessard@254: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@254: self.LeftGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) lbessard@254: self.RightBoxSizer = wx.StaticBoxSizer(self.staticBox1, wx.VERTICAL) lbessard@254: self.RightBoxGridSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=10) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_LeftGridSizer_Items(self.LeftGridSizer) lbessard@254: self._init_coll_LeftGridSizer_Growables(self.LeftGridSizer) lbessard@254: self._init_coll_RightBoxSizer_Items(self.RightBoxSizer) lbessard@254: self._init_coll_RightBoxGridSizer_Items(self.RightBoxGridSizer) lbessard@254: self._init_coll_RightBoxGridSizer_Growables(self.RightBoxGridSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@205: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Dialog.__init__(self, id=ID_USERTYPEDIALOG, name='UserTypeDialog', lbessard@254: parent=prnt, pos=wx.Point(376, 223), size=wx.Size(444, 210), laurent@580: style=wx.DEFAULT_DIALOG_STYLE, title=_('Add User Type')) lbessard@254: self.SetClientSize(wx.Size(444, 210)) lbessard@254: lbessard@254: self.staticText1 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT1, laurent@580: label=_('Type:'), name='staticText1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: laurent@585: self.Type = wx.ComboBox(choices=[], id=ID_USERTYPEDIALOGTYPE, lbessard@254: name='Type', parent=self, pos=wx.Point(0, 0), laurent@585: size=wx.Size(0, 28), style=wx.CB_READONLY) Laurent@762: self.Type.Bind(wx.wx.EVT_COMBOBOX, self.OnTypeChoice, lbessard@254: id=ID_USERTYPEDIALOGTYPE) lbessard@254: lbessard@254: self.Spacer = wx.Panel(id=ID_MAPVARIABLEDIALOGSPACER, lbessard@254: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@254: lbessard@254: self.staticBox1 = wx.StaticBox(id=ID_USERTYPEDIALOGSTATICBOX1, laurent@580: label=_('Values'), name='staticBox1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0) lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT2, laurent@580: label=_('Minimum:'), name='staticText2', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0) lbessard@254: lbessard@254: self.Min = wx.TextCtrl(id=ID_USERTYPEDIALOGMIN, name='Min', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=wx.TE_RIGHT, value='0') lbessard@254: lbessard@254: self.staticText3 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT3, laurent@580: label=_('Maximum:'), name='staticText3', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0) lbessard@254: lbessard@254: self.Max = wx.TextCtrl(id=ID_USERTYPEDIALOGMAX, name='Max', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=wx.TE_RIGHT, value='0') lbessard@254: lbessard@254: self.staticText4 = wx.StaticText(id=ID_USERTYPEDIALOGSTATICTEXT4, laurent@580: label=_('Length:'), name='staticText4', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(80, 17), style=0) lbessard@254: lbessard@254: self.Length = wx.TextCtrl(id=ID_USERTYPEDIALOGLENGTH, name='Length', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=wx.TE_RIGHT, value='0') lbessard@254: lbessard@254: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) lbessard@254: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: lbessard@205: def __init__(self, parent): lbessard@205: self._init_ctrls(parent) lbessard@254: lbessard@205: self.TypeDictionary = {} lbessard@205: lbessard@205: def OnOK(self, event): lbessard@205: error = [] lbessard@205: good = True laurent@580: message = None lbessard@205: name = self.Type.GetStringSelection() lbessard@205: if name != "": lbessard@205: valuetype = self.TypeDictionary[name][1] lbessard@205: if valuetype == 0: lbessard@205: try: lbessard@205: int(self.Min.GetValue(), 16) lbessard@205: except: laurent@580: error.append(_("Minimum")) lbessard@205: good = False lbessard@205: try: lbessard@205: int(self.Max.GetValue(), 16) lbessard@205: except: laurent@580: error.append(_("Maximum")) lbessard@205: good = False lbessard@205: elif valuetype == 1: lbessard@205: try: lbessard@205: int(self.Length.GetValue(), 16) lbessard@205: except: laurent@580: error.append(_("Length")) lbessard@205: good = False lbessard@205: if len(error) > 0: laurent@580: message = "" lbessard@205: for i, item in enumerate(error): lbessard@205: if i == 0: laurent@580: message += item lbessard@205: elif i == len(error) - 1: laurent@580: message += _(" and %s")%item + _(" must be integers!") lbessard@205: else: laurent@580: message += _(", %s")%item + _(" must be integer!") lbessard@205: else: laurent@580: message = _("A type must be selected!") laurent@580: if message is not None: laurent@580: message = wx.MessageDialog(self, _("Form isn't valid. %s")%(firstmessage,secondmessage), _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: else: lbessard@254: self.EndModal(wx.ID_OK) lbessard@205: lbessard@205: def SetValues(self, min = None, max = None, length = None): lbessard@205: if min != None: lbessard@205: self.Min.SetValue(str(min)) lbessard@205: if max != None: lbessard@205: self.Max.SetValue(str(max)) lbessard@205: if length != None: lbessard@205: self.Length.SetValue(str(length)) lbessard@205: lbessard@205: def SetTypeList(self, typedic, type = None): lbessard@205: self.Type.Clear() lbessard@205: list = [] lbessard@205: for index, (name, valuetype) in typedic.iteritems(): lbessard@205: self.TypeDictionary[name] = (index, valuetype) lbessard@205: list.append((index, name)) lbessard@205: list.sort() lbessard@205: for index, name in list: lbessard@205: self.Type.Append(name) lbessard@205: if type != None: lbessard@205: self.Type.SetStringSelection(typedic[type][0]) lbessard@205: self.RefreshValues() lbessard@205: lbessard@205: def OnTypeChoice(self, event): lbessard@205: self.RefreshValues() lbessard@205: event.Skip() lbessard@205: lbessard@205: def RefreshValues(self): lbessard@205: name = self.Type.GetStringSelection() lbessard@205: if name != "": lbessard@205: valuetype = self.TypeDictionary[name][1] lbessard@205: if valuetype == 0: lbessard@205: self.staticText2.Enable(True) lbessard@205: self.staticText3.Enable(True) lbessard@205: self.staticText4.Enable(False) lbessard@205: self.Min.Enable(True) lbessard@205: self.Max.Enable(True) lbessard@205: self.Length.Enable(False) lbessard@205: elif valuetype == 1: lbessard@205: self.staticText2.Enable(False) lbessard@205: self.staticText3.Enable(False) lbessard@205: self.staticText4.Enable(True) lbessard@205: self.Min.Enable(False) lbessard@205: self.Max.Enable(False) lbessard@205: self.Length.Enable(True) lbessard@205: else: lbessard@205: self.staticText2.Enable(False) lbessard@205: self.staticText3.Enable(False) lbessard@205: self.staticText4.Enable(False) lbessard@205: self.Min.Enable(False) lbessard@205: self.Max.Enable(False) lbessard@205: self.Length.Enable(False) lbessard@205: lbessard@205: def GetValues(self): lbessard@205: name = self.Type.GetStringSelection() lbessard@205: type = self.TypeDictionary[name][0] lbessard@205: min = int(self.Min.GetValue()) lbessard@205: max = int(self.Max.GetValue()) lbessard@205: length = int(self.Length.GetValue()) lbessard@205: return type, min, max, length lbessard@205: lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Editing Node Infos Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: lbessard@254: [ID_NODEINFOSDIALOG, ID_NODEINFOSDIALOGNAME, lbessard@418: ID_NODEINFOSDIALOGNODEID, ID_NODEINFOSDIALOGTYPE, lbessard@418: ID_NODEINFOSDIALOGDEFAULTSTRINGSIZE, ID_NODEINFOSDIALOGDESCRIPTION, lbessard@418: ID_NODEINFOSDIALOGSTATICTEXT1, ID_NODEINFOSDIALOGSTATICTEXT2, lbessard@418: ID_NODEINFOSDIALOGSTATICTEXT3, ID_NODEINFOSDIALOGSTATICTEXT4, lbessard@418: ID_NODEINFOSDIALOGSTATICTEXT5, lbessard@418: ] = [wx.NewId() for _init_ctrls in range(11)] lbessard@205: laurent@580: def GetNodeTypes(): laurent@580: _ = lambda x : x laurent@580: return [_("master"), _("slave")] laurent@580: NODE_TYPES_DICT = dict([(_(node_type), node_type) for node_type in GetNodeTypes()]) laurent@580: lbessard@205: class NodeInfosDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW) lbessard@276: parent.AddWindow(self.NodeName, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText2, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.NodeID, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText3, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Type, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText4, 0, border=0, flag=wx.GROW) lbessard@418: parent.AddWindow(self.DefaultStringSize, 0, border=0, flag=wx.GROW) lbessard@418: parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_MainSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@205: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=8, vgap=5) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@254: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Dialog.__init__(self, id=ID_NODEINFOSDIALOG, lbessard@205: name='NodeInfosDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@254: size=wx.Size(300, 280), style=wx.DEFAULT_DIALOG_STYLE, laurent@580: title=_('Node infos')) lbessard@254: self.SetClientSize(wx.Size(300, 280)) lbessard@254: lbessard@254: self.staticText1 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT1, laurent@580: label=_('Name:'), name='staticText1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@276: self.NodeName = wx.TextCtrl(id=ID_NODEINFOSDIALOGNAME, name='NodeName', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=0, value='') lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT2, laurent@580: label=_('Node ID:'), name='staticText2', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.NodeID = wx.TextCtrl(id=ID_NODEINFOSDIALOGNODEID, name='NodeID', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 25), lbessard@254: style=wx.TE_RIGHT, value='') lbessard@254: lbessard@254: self.staticText3 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT3, laurent@580: label=_('Type:'), name='staticText3', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: laurent@585: self.Type = wx.ComboBox(choices=[], id=ID_NODEINFOSDIALOGTYPE, lbessard@254: name='Type', parent=self, pos=wx.Point(0, 0), laurent@585: size=wx.Size(0, 28), style=wx.CB_READONLY) lbessard@254: lbessard@254: self.staticText4 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT4, laurent@580: label=_('Default String Size:'), name='staticText4', parent=self, lbessard@418: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@418: lbessard@418: self.DefaultStringSize = wx.SpinCtrl(id=ID_NODEINFOSDIALOGDEFAULTSTRINGSIZE, lbessard@418: name='DefaultStringSize', parent=self, pos=wx.Point(0, 0), lbessard@418: size=wx.Size(0, 25), style=wx.TE_RIGHT) lbessard@418: lbessard@418: self.staticText5 = wx.StaticText(id=ID_NODEINFOSDIALOGSTATICTEXT5, laurent@580: label=_('Description:'), name='staticText5', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.Description = wx.TextCtrl(id=ID_NODEINFOSDIALOGDESCRIPTION, lbessard@254: name='Description', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 24), style=0, value='') lbessard@254: lbessard@254: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) lbessard@254: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: lbessard@205: def __init__(self, parent): lbessard@205: self._init_ctrls(parent) lbessard@254: lbessard@299: self.staticText2.Hide() lbessard@299: self.NodeID.Hide() lbessard@299: laurent@580: for node_type in GetNodeTypes(): laurent@580: self.Type.Append(_(node_type)) lbessard@205: lbessard@205: def OnOK(self, event): lbessard@276: name = self.NodeName.GetValue() lbessard@205: message = "" lbessard@205: if name != "": lbessard@205: good = not name[0].isdigit() lbessard@205: for item in name.split("_"): lbessard@205: good &= item.isalnum() lbessard@205: if not good: laurent@580: message = _("Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!") lbessard@205: if message != "": lbessard@205: try: lbessard@205: nodeid = int(self.NodeID.GetValue(), 16) lbessard@205: except: laurent@580: message = _("Node ID must be integer!") lbessard@205: if message != "": laurent@580: message = wx.MessageDialog(self, message, _("ERROR"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@276: self.NodeName.SetFocus() lbessard@205: else: lbessard@254: self.EndModal(wx.ID_OK) lbessard@205: lbessard@418: def SetValues(self, name, id, type, description, defaultstringsize): lbessard@276: self.NodeName.SetValue(name) lbessard@205: self.NodeID.SetValue("0x%02X"%id) laurent@580: self.Type.SetStringSelection(_(type)) lbessard@205: self.Description.SetValue(description) lbessard@418: self.DefaultStringSize.SetValue(defaultstringsize) lbessard@205: lbessard@205: def GetValues(self): lbessard@276: name = self.NodeName.GetValue() lbessard@205: nodeid = int(self.NodeID.GetValue(), 16) laurent@580: type = NODE_TYPES_DICT[self.Type.GetStringSelection()] lbessard@205: description = self.Description.GetValue() lbessard@418: defaultstringsize = self.DefaultStringSize.GetValue() lbessard@418: return name, nodeid, type, description, defaultstringsize lbessard@205: lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # Create New Node Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@205: lbessard@254: [ID_CREATENODEDIALOG, ID_CREATENODEDIALOGEMERGENCY, lbessard@254: ID_CREATENODEDIALOGGENSYNC, ID_CREATENODEDIALOGSPACER, lbessard@254: ID_CREATENODEDIALOGNAME, ID_CREATENODEDIALOGNMT_HEARTBEAT, lbessard@254: ID_CREATENODEDIALOGNMT_NODEGUARDING, ID_CREATENODEDIALOGNMT_NONE, lbessard@254: ID_CREATENODEDIALOGNODEID, ID_CREATENODEDIALOGPROFILE, lbessard@254: ID_CREATENODEDIALOGSAVECONFIG, ID_CREATENODEDIALOGSTATICTEXT1, lbessard@254: ID_CREATENODEDIALOGSTATICTEXT2, ID_CREATENODEDIALOGSTATICTEXT3, lbessard@254: ID_CREATENODEDIALOGSTATICTEXT4, ID_CREATENODEDIALOGSTATICTEXT5, lbessard@254: ID_CREATENODEDIALOGSTATICTEXT6, ID_CREATENODEDIALOGSTATICTEXT7, lbessard@254: ID_CREATENODEDIALOGSTOREEDS, ID_CREATENODEDIALOGDESCRIPTION, lbessard@254: ID_CREATENODEDIALOGTYPE, lbessard@205: ] = [wx.NewId() for _init_ctrls in range(21)] lbessard@205: lbessard@205: class CreateNodeDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.TopBoxSizer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.staticText7, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Description, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_MainSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: lbessard@254: def _init_coll_TopBoxSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.LeftBoxSizer, 1, border=10, flag=wx.GROW|wx.RIGHT) lbessard@254: parent.AddSizer(self.RightGridSizer, 1, border=10, flag=wx.GROW|wx.LEFT) lbessard@254: lbessard@254: def _init_coll_LeftBoxSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.Type, 0, border=10, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@276: parent.AddWindow(self.NodeName, 0, border=10, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.NodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.staticText4, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.Profile, 0, border=20, flag=wx.GROW|wx.BOTTOM) lbessard@254: lbessard@254: def _init_coll_RightGridSizer_Items(self, parent): lbessard@254: parent.AddSizer(self.RightTopGridSizer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Spacer, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddSizer(self.RightBottomGridSizer, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_RightGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(1) lbessard@254: lbessard@254: def _init_coll_RightTopGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText5, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.NMT_None, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.NMT_NodeGuarding, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.NMT_Heartbeat, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_RightTopGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: lbessard@254: def _init_coll_RightBottomGridSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText6, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.DS302, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.GenSYNC, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.Emergency, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.SaveConfig, 0, border=0, flag=wx.GROW) lbessard@254: parent.AddWindow(self.StoreEDS, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_RightBottomGridSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@205: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=5, rows=3, vgap=0) lbessard@254: self.TopBoxSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@254: self.LeftBoxSizer = wx.BoxSizer(wx.VERTICAL) lbessard@254: self.RightGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=5) lbessard@254: self.RightTopGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=0) lbessard@254: self.RightBottomGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=6, vgap=0) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@254: self._init_coll_TopBoxSizer_Items(self.TopBoxSizer) lbessard@254: self._init_coll_LeftBoxSizer_Items(self.LeftBoxSizer) lbessard@254: self._init_coll_RightGridSizer_Items(self.RightGridSizer) lbessard@254: self._init_coll_RightGridSizer_Growables(self.RightGridSizer) lbessard@254: self._init_coll_RightTopGridSizer_Items(self.RightTopGridSizer) lbessard@254: self._init_coll_RightTopGridSizer_Growables(self.RightTopGridSizer) lbessard@254: self._init_coll_RightBottomGridSizer_Items(self.RightBottomGridSizer) lbessard@254: self._init_coll_RightBottomGridSizer_Growables(self.RightBottomGridSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@205: etisserant@486: def _init_ctrls(self, prnt, buttons): lbessard@254: wx.Dialog.__init__(self, id=ID_CREATENODEDIALOG, lbessard@205: name='CreateNodeDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@254: size=wx.Size(450, 350), style=wx.DEFAULT_DIALOG_STYLE, laurent@580: title=_('Create a new Node')) lbessard@254: self.SetClientSize(wx.Size(450, 350)) lbessard@254: lbessard@254: self.staticText1 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT1, laurent@580: label=_('Type:'), name='staticText1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT2, laurent@580: label=_('Name:'), name='staticText2', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText3 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT3, laurent@580: label=_('Node ID:'), name='staticText3', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.staticText4 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT4, laurent@580: label=_('Profile:'), name='staticText4', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: laurent@585: self.Type = wx.ComboBox(choices=[], id=ID_CREATENODEDIALOGTYPE, lbessard@254: name='Type', parent=self, pos=wx.Point(0, 0), laurent@585: size=wx.Size(0, 28), style=wx.CB_READONLY) lbessard@254: lbessard@276: self.NodeName = wx.TextCtrl(id=ID_CREATENODEDIALOGNAME, name='NodeName', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=0, value='') lbessard@254: lbessard@254: self.NodeID = wx.TextCtrl(id=ID_CREATENODEDIALOGNODEID, name='NodeID', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), lbessard@254: style=wx.TE_RIGHT, value='') lbessard@254: laurent@585: self.Profile = wx.ComboBox(choices=[], id=ID_CREATENODEDIALOGPROFILE, lbessard@254: name='Profile', parent=self, pos=wx.Point(0, 0), laurent@585: size=wx.Size(0, 28), style=wx.CB_READONLY) Laurent@762: self.Profile.Bind(wx.EVT_COMBOBOX, self.OnProfileChoice, lbessard@254: id=ID_CREATENODEDIALOGPROFILE) lbessard@254: lbessard@254: self.staticText5 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT5, laurent@580: label=_('Network Management:'), name='staticText5', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.NMT_None = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NONE, laurent@580: label=_('None'), name='NMT_None', parent=self, lbessard@543: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=wx.RB_GROUP) lbessard@205: self.NMT_None.SetValue(True) lbessard@205: lbessard@254: self.NMT_NodeGuarding = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_NODEGUARDING, laurent@580: label=_('Node Guarding'), name='NMT_NodeGuarding', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.NMT_NodeGuarding.SetValue(False) lbessard@205: lbessard@254: self.NMT_Heartbeat = wx.RadioButton(id=ID_CREATENODEDIALOGNMT_HEARTBEAT, laurent@580: label=_('Heartbeat'), name='NMT_Heartbeat', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.NMT_Heartbeat.SetValue(False) lbessard@205: lbessard@254: self.staticText6 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT6, laurent@580: label=_('Options:'), name='staticText6', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.DS302 = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC, laurent@580: label=_('DS-302 Profile'), name='DS302', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.DS302.SetValue(False) lbessard@205: #self.DS302.Enable(False) lbessard@205: lbessard@254: self.GenSYNC = wx.CheckBox(id=ID_CREATENODEDIALOGGENSYNC, laurent@580: label=_('Generate SYNC'), name='GenSYNC', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.GenSYNC.SetValue(False) lbessard@205: lbessard@254: self.Emergency = wx.CheckBox(id=ID_CREATENODEDIALOGEMERGENCY, laurent@580: label=_('Emergency support'), name='Emergency', lbessard@254: parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.Emergency.SetValue(False) lbessard@205: lbessard@254: self.SaveConfig = wx.CheckBox(id=ID_CREATENODEDIALOGSAVECONFIG, laurent@580: label=_('Save Configuration'), name='SaveConfig', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@205: self.SaveConfig.SetValue(False) lbessard@205: self.SaveConfig.Enable(False) lbessard@205: lbessard@254: self.StoreEDS = wx.CheckBox(id=ID_CREATENODEDIALOGSTOREEDS, laurent@580: label=_('Store EDS'), name='StoreEDS', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) lbessard@254: self.StoreEDS.SetValue(False) lbessard@254: self.StoreEDS.Hide() lbessard@254: lbessard@254: self.staticText7 = wx.StaticText(id=ID_CREATENODEDIALOGSTATICTEXT7, laurent@580: label=_('Description:'), name='staticText7', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.Description = wx.TextCtrl(id=ID_CREATENODEDIALOGDESCRIPTION, lbessard@254: name='Description', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 24), style=0, value='') lbessard@254: lbessard@259: self.Spacer = wx.Panel(id=ID_CREATENODEDIALOGSPACER, lbessard@254: name='Spacer', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) lbessard@254: etisserant@486: self.ButtonSizer = self.CreateButtonSizer(buttons) lbessard@254: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: etisserant@486: def __init__(self, parent,buttons=wx.OK|wx.CANCEL): etisserant@486: self._init_ctrls(parent,buttons) lbessard@254: lbessard@299: self.staticText3.Hide() lbessard@299: self.NodeID.Hide() lbessard@299: lbessard@205: self.NodeID.SetValue("0x00") laurent@580: for node_type in GetNodeTypes(): laurent@580: self.Type.Append(_(node_type)) laurent@580: self.Type.SetStringSelection(_("slave")) lbessard@205: self.Description.SetValue("") lbessard@205: self.ListProfile = {"None" : ""} laurent@580: self.Profile.Append(_("None")) lbessard@258: self.Directory = os.path.join(ScriptDirectory, "config") lbessard@205: listfiles = os.listdir(self.Directory) lbessard@205: listfiles.sort() lbessard@205: for item in listfiles: lbessard@205: name, extend = os.path.splitext(item) lbessard@205: if os.path.isfile(os.path.join(self.Directory, item)) and extend == ".prf" and name != "DS-302": lbessard@205: self.ListProfile[name] = os.path.join(self.Directory, item) lbessard@205: self.Profile.Append(name) laurent@580: self.Profile.Append(_("Other")) laurent@580: self.Profile.SetStringSelection(_("None")) lbessard@276: self.NodeName.SetFocus() lbessard@205: lbessard@205: def OnOK(self, event): lbessard@276: name = self.NodeName.GetValue() lbessard@205: message = "" lbessard@205: if name != "": lbessard@205: good = not name[0].isdigit() lbessard@205: for item in name.split("_"): lbessard@205: good &= item.isalnum() lbessard@205: if not good: laurent@580: message = _("Node name can't be undefined or start with a digit and must be composed of alphanumerical characters or underscore!") lbessard@205: if message != "": lbessard@205: try: lbessard@205: nodeid = int(self.NodeID.GetValue(), 16) lbessard@205: except: laurent@580: message = _("Node ID must be integer!") lbessard@205: if message != "": laurent@580: message = wx.MessageDialog(self, message, _("ERROR"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@276: self.NodeName.SetFocus() lbessard@205: else: lbessard@254: self.EndModal(wx.ID_OK) lbessard@205: lbessard@205: def GetValues(self): lbessard@276: name = self.NodeName.GetValue() lbessard@205: nodeid = 0 lbessard@205: if self.NodeID.GetValue() != "": lbessard@205: nodeid = int(self.NodeID.GetValue(), 16) laurent@580: type = NODE_TYPES_DICT[self.Type.GetStringSelection()] lbessard@205: description = self.Description.GetValue() lbessard@205: return name, nodeid, type, description lbessard@205: lbessard@205: def GetProfile(self): lbessard@205: name = self.Profile.GetStringSelection() laurent@580: if name == _("None"): laurent@580: name = "None" lbessard@205: return name, self.ListProfile[name] lbessard@205: lbessard@205: def GetNMTManagement(self): lbessard@205: if self.NMT_None.GetValue(): lbessard@205: return "None" lbessard@205: elif self.NMT_NodeGuarding.GetValue(): lbessard@205: return "NodeGuarding" lbessard@205: elif self.NMT_Heartbeat.GetValue(): lbessard@205: return "Heartbeat" lbessard@205: return None lbessard@205: lbessard@205: def GetOptions(self): lbessard@205: options = [] lbessard@205: if self.DS302.GetValue(): lbessard@205: options.append("DS302") lbessard@205: if self.GenSYNC.GetValue(): lbessard@205: options.append("GenSYNC") lbessard@205: if self.Emergency.GetValue(): lbessard@205: options.append("Emergency") lbessard@205: if self.SaveConfig.GetValue(): lbessard@205: options.append("SaveConfig") lbessard@254: if self.StoreEDS.GetValue(): lbessard@254: options.append("StoreEDS") lbessard@205: return options lbessard@205: lbessard@205: def OnProfileChoice(self, event): laurent@580: if self.Profile.GetStringSelection() == _("Other"): laurent@580: dialog = wx.FileDialog(self, _("Choose a file"), self.Directory, "", _("OD Profile files (*.prf)|*.prf|All files|*.*"), wx.OPEN|wx.CHANGE_DIR) lbessard@205: dialog.ShowModal() lbessard@205: filepath = dialog.GetPath() lbessard@205: dialog.Destroy() lbessard@205: if os.path.isfile(filepath): lbessard@205: name = os.path.splitext(os.path.basename(filepath))[0] lbessard@205: self.ListProfile[name] = filepath lbessard@205: length = self.Profile.GetCount() lbessard@205: self.Profile.Insert(name, length - 2) lbessard@205: self.Profile.SetStringSelection(name) lbessard@205: else: laurent@580: self.Profile.SetStringSelection(_("None")) lbessard@205: event.Skip() lbessard@205: lbessard@205: lbessard@205: #------------------------------------------------------------------------------- lbessard@205: # ADD Slave to NodeList Dialog lbessard@205: #------------------------------------------------------------------------------- lbessard@205: lbessard@254: [ID_ADDSLAVEDIALOG, ID_ADDSLAVEDIALOGSLAVENAME, lbessard@254: ID_ADDSLAVEDIALOGSLAVENODEID, ID_ADDSLAVEDIALOGEDSFILE, lbessard@254: ID_ADDSLAVEDIALOGIMPORTEDS, ID_ADDSLAVEDIALOGSTATICTEXT1, lbessard@254: ID_ADDSLAVEDIALOGSTATICTEXT2, ID_ADDSLAVEDIALOGSTATICTEXT3, lbessard@254: ] = [wx.NewId() for _init_ctrls in range(8)] lbessard@205: lbessard@205: class AddSlaveDialog(wx.Dialog): lbessard@205: def _init_coll_flexGridSizer1_Items(self, parent): lbessard@254: parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@254: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@254: lbessard@254: def _init_coll_flexGridSizer1_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@254: lbessard@254: def _init_coll_MainSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.staticText1, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.SlaveName, 0, border=10, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.staticText2, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.SlaveNodeID, 0, border=10, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddWindow(self.staticText3, 0, border=5, flag=wx.GROW|wx.BOTTOM) lbessard@254: parent.AddSizer(self.BottomSizer, 0, border=0, flag=wx.GROW) lbessard@254: lbessard@254: def _init_coll_BottomSizer_Items(self, parent): lbessard@254: parent.AddWindow(self.EDSFile, 0, border=4, flag=wx.GROW|wx.TOP|wx.BOTTOM) lbessard@254: parent.AddWindow(self.ImportEDS, 0, border=0, flag=0) lbessard@254: lbessard@254: def _init_coll_BottomSizer_Growables(self, parent): lbessard@254: parent.AddGrowableCol(0) lbessard@254: parent.AddGrowableRow(0) lbessard@205: lbessard@205: def _init_sizers(self): lbessard@254: self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) lbessard@254: self.MainSizer = wx.BoxSizer(wx.VERTICAL) lbessard@254: self.BottomSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=0) lbessard@254: lbessard@205: self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) lbessard@254: self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) lbessard@254: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@254: self._init_coll_BottomSizer_Items(self.BottomSizer) lbessard@254: self._init_coll_BottomSizer_Growables(self.BottomSizer) lbessard@254: lbessard@205: self.SetSizer(self.flexGridSizer1) lbessard@205: lbessard@205: def _init_ctrls(self, prnt): lbessard@254: wx.Dialog.__init__(self, id=ID_ADDSLAVEDIALOG, lbessard@205: name='AddSlaveDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@254: size=wx.Size(300, 250), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, laurent@580: title=_('Add a slave to nodelist')) lbessard@205: self.SetClientSize(wx.Size(300, 250)) lbessard@205: lbessard@254: self.staticText1 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT1, laurent@580: label=_('Slave Name:'), name='staticText1', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.SlaveName = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENAME, lbessard@254: name='SlaveName', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 24), style=0) lbessard@254: lbessard@254: self.staticText2 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT2, laurent@580: label=_('Slave Node ID:'), name='staticText2', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: lbessard@254: self.SlaveNodeID = wx.TextCtrl(id=ID_ADDSLAVEDIALOGSLAVENODEID, lbessard@254: name='SlaveName', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(0, 24), style=wx.ALIGN_RIGHT) lbessard@254: lbessard@254: self.staticText3 = wx.StaticText(id=ID_ADDSLAVEDIALOGSTATICTEXT3, laurent@580: label=_('EDS File:'), name='staticText3', parent=self, lbessard@254: pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) lbessard@254: laurent@585: self.EDSFile = wx.ComboBox(id=ID_ADDSLAVEDIALOGEDSFILE, lbessard@254: name='EDSFile', parent=self, pos=wx.Point(0, 0), laurent@585: size=wx.Size(0, 28), style=wx.CB_READONLY) lbessard@254: laurent@580: self.ImportEDS = wx.Button(id=ID_ADDSLAVEDIALOGIMPORTEDS, label=_('Import EDS'), lbessard@254: name='ImportEDS', parent=self, pos=wx.Point(0, 0), lbessard@205: size=wx.Size(100, 32), style=0) lbessard@205: self.ImportEDS.Bind(wx.EVT_BUTTON, self.OnImportEDSButton, lbessard@254: id=ID_ADDSLAVEDIALOGIMPORTEDS) lbessard@254: lbessard@254: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@254: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) lbessard@254: lbessard@205: self._init_sizers() lbessard@205: lbessard@205: def __init__(self, parent): lbessard@205: self._init_ctrls(parent) lbessard@205: lbessard@205: self.SlaveNodeID.SetValue("0x00") lbessard@254: lbessard@205: def OnOK(self, event): lbessard@205: error = [] lbessard@205: if self.SlaveName.GetValue() == "": laurent@580: error.append(_("Slave Name")) lbessard@205: if self.SlaveNodeID.GetValue() == "": laurent@580: error.append(_("Slave Node ID")) lbessard@205: if self.EDSFile.GetStringSelection() == "": laurent@580: error.append(_("EDS File")) lbessard@205: if len(error) > 0: lbessard@205: text = "" lbessard@205: for i, item in enumerate(error): lbessard@205: if i == 0: lbessard@205: text += item lbessard@205: elif i == len(error) - 1: laurent@580: text += _(" and %s")%item lbessard@205: else: laurent@580: text += _(", %s")%item laurent@580: message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: else: lbessard@205: try: lbessard@205: nodeid = self.SlaveNodeID.GetValue() lbessard@205: if nodeid.find("x") != -1: lbessard@205: nodeid = int(nodeid, 16) lbessard@205: else: lbessard@205: nodeid = int(nodeid) lbessard@205: except: laurent@580: message = wx.MessageDialog(self, _("Slave Node ID must be a value in decimal or hexadecimal!"), _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: return lbessard@205: if not 0 <= nodeid <= 127: laurent@580: message = wx.MessageDialog(self, _("Slave Node ID must be between 0 and 127!"), _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() Laurent@748: elif nodeid == self.NodeList.GetMasterNodeID() or nodeid in self.NodeList.GetSlaveIDs(): laurent@580: message = wx.MessageDialog(self, _("A Node with this ID already exist in the network!"), _("Error"), wx.OK|wx.ICON_ERROR) lbessard@205: message.ShowModal() lbessard@205: message.Destroy() lbessard@205: else: lbessard@254: self.EndModal(wx.ID_OK) lbessard@205: lbessard@205: def OnImportEDSButton(self, event): etisserant@486: dialog = wx.FileDialog(self, laurent@580: _("Choose an EDS file"), Laurent@757: os.path.expanduser("~"), etisserant@486: "", laurent@580: _("EDS files (*.eds)|*.eds|All files|*.*"), etisserant@486: wx.OPEN) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: filepath = dialog.GetPath() Laurent@740: else: Laurent@740: filepath = "" lbessard@205: dialog.Destroy() Laurent@740: if os.path.isfile(filepath): Laurent@740: result, question = self.NodeList.ImportEDSFile(filepath) Laurent@740: if result is not None and question: Laurent@740: dialog = wx.MessageDialog(self, _("%s\nWould you like to replace it ?")%result, _("Question"), wx.YES_NO|wx.ICON_QUESTION) Laurent@740: if dialog.ShowModal() == wx.ID_YES: Laurent@766: result, question = self.NodeList.ImportEDSFile(filepath, True) Laurent@740: dialog.Destroy() Laurent@740: if result is not None and not question: Laurent@740: dialog = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) Laurent@740: dialog.ShowModal() Laurent@740: dialog.Destroy() lbessard@205: self.RefreshEDSFile() lbessard@205: event.Skip() lbessard@205: lbessard@205: def RefreshEDSFile(self): lbessard@205: selection = self.EDSFile.GetStringSelection() lbessard@205: self.EDSFile.Clear() lbessard@205: for option in self.NodeList.EDSNodes.keys(): lbessard@205: self.EDSFile.Append(option) lbessard@254: if self.EDSFile.FindString(selection) != wx.NOT_FOUND: lbessard@205: self.EDSFile.SetStringSelection(selection) lbessard@205: lbessard@205: def SetNodeList(self, nodelist): lbessard@205: self.NodeList = nodelist lbessard@205: self.RefreshEDSFile() lbessard@205: lbessard@205: def GetValues(self): lbessard@205: values = {} lbessard@205: values["slaveName"] = self.SlaveName.GetValue() lbessard@205: nodeid = self.SlaveNodeID.GetValue() lbessard@205: if nodeid.find("x") != -1: lbessard@205: values["slaveNodeID"] = int(nodeid, 16) lbessard@205: else: lbessard@205: values["slaveNodeID"] = int(nodeid) lbessard@205: values["edsFile"] = self.EDSFile.GetStringSelection() lbessard@205: return values lbessard@327: lbessard@327: #------------------------------------------------------------------------------- lbessard@327: # Editing DCF Entry Dialog lbessard@327: #------------------------------------------------------------------------------- lbessard@327: laurent@580: def DCFEntryTableColnames(): laurent@580: _ = lambda x : x laurent@580: return [_("Index"), _("Subindex"), _("Size"), _("Value")] laurent@580: lbessard@327: class DCFEntryValuesTable(wx.grid.PyGridTableBase): lbessard@327: lbessard@327: """ lbessard@327: A custom wxGrid Table using user supplied data lbessard@327: """ lbessard@327: def __init__(self, parent, data, colnames): lbessard@327: # The base class must be initialized *first* lbessard@327: wx.grid.PyGridTableBase.__init__(self) lbessard@327: self.data = data lbessard@327: self.colnames = colnames lbessard@327: self.Parent = parent lbessard@327: # XXX laurent@580: # we need to store the row length and col length to lbessard@327: # see if the table has changed size lbessard@327: self._rows = self.GetNumberRows() lbessard@327: self._cols = self.GetNumberCols() lbessard@327: lbessard@327: def GetNumberCols(self): lbessard@327: return len(self.colnames) lbessard@327: lbessard@327: def GetNumberRows(self): lbessard@327: return len(self.data) lbessard@327: laurent@580: def GetColLabelValue(self, col, translate=True): lbessard@327: if col < len(self.colnames): laurent@580: if translate: laurent@580: return _(self.colnames[col]) lbessard@327: return self.colnames[col] lbessard@327: laurent@580: def GetRowLabelValues(self, row, translate=True): lbessard@327: return row lbessard@327: lbessard@327: def GetValue(self, row, col): lbessard@327: if row < self.GetNumberRows(): laurent@580: return str(self.data[row].get(self.GetColLabelValue(col, False), "")) lbessard@327: lbessard@327: def GetEditor(self, row, col): lbessard@327: if row < self.GetNumberRows(): laurent@580: return self.editors[row].get(self.GetColLabelValue(col, False), "") lbessard@327: lbessard@327: def GetValueByName(self, row, colname): lbessard@327: return self.data[row].get(colname) lbessard@327: lbessard@327: def SetValue(self, row, col, value): lbessard@327: if col < len(self.colnames): laurent@580: self.data[row][self.GetColLabelValue(col, False)] = value lbessard@327: lbessard@327: def ResetView(self, grid): lbessard@327: """ lbessard@327: (wx.grid.Grid) -> Reset the grid view. Call this to lbessard@327: update the grid if rows and columns have been added or deleted lbessard@327: """ lbessard@327: grid.BeginBatch() lbessard@327: for current, new, delmsg, addmsg in [ lbessard@327: (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), lbessard@327: (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), lbessard@327: ]: lbessard@327: if new < current: lbessard@327: msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) lbessard@327: grid.ProcessTableMessage(msg) lbessard@327: elif new > current: lbessard@327: msg = wx.grid.GridTableMessage(self,addmsg,new-current) lbessard@327: grid.ProcessTableMessage(msg) lbessard@327: self.UpdateValues(grid) lbessard@327: grid.EndBatch() lbessard@327: lbessard@327: self._rows = self.GetNumberRows() lbessard@327: self._cols = self.GetNumberCols() lbessard@327: # update the column rendering scheme lbessard@327: self._updateColAttrs(grid) lbessard@327: lbessard@327: # update the scrollbars and the displayed part of the grid lbessard@327: grid.AdjustScrollbars() lbessard@327: grid.ForceRefresh() lbessard@327: lbessard@327: lbessard@327: def UpdateValues(self, grid): lbessard@327: """Update all displayed values""" lbessard@327: # This sends an event to the grid table to update all of the values lbessard@327: msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) lbessard@327: grid.ProcessTableMessage(msg) lbessard@327: lbessard@327: def _updateColAttrs(self, grid): lbessard@327: """ lbessard@327: wx.grid.Grid -> update the column attributes to add the lbessard@327: appropriate renderer given the column name. lbessard@327: lbessard@327: Otherwise default to the default renderer. lbessard@327: """ lbessard@327: lbessard@327: for row in range(self.GetNumberRows()): lbessard@327: for col in range(self.GetNumberCols()): lbessard@327: editor = wx.grid.GridCellTextEditor() lbessard@327: renderer = wx.grid.GridCellStringRenderer() Laurent@757: Laurent@757: grid.SetReadOnly(row, col, self.Parent.Editable) lbessard@327: grid.SetCellEditor(row, col, editor) lbessard@327: grid.SetCellRenderer(row, col, renderer) lbessard@327: lbessard@327: grid.SetCellBackgroundColour(row, col, wx.WHITE) lbessard@327: lbessard@327: def SetData(self, data): lbessard@327: self.data = data lbessard@327: lbessard@327: def AppendRow(self, row_content): lbessard@327: self.data.append(row_content) lbessard@327: lbessard@327: def Empty(self): lbessard@327: self.data = [] lbessard@327: self.editors = [] lbessard@327: lbessard@327: [ID_DCFENTRYVALUESDIALOG, ID_DCFENTRYVALUESDIALOGVALUESGRID, lbessard@327: ID_DCFENTRYVALUESDIALOGADDBUTTON, ID_DCFENTRYVALUESDIALOGDELETEBUTTON, lbessard@327: ID_DCFENTRYVALUESDIALOGUPBUTTON, ID_DCFENTRYVALUESDIALOGDOWNBUTTON, lbessard@327: ID_VARIABLEEDITORPANELSTATICTEXT1, lbessard@327: ] = [wx.NewId() for _init_ctrls in range(7)] lbessard@327: lbessard@327: class DCFEntryValuesDialog(wx.Dialog): lbessard@327: lbessard@327: if wx.VERSION < (2, 6, 0): lbessard@327: def Bind(self, event, function, id = None): lbessard@327: if id is not None: lbessard@327: event(self, id, function) lbessard@327: else: lbessard@327: event(self, function) lbessard@327: lbessard@327: def _init_coll_MainSizer_Items(self, parent): lbessard@327: parent.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@327: parent.AddWindow(self.ValuesGrid, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) lbessard@327: parent.AddSizer(self.ButtonPanelSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT) lbessard@327: parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) lbessard@327: lbessard@327: def _init_coll_MainSizer_Growables(self, parent): lbessard@327: parent.AddGrowableCol(0) lbessard@327: parent.AddGrowableRow(1) lbessard@327: lbessard@327: def _init_coll_ButtonPanelSizer_Items(self, parent): lbessard@327: parent.AddWindow(self.UpButton, 0, border=5, flag=wx.ALL) lbessard@327: parent.AddWindow(self.AddButton, 0, border=5, flag=wx.ALL) lbessard@327: parent.AddWindow(self.DownButton, 0, border=5, flag=wx.ALL) lbessard@327: parent.AddWindow(self.DeleteButton, 0, border=5, flag=wx.ALL) lbessard@327: lbessard@327: def _init_sizers(self): lbessard@327: self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0) lbessard@327: self.ButtonPanelSizer = wx.BoxSizer(wx.HORIZONTAL) lbessard@327: lbessard@327: self._init_coll_MainSizer_Items(self.MainSizer) lbessard@327: self._init_coll_MainSizer_Growables(self.MainSizer) lbessard@327: self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer) lbessard@327: lbessard@327: self.SetSizer(self.MainSizer) lbessard@327: lbessard@327: def _init_ctrls(self, prnt): lbessard@327: wx.Dialog.__init__(self, id=ID_DCFENTRYVALUESDIALOG, lbessard@327: name='DCFEntryValuesDialog', parent=prnt, pos=wx.Point(376, 223), lbessard@327: size=wx.Size(400, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, laurent@580: title=_('Edit DCF Entry Values')) lbessard@327: self.SetClientSize(wx.Size(400, 300)) lbessard@327: lbessard@327: self.staticText1 = wx.StaticText(id=ID_VARIABLEEDITORPANELSTATICTEXT1, laurent@580: label=_('Entry Values:'), name='staticText1', parent=self, lbessard@327: pos=wx.Point(0, 0), size=wx.Size(95, 17), style=0) lbessard@327: lbessard@327: self.ValuesGrid = wx.grid.Grid(id=ID_DCFENTRYVALUESDIALOGVALUESGRID, lbessard@327: name='ValuesGrid', parent=self, pos=wx.Point(0, 0), lbessard@327: size=wx.Size(0, 150), style=wx.VSCROLL) lbessard@327: self.ValuesGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, lbessard@327: 'Sans')) lbessard@327: self.ValuesGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, lbessard@327: False, 'Sans')) lbessard@327: self.ValuesGrid.SetRowLabelSize(0) lbessard@327: self.ValuesGrid.SetSelectionBackground(wx.WHITE) lbessard@327: self.ValuesGrid.SetSelectionForeground(wx.BLACK) lbessard@327: if wx.VERSION >= (2, 6, 0): lbessard@327: self.ValuesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnValuesGridCellChange) lbessard@328: self.ValuesGrid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnValuesGridSelectCell) lbessard@327: else: lbessard@327: wx.grid.EVT_GRID_CELL_CHANGE(self.ValuesGrid, self.OnValuesGridCellChange) lbessard@328: wx.grid.EVT_GRID_SELECT_CELL(self.ValuesGrid, self.OnValuesGridSelectCell) lbessard@327: laurent@580: self.AddButton = wx.Button(id=ID_DCFENTRYVALUESDIALOGADDBUTTON, label=_('Add'), lbessard@327: name='AddButton', parent=self, pos=wx.Point(0, 0), lbessard@327: size=wx.Size(72, 32), style=0) lbessard@327: self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_DCFENTRYVALUESDIALOGADDBUTTON) lbessard@327: laurent@580: self.DeleteButton = wx.Button(id=ID_DCFENTRYVALUESDIALOGDELETEBUTTON, label=_('Delete'), lbessard@327: name='DeleteButton', parent=self, pos=wx.Point(0, 0), lbessard@327: size=wx.Size(72, 32), style=0) lbessard@327: self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_DCFENTRYVALUESDIALOGDELETEBUTTON) lbessard@327: lbessard@327: self.UpButton = wx.Button(id=ID_DCFENTRYVALUESDIALOGUPBUTTON, label='^', lbessard@327: name='UpButton', parent=self, pos=wx.Point(0, 0), lbessard@327: size=wx.Size(32, 32), style=0) lbessard@327: self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_DCFENTRYVALUESDIALOGUPBUTTON) lbessard@327: lbessard@327: self.DownButton = wx.Button(id=ID_DCFENTRYVALUESDIALOGDOWNBUTTON, label='v', lbessard@327: name='DownButton', parent=self, pos=wx.Point(0, 0), lbessard@327: size=wx.Size(32, 32), style=0) lbessard@327: self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_DCFENTRYVALUESDIALOGDOWNBUTTON) lbessard@327: lbessard@327: self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) lbessard@327: lbessard@327: self._init_sizers() lbessard@327: Laurent@757: def __init__(self, parent, editable=True): lbessard@327: self._init_ctrls(parent) lbessard@327: lbessard@327: self.Values = [] lbessard@327: self.DefaultValue = {"Index" : 0, "Subindex" : 0, "Size" : 1, "Value" : 0} Laurent@757: self.Editable = editable lbessard@327: laurent@580: self.Table = DCFEntryValuesTable(self, [], DCFEntryTableColnames()) lbessard@327: self.ValuesGrid.SetTable(self.Table) lbessard@327: lbessard@327: def OnValuesGridCellChange(self, event): lbessard@327: row, col = event.GetRow(), event.GetCol() lbessard@327: colname = self.Table.GetColLabelValue(col) lbessard@327: value = self.Table.GetValue(row, col) lbessard@327: try: lbessard@327: self.Values[row][colname] = int(value, 16) lbessard@327: except: laurent@580: message = wx.MessageDialog(self, _("\"%s\" is not a valid value!")%value, _("Error"), wx.OK|wx.ICON_ERROR) lbessard@327: message.ShowModal() lbessard@327: message.Destroy() lbessard@359: wx.CallAfter(self.RefreshValues) lbessard@359: event.Skip() lbessard@327: lbessard@328: def OnValuesGridSelectCell(self, event): lbessard@328: wx.CallAfter(self.RefreshButtons) lbessard@328: event.Skip() lbessard@328: lbessard@328: def RefreshButtons(self): lbessard@328: row = self.ValuesGrid.GetGridCursorRow() lbessard@328: length = len(self.Table.data) Laurent@757: self.AddButton.Enable(self.Editable) Laurent@757: self.DeleteButton.Enable(self.Editable and length > 0) Laurent@757: self.UpButton.Enable(self.Editable and row > 0) Laurent@757: self.DownButton.Enable(self.Editable and row < length - 1) lbessard@328: lbessard@327: def OnAddButton(self, event): lbessard@327: new_row = self.DefaultValue.copy() lbessard@327: self.Values.append(new_row) lbessard@327: self.RefreshValues() lbessard@327: event.Skip() lbessard@327: lbessard@327: def OnDeleteButton(self, event): lbessard@328: row = self.ValuesGrid.GetGridCursorRow() lbessard@328: self.Values.pop(row) lbessard@327: self.RefreshValues() lbessard@327: event.Skip() lbessard@327: lbessard@327: def OnUpButton(self, event): lbessard@327: self.MoveValue(self.ValuesGrid.GetGridCursorRow(), -1) lbessard@327: event.Skip() lbessard@327: lbessard@327: def OnDownButton(self, event): lbessard@327: self.MoveValue(self.ValuesGrid.GetGridCursorRow(), 1) lbessard@327: event.Skip() lbessard@327: lbessard@327: def MoveValue(self, value_index, move): lbessard@327: new_index = max(0, min(value_index + move, len(self.Values) - 1)) lbessard@327: if new_index != value_index: lbessard@327: self.Values.insert(new_index, self.Values.pop(value_index)) lbessard@328: col = self.ValuesGrid.GetGridCursorCol() lbessard@327: self.RefreshValues() lbessard@328: self.ValuesGrid.SetGridCursor(new_index, col) lbessard@328: self.RefreshButtons() lbessard@327: else: lbessard@327: self.RefreshValues() lbessard@327: lbessard@327: def SetValues(self, values): lbessard@327: self.Values = [] lbessard@327: if values != "": lbessard@327: data = values[4:] lbessard@327: current = 0 lbessard@327: for i in xrange(BE_to_LE(values[:4])): lbessard@327: value = {} lbessard@327: value["Index"] = BE_to_LE(data[current:current+2]) lbessard@327: value["Subindex"] = BE_to_LE(data[current+2:current+3]) lbessard@327: size = BE_to_LE(data[current+3:current+7]) lbessard@327: value["Size"] = size lbessard@327: value["Value"] = BE_to_LE(data[current+7:current+7+size]) lbessard@327: current += 7 + size lbessard@327: self.Values.append(value) lbessard@327: self.RefreshValues() lbessard@327: lbessard@327: def GetValues(self): lbessard@500: if len(self.Values) > 0: lbessard@500: value = LE_to_BE(len(self.Values), 4) lbessard@500: for row in self.Values: lbessard@500: value += LE_to_BE(row["Index"], 2) lbessard@500: value += LE_to_BE(row["Subindex"], 1) lbessard@500: value += LE_to_BE(row["Size"], 4) lbessard@500: value += LE_to_BE(row["Value"], row["Size"]) lbessard@500: return value lbessard@500: return "" lbessard@327: lbessard@327: def RefreshValues(self): lbessard@327: if len(self.Table.data) > 0: lbessard@328: self.ValuesGrid.SetGridCursor(0, 0) lbessard@327: data = [] lbessard@327: for value in self.Values: lbessard@327: row = {} lbessard@327: row["Index"] = "%04X"%value["Index"] lbessard@327: row["Subindex"] = "%02X"%value["Subindex"] lbessard@327: row["Size"] = "%08X"%value["Size"] lbessard@327: row["Value"] = ("%0"+"%d"%(value["Size"] * 2)+"X")%value["Value"] lbessard@327: data.append(row) lbessard@327: self.Table.SetData(data) lbessard@327: self.Table.ResetView(self.ValuesGrid) lbessard@328: self.RefreshButtons() lbessard@328: