Laurent@745: from types import * Laurent@745: smarteh-dev@715: import wx smarteh-dev@715: smarteh-dev@715: from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes smarteh-dev@715: from commondialogs import * smarteh-dev@715: smarteh-dev@715: class NodeEditorTemplate: smarteh-dev@715: smarteh-dev@715: EDITMENU_ID = None smarteh-dev@715: smarteh-dev@715: def __init__(self, manager, frame, mode_solo): smarteh-dev@715: self.Manager = manager smarteh-dev@715: self.Frame = frame smarteh-dev@715: self.ModeSolo = mode_solo smarteh-dev@715: smarteh-dev@715: self.BusId = None smarteh-dev@715: self.Closing = False smarteh-dev@715: smarteh-dev@715: def SetBusId(self, bus_id): smarteh-dev@715: self.BusId = bus_id smarteh-dev@715: smarteh-dev@715: def GetBusId(self): smarteh-dev@715: return self.BusId smarteh-dev@715: smarteh-dev@715: def IsClosing(self): smarteh-dev@715: return self.Closing smarteh-dev@715: smarteh-dev@715: def OnAddSDOServerMenu(self, event): smarteh-dev@715: self.Manager.AddSDOServerToCurrent() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: smarteh-dev@715: def OnAddSDOClientMenu(self, event): smarteh-dev@715: self.Manager.AddSDOClientToCurrent() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: smarteh-dev@715: def OnAddPDOTransmitMenu(self, event): smarteh-dev@715: self.Manager.AddPDOTransmitToCurrent() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: smarteh-dev@715: def OnAddPDOReceiveMenu(self, event): smarteh-dev@715: self.Manager.AddPDOReceiveToCurrent() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: smarteh-dev@715: def OnAddMapVariableMenu(self, event): smarteh-dev@715: self.AddMapVariable() smarteh-dev@715: smarteh-dev@715: def OnAddUserTypeMenu(self, event): smarteh-dev@715: self.AddUserType() smarteh-dev@715: smarteh-dev@715: def OnRefreshMenu(self, event): smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: smarteh-dev@715: def RefreshCurrentIndexList(self): smarteh-dev@715: pass smarteh-dev@715: smarteh-dev@715: def RefreshStatusBar(self): smarteh-dev@715: pass smarteh-dev@715: smarteh-dev@715: def SetStatusBarText(self, selection, manager): smarteh-dev@715: if selection: smarteh-dev@715: index, subIndex = selection smarteh-dev@715: if manager.IsCurrentEntry(index): smarteh-dev@715: self.Frame.HelpBar.SetStatusText(_("Index: 0x%04X")%index, 0) smarteh-dev@715: self.Frame.HelpBar.SetStatusText(_("Subindex: 0x%02X")%subIndex, 1) smarteh-dev@715: entryinfos = manager.GetEntryInfos(index) smarteh-dev@715: name = entryinfos["name"] smarteh-dev@715: category = _("Optional") smarteh-dev@715: if entryinfos["need"]: smarteh-dev@715: category = _("Mandatory") smarteh-dev@715: struct = "VAR" smarteh-dev@715: number = "" smarteh-dev@715: if entryinfos["struct"] & OD_IdenticalIndexes: smarteh-dev@715: number = _(" possibly defined %d times")%entryinfos["nbmax"] smarteh-dev@715: if entryinfos["struct"] & OD_IdenticalSubindexes: smarteh-dev@715: struct = "REC" smarteh-dev@715: elif entryinfos["struct"] & OD_MultipleSubindexes: smarteh-dev@715: struct = "ARRAY" smarteh-dev@715: text = _("%s: %s entry of struct %s%s.")%(name,category,struct,number) smarteh-dev@715: self.Frame.HelpBar.SetStatusText(text, 2) smarteh-dev@715: else: smarteh-dev@715: for i in xrange(3): smarteh-dev@715: self.Frame.HelpBar.SetStatusText("", i) smarteh-dev@715: else: smarteh-dev@715: for i in xrange(3): smarteh-dev@715: self.Frame.HelpBar.SetStatusText("", i) smarteh-dev@715: smarteh-dev@715: def RefreshProfileMenu(self): smarteh-dev@715: if self.EDITMENU_ID is not None: smarteh-dev@715: profile = self.Manager.GetCurrentProfileName() smarteh-dev@715: edititem = self.Frame.EditMenu.FindItemById(self.EDITMENU_ID) smarteh-dev@715: if edititem: smarteh-dev@715: length = self.Frame.AddMenu.GetMenuItemCount() smarteh-dev@715: for i in xrange(length-6): smarteh-dev@715: additem = self.Frame.AddMenu.FindItemByPosition(6) smarteh-dev@715: self.Frame.AddMenu.Delete(additem.GetId()) smarteh-dev@715: if profile not in ("None", "DS-301"): smarteh-dev@715: edititem.SetText(_("%s Profile")%profile) smarteh-dev@715: edititem.Enable(True) smarteh-dev@715: self.Frame.AddMenu.AppendSeparator() smarteh-dev@715: for text, indexes in self.Manager.GetCurrentSpecificMenu(): smarteh-dev@715: new_id = wx.NewId() smarteh-dev@715: self.Frame.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) smarteh-dev@715: self.Frame.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) smarteh-dev@715: else: smarteh-dev@715: edititem.SetText(_("Other Profile")) smarteh-dev@715: edititem.Enable(False) smarteh-dev@715: smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: # Buffer Functions smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: smarteh-dev@715: def RefreshBufferState(self): smarteh-dev@715: pass smarteh-dev@715: smarteh-dev@715: def OnUndoMenu(self, event): smarteh-dev@715: self.Manager.LoadCurrentPrevious() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: smarteh-dev@715: def OnRedoMenu(self, event): smarteh-dev@715: self.Manager.LoadCurrentNext() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: # Editing Profiles functions smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: smarteh-dev@715: def OnCommunicationMenu(self, event): smarteh-dev@715: dictionary,current = self.Manager.GetCurrentCommunicationLists() smarteh-dev@715: self.EditProfile(_("Edit DS-301 Profile"), dictionary, current) smarteh-dev@715: smarteh-dev@715: def OnOtherCommunicationMenu(self, event): smarteh-dev@715: dictionary,current = self.Manager.GetCurrentDS302Lists() smarteh-dev@715: self.EditProfile(_("Edit DS-302 Profile"), dictionary, current) smarteh-dev@715: smarteh-dev@715: def OnEditProfileMenu(self, event): smarteh-dev@715: title = _("Edit %s Profile") % self.Manager.GetCurrentProfileName() smarteh-dev@715: dictionary,current = self.Manager.GetCurrentProfileLists() smarteh-dev@715: self.EditProfile(title, dictionary, current) smarteh-dev@715: smarteh-dev@715: def EditProfile(self, title, dictionary, current): smarteh-dev@715: dialog = CommunicationDialog(self.Frame) smarteh-dev@715: dialog.SetTitle(title) smarteh-dev@715: dialog.SetIndexDictionary(dictionary) smarteh-dev@715: dialog.SetCurrentList(current) smarteh-dev@715: dialog.RefreshLists() smarteh-dev@715: if dialog.ShowModal() == wx.ID_OK: smarteh-dev@715: new_profile = dialog.GetCurrentList() smarteh-dev@715: addinglist = [] smarteh-dev@715: removinglist = [] smarteh-dev@715: for index in new_profile: smarteh-dev@715: if index not in current: smarteh-dev@715: addinglist.append(index) smarteh-dev@715: for index in current: smarteh-dev@715: if index not in new_profile: smarteh-dev@715: removinglist.append(index) smarteh-dev@715: self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) smarteh-dev@715: self.Manager.BufferCurrentNode() smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: smarteh-dev@715: dialog.Destroy() smarteh-dev@715: smarteh-dev@715: def GetProfileCallBack(self, text): smarteh-dev@715: def ProfileCallBack(event): smarteh-dev@715: self.Manager.AddSpecificEntryToCurrent(text) smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: return ProfileCallBack smarteh-dev@715: smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: # Edit Node informations function smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: smarteh-dev@715: def OnNodeInfosMenu(self, event): smarteh-dev@715: dialog = NodeInfosDialog(self.Frame) smarteh-dev@715: name, id, type, description = self.Manager.GetCurrentNodeInfos() smarteh-dev@715: defaultstringsize = self.Manager.GetCurrentNodeDefaultStringSize() smarteh-dev@715: dialog.SetValues(name, id, type, description, defaultstringsize) smarteh-dev@715: if dialog.ShowModal() == wx.ID_OK: smarteh-dev@715: name, id, type, description, defaultstringsize = dialog.GetValues() smarteh-dev@715: self.Manager.SetCurrentNodeInfos(name, id, type, description) smarteh-dev@715: self.Manager.SetCurrentNodeDefaultStringSize(defaultstringsize) smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: self.RefreshProfileMenu() smarteh-dev@715: smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: # Add User Types and Variables smarteh-dev@715: #------------------------------------------------------------------------------- smarteh-dev@715: smarteh-dev@715: def AddMapVariable(self): smarteh-dev@715: index = self.Manager.GetCurrentNextMapIndex() smarteh-dev@715: if index: smarteh-dev@715: dialog = MapVariableDialog(self.Frame) smarteh-dev@715: dialog.SetIndex(index) smarteh-dev@715: if dialog.ShowModal() == wx.ID_OK: smarteh-dev@715: result = self.Manager.AddMapVariableToCurrent(*dialog.GetValues()) smarteh-dev@715: if not isinstance(result, (StringType, UnicodeType)): smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: else: smarteh-dev@715: self.ShowErrorMessage(result) smarteh-dev@715: dialog.Destroy() smarteh-dev@715: else: smarteh-dev@715: self.ShowErrorMessage(_("No map variable index left!")) smarteh-dev@715: smarteh-dev@715: def AddUserType(self): smarteh-dev@715: dialog = UserTypeDialog(self) smarteh-dev@715: dialog.SetTypeList(self.Manager.GetCustomisableTypes()) smarteh-dev@715: if dialog.ShowModal() == wx.ID_OK: smarteh-dev@715: result = self.Manager.AddUserTypeToCurrent(*dialog.GetValues()) smarteh-dev@715: if not isinstance(result, (StringType, UnicodeType)): smarteh-dev@715: self.RefreshBufferState() smarteh-dev@715: self.RefreshCurrentIndexList() smarteh-dev@715: else: smarteh-dev@715: self.ShowErrorMessage(result) smarteh-dev@715: dialog.Destroy() smarteh-dev@715: smarteh-dev@715: def ShowErrorMessage(self, message): smarteh-dev@715: message = wx.MessageDialog(self.Frame, message, _("Error"), wx.OK|wx.ICON_ERROR) smarteh-dev@715: message.ShowModal() smarteh-dev@715: message.Destroy()