etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: # etisserant@0: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@0: #modify it under the terms of the GNU Lesser General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: import wx etisserant@0: etisserant@0: from types import * etisserant@0: import os, re, platform, sys, time, traceback, getopt etisserant@0: etisserant@0: __version__ = "$Revision$" etisserant@0: greg@206: from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes greg@206: etisserant@0: from nodemanager import * lbessard@205: from subindextable import * lbessard@205: from commondialogs import * etisserant@0: from doc_index.DS301_index import * etisserant@0: lbessard@72: try: lbessard@254: import wx.html lbessard@254: lbessard@254: EVT_HTML_URL_CLICK = wx.NewId() lbessard@254: lbessard@254: class HtmlWindowUrlClick(wx.PyEvent): lbessard@72: def __init__(self, linkinfo): lbessard@254: wx.PyEvent.__init__(self) lbessard@254: self.SetEventType(EVT_HTML_URL_CLICK) lbessard@72: self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) lbessard@254: lbessard@254: class UrlClickHtmlWindow(wx.html.HtmlWindow): lbessard@72: """ HTML window that generates and OnLinkClicked event. lbessard@72: lbessard@72: Use this to avoid having to override HTMLWindow lbessard@72: """ lbessard@72: def OnLinkClicked(self, linkinfo): lbessard@254: wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) lbessard@254: lbessard@254: def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): lbessard@254: if event == HtmlWindowUrlClick: lbessard@254: self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) lbessard@254: else: lbessard@254: wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) lbessard@72: lbessard@72: #------------------------------------------------------------------------------- lbessard@72: # Html Frame lbessard@72: #------------------------------------------------------------------------------- lbessard@72: lbessard@254: [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] lbessard@72: lbessard@72: class HtmlFrame(wx.Frame): lbessard@72: def _init_ctrls(self, prnt): lbessard@254: wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', lbessard@72: parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), lbessard@72: style=wx.DEFAULT_FRAME_STYLE, title='') lbessard@273: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) lbessard@72: lbessard@254: self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, lbessard@72: name='HtmlContent', parent=self, pos=wx.Point(0, 0), lbessard@254: size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) lbessard@254: self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) lbessard@72: lbessard@72: def __init__(self, parent, opened): lbessard@72: self._init_ctrls(parent) lbessard@72: self.HtmlFrameOpened = opened lbessard@72: lbessard@72: def SetHtmlCode(self, htmlcode): lbessard@72: self.HtmlContent.SetPage(htmlcode) lbessard@72: lbessard@72: def SetHtmlPage(self, htmlpage): lbessard@72: self.HtmlContent.LoadPage(htmlpage) lbessard@72: lbessard@72: def OnCloseFrame(self, event): lbessard@72: self.HtmlFrameOpened.remove(self.GetTitle()) lbessard@72: event.Skip() lbessard@72: lbessard@72: def OnLinkClick(self, event): lbessard@72: url = event.linkinfo[0] lbessard@72: try: lbessard@72: import webbrowser lbessard@72: except ImportError: lbessard@254: wx.MessageBox('Please point your browser at: %s' % url) lbessard@72: else: lbessard@72: webbrowser.open(url) lbessard@254: lbessard@72: Html_Window = True lbessard@72: except: lbessard@72: Html_Window = False etisserant@0: greg@318: ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] etisserant@0: lbessard@254: [ID_OBJDICTEDIT, ID_OBJDICTEDITFILEOPENED, lbessard@254: ID_OBJDICTEDITHELPBAR, etisserant@0: ] = [wx.NewId() for _init_ctrls in range(3)] etisserant@0: lbessard@254: [ID_OBJDICTEDITADDMENUITEMS0, ID_OBJDICTEDITADDMENUITEMS1, lbessard@254: ID_OBJDICTEDITADDMENUITEMS2, ID_OBJDICTEDITADDMENUITEMS3, lbessard@254: ID_OBJDICTEDITADDMENUITEMS4, ID_OBJDICTEDITADDMENUITEMS5, etisserant@0: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] etisserant@0: lbessard@254: [ID_OBJDICTEDITFILEMENUITEMS0, ID_OBJDICTEDITFILEMENUITEMS1, lbessard@254: ID_OBJDICTEDITFILEMENUITEMS2, ID_OBJDICTEDITFILEMENUITEMS4, lbessard@254: ID_OBJDICTEDITFILEMENUITEMS5, ID_OBJDICTEDITFILEMENUITEMS6, lbessard@254: ID_OBJDICTEDITFILEMENUITEMS7, ID_OBJDICTEDITFILEMENUITEMS8, lbessard@254: ID_OBJDICTEDITFILEMENUITEMS9, lbessard@182: ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] etisserant@0: lbessard@254: [ID_OBJDICTEDITEDITMENUITEMS0, ID_OBJDICTEDITEDITMENUITEMS1, lbessard@254: ID_OBJDICTEDITEDITMENUITEMS2, ID_OBJDICTEDITEDITMENUITEMS4, lbessard@254: ID_OBJDICTEDITEDITMENUITEMS6, ID_OBJDICTEDITEDITMENUITEMS7, lbessard@254: ID_OBJDICTEDITEDITMENUITEMS8, etisserant@0: ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] etisserant@0: lbessard@254: [ID_OBJDICTEDITHELPMENUITEMS0, ID_OBJDICTEDITHELPMENUITEMS1, lbessard@254: ID_OBJDICTEDITHELPMENUITEMS2, etisserant@0: ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] etisserant@0: etisserant@0: class objdictedit(wx.Frame): etisserant@0: def _init_coll_menuBar1_Menus(self, parent): etisserant@0: parent.Append(menu=self.FileMenu, title='File') etisserant@0: parent.Append(menu=self.EditMenu, title='Edit') etisserant@0: parent.Append(menu=self.AddMenu, title='Add') etisserant@0: parent.Append(menu=self.HelpMenu, title='Help') etisserant@0: etisserant@0: def _init_coll_EditMenu_Items(self, parent): lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') etisserant@0: parent.AppendSeparator() lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') etisserant@0: parent.AppendSeparator() lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text='Node infos') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-301 Profile') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-302 Profile') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS7, etisserant@0: kind=wx.ITEM_NORMAL, text='Other Profile') etisserant@0: self.Bind(wx.EVT_MENU, self.OnUndoMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRedoMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnRefreshMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS6) etisserant@0: self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS7) etisserant@0: self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, lbessard@254: id=ID_OBJDICTEDITEDITMENUITEMS8) etisserant@0: etisserant@0: def _init_coll_HelpMenu_Items(self, parent): lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') etisserant@0: self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, lbessard@254: id=ID_OBJDICTEDITHELPMENUITEMS0) lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS1, lbessard@205: kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') lbessard@205: self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, lbessard@254: id=ID_OBJDICTEDITHELPMENUITEMS1) lbessard@72: if Html_Window: lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS2, lbessard@72: kind=wx.ITEM_NORMAL, text='About') lbessard@72: self.Bind(wx.EVT_MENU, self.OnAboutMenu, lbessard@254: id=ID_OBJDICTEDITHELPMENUITEMS2) etisserant@0: etisserant@0: def _init_coll_FileMenu_Items(self, parent): lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text='New\tCTRL+N') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS6, etisserant@0: kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') etisserant@0: parent.AppendSeparator() lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS7, etisserant@171: kind=wx.ITEM_NORMAL, text='Import EDS file') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS9, lbessard@182: kind=wx.ITEM_NORMAL, text='Export to EDS file') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS8, etisserant@0: kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') etisserant@0: parent.AppendSeparator() lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Exit') etisserant@0: self.Bind(wx.EVT_MENU, self.OnOpenMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnCloseMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnQuitMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnNewMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS5) etisserant@0: self.Bind(wx.EVT_MENU, self.OnSaveAsMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS6) lbessard@182: self.Bind(wx.EVT_MENU, self.OnImportEDSMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS7) lbessard@182: self.Bind(wx.EVT_MENU, self.OnExportCMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS8) lbessard@182: self.Bind(wx.EVT_MENU, self.OnExportEDSMenu, lbessard@254: id=ID_OBJDICTEDITFILEMENUITEMS9) etisserant@0: etisserant@0: def _init_coll_AddMenu_Items(self, parent): lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS0, etisserant@0: kind=wx.ITEM_NORMAL, text='SDO Server') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS1, etisserant@0: kind=wx.ITEM_NORMAL, text='SDO Client') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS2, etisserant@0: kind=wx.ITEM_NORMAL, text='PDO Transmit') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS3, etisserant@0: kind=wx.ITEM_NORMAL, text='PDO Receive') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS4, etisserant@0: kind=wx.ITEM_NORMAL, text='Map Variable') lbessard@254: parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS5, etisserant@0: kind=wx.ITEM_NORMAL, text='User Type') etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS0) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS1) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS2) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS3) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS4) etisserant@0: self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, lbessard@254: id=ID_OBJDICTEDITADDMENUITEMS5) etisserant@0: etisserant@0: def _init_coll_HelpBar_Fields(self, parent): etisserant@0: parent.SetFieldsCount(3) etisserant@0: etisserant@0: parent.SetStatusText(number=0, text='') etisserant@0: parent.SetStatusText(number=1, text='') etisserant@0: parent.SetStatusText(number=2, text='') etisserant@0: etisserant@0: parent.SetStatusWidths([100, 110, -1]) etisserant@0: etisserant@0: def _init_utils(self): etisserant@0: self.menuBar1 = wx.MenuBar() etisserant@0: self.menuBar1.SetEvtHandlerEnabled(True) etisserant@0: etisserant@0: self.FileMenu = wx.Menu(title='') etisserant@0: self.EditMenu = wx.Menu(title='') etisserant@0: self.AddMenu = wx.Menu(title='') etisserant@0: self.HelpMenu = wx.Menu(title='') etisserant@0: etisserant@0: self._init_coll_menuBar1_Menus(self.menuBar1) etisserant@0: self._init_coll_FileMenu_Items(self.FileMenu) etisserant@0: self._init_coll_EditMenu_Items(self.EditMenu) etisserant@0: self._init_coll_AddMenu_Items(self.AddMenu) etisserant@0: self._init_coll_HelpMenu_Items(self.HelpMenu) etisserant@0: etisserant@0: def _init_ctrls(self, prnt): lbessard@254: wx.Frame.__init__(self, id=ID_OBJDICTEDIT, name='objdictedit', etisserant@0: parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), etisserant@0: style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') etisserant@0: self._init_utils() etisserant@0: self.SetClientSize(wx.Size(1000, 700)) etisserant@0: self.SetMenuBar(self.menuBar1) lbessard@273: self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) lbessard@254: lbessard@254: self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED, etisserant@0: name='FileOpened', parent=self, pos=wx.Point(0, 0), etisserant@0: size=wx.Size(0, 0), style=0) etisserant@0: self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, lbessard@254: self.OnFileSelectedChanged, id=ID_OBJDICTEDITFILEOPENED) lbessard@254: lbessard@254: self.HelpBar = wx.StatusBar(id=ID_OBJDICTEDITHELPBAR, name='HelpBar', lbessard@254: parent=self, style=wx.ST_SIZEGRIP) etisserant@0: self._init_coll_HelpBar_Fields(self.HelpBar) etisserant@0: self.SetStatusBar(self.HelpBar) etisserant@0: lbessard@276: def __init__(self, parent, filesOpen = []): etisserant@0: self._init_ctrls(parent) etisserant@0: self.HtmlFrameOpened = [] lbessard@245: self.ModeSolo = True etisserant@0: lbessard@258: self.Manager = NodeManager() etisserant@0: for filepath in filesOpen: lbessard@232: result = self.Manager.OpenFileInCurrent(filepath) lbessard@232: if type(result) == IntType: lbessard@299: new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) lbessard@232: new_editingpanel.SetIndex(result) lbessard@232: self.FileOpened.AddPage(new_editingpanel, "") lbessard@232: window = self.FileOpened.GetPage(0) lbessard@232: if window: lbessard@232: self.Manager.ChangeCurrentNode(window.GetIndex()) lbessard@232: self.FileOpened.SetSelection(0) lbessard@258: if self.Manager.CurrentDS302Defined(): lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) etisserant@0: else: lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshTitle() etisserant@0: self.RefreshMainMenu() etisserant@0: etisserant@0: def OnAddSDOServerMenu(self, event): etisserant@0: self.Manager.AddSDOServerToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddSDOClientMenu(self, event): etisserant@0: self.Manager.AddSDOClientToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPDOTransmitMenu(self, event): etisserant@0: self.Manager.AddPDOTransmitToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddPDOReceiveMenu(self, event): etisserant@0: self.Manager.AddPDOReceiveToCurrent() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddMapVariableMenu(self, event): etisserant@0: self.AddMapVariable() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAddUserTypeMenu(self, event): etisserant@0: self.AddUserType() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnFileSelectedChanged(self, event): lbessard@43: selected = event.GetSelection() etisserant@37: # At init selected = -1 etisserant@37: if selected >= 0: lbessard@205: window = self.FileOpened.GetPage(selected) lbessard@223: if window: lbessard@223: self.Manager.ChangeCurrentNode(window.GetIndex()) lbessard@300: wx.CallAfter(self.RefreshBufferState) lbessard@223: self.RefreshStatusBar() lbessard@223: self.RefreshProfileMenu() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnHelpDS301Menu(self, event): lbessard@72: find_index = False etisserant@0: selected = self.FileOpened.GetSelection() etisserant@0: if selected >= 0: etisserant@0: window = self.FileOpened.GetPage(selected) etisserant@0: result = window.GetSelection() etisserant@0: if result: lbessard@72: find_index = True etisserant@0: index, subIndex = result etisserant@158: result = OpenPDFDocIndex(index, ScriptDirectory) etisserant@0: if type(result) == StringType: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@72: if not find_index: etisserant@158: result = OpenPDFDocIndex(None, ScriptDirectory) lbessard@72: if type(result) == StringType: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) lbessard@72: message.ShowModal() lbessard@72: message.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnHelpCANFestivalMenu(self, event): etisserant@158: #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) etisserant@341: if wx.Platform == '__WXMSW__': etisserant@386: readerpath = get_acroversion() etisserant@386: readerexepath = os.path.join(readerpath,"AcroRd32.exe") etisserant@386: if(os.path.isfile(readerexepath)): etisserant@386: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", os.path.join(ScriptDirectory, "doc","manual_en.pdf")) etisserant@341: else: etisserant@341: os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnAboutMenu(self, event): etisserant@158: self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OpenHtmlFrame(self, title, file, size): etisserant@0: if title not in self.HtmlFrameOpened: etisserant@0: self.HtmlFrameOpened.append(title) etisserant@0: window = HtmlFrame(self, self.HtmlFrameOpened) etisserant@0: window.SetTitle(title) etisserant@0: window.SetHtmlPage(file) etisserant@0: window.SetClientSize(size) etisserant@0: window.Show() etisserant@0: etisserant@0: def OnQuitMenu(self, event): etisserant@0: self.Close() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnCloseFrame(self, event): etisserant@0: if self.Manager.OneFileHasChanged(): lbessard@254: dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) etisserant@0: answer = dialog.ShowModal() etisserant@0: dialog.Destroy() lbessard@254: if answer == wx.ID_YES: etisserant@0: self.Manager.ChangeCurrentNode(0) etisserant@0: for i in xrange(self.FileOpened.GetPageCount()): lbessard@223: window = self.FileOpened.GetPage(i) lbessard@223: self.Manager.ChangeCurrentNode(window.GetIndex()) etisserant@0: if self.Manager.CurrentIsSaved(): etisserant@0: self.Manager.CloseCurrent() etisserant@0: else: etisserant@0: self.Save() etisserant@0: self.Manager.CloseCurrent(True) etisserant@0: event.Skip() lbessard@254: elif answer == wx.ID_NO: etisserant@0: for i in xrange(self.FileOpened.GetPageCount()): etisserant@0: self.Manager.CloseCurrent(True) lbessard@254: wx.CallAfter(self.Close) etisserant@0: event.Skip() etisserant@0: else: etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Refresh Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def RefreshTitle(self): etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename()) etisserant@0: else: etisserant@0: self.SetTitle("Objdictedit") etisserant@0: etisserant@0: def OnRefreshMenu(self, event): etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: etisserant@0: def RefreshCurrentIndexList(self): etisserant@0: selected = self.FileOpened.GetSelection() etisserant@0: window = self.FileOpened.GetPage(selected) etisserant@0: window.RefreshIndexList() etisserant@0: etisserant@0: def RefreshStatusBar(self): lbessard@348: if self and self.HelpBar: lbessard@209: selected = self.FileOpened.GetSelection() lbessard@209: if selected >= 0: lbessard@209: window = self.FileOpened.GetPage(selected) lbessard@209: selection = window.GetSelection() lbessard@209: if selection: lbessard@209: index, subIndex = selection lbessard@209: if self.Manager.IsCurrentEntry(index): lbessard@209: self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) lbessard@209: self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) lbessard@209: entryinfos = self.Manager.GetEntryInfos(index) lbessard@209: name = entryinfos["name"] lbessard@209: category = "Optional" lbessard@209: if entryinfos["need"]: lbessard@209: category = "Mandatory" lbessard@209: struct = "VAR" lbessard@209: number = "" lbessard@209: if entryinfos["struct"] & OD_IdenticalIndexes: lbessard@209: number = " possibly defined %d times"%entryinfos["nbmax"] lbessard@209: if entryinfos["struct"] & OD_IdenticalSubindexes: lbessard@209: struct = "REC" lbessard@209: elif entryinfos["struct"] & OD_MultipleSubindexes: lbessard@209: struct = "ARRAY" lbessard@209: text = "%s: %s entry of struct %s%s."%(name,category,struct,number) lbessard@209: self.HelpBar.SetStatusText(text, 2) lbessard@209: else: lbessard@209: for i in xrange(3): lbessard@209: self.HelpBar.SetStatusText("", i) lbessard@205: else: lbessard@205: for i in xrange(3): lbessard@205: self.HelpBar.SetStatusText("", i) etisserant@0: etisserant@0: def RefreshMainMenu(self): lbessard@182: if self.FileMenu: lbessard@182: if self.FileOpened.GetPageCount() > 0: lbessard@182: self.menuBar1.EnableTop(1, True) lbessard@182: self.menuBar1.EnableTop(2, True) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, True) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, True) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, True) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, True) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, True) lbessard@182: else: lbessard@258: self.menuBar1.EnableTop(1, False) lbessard@182: self.menuBar1.EnableTop(2, False) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, False) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, False) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, False) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, False) lbessard@254: self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, False) etisserant@0: etisserant@0: def RefreshEditMenu(self): lbessard@182: if self.FileMenu: lbessard@182: if self.FileOpened.GetPageCount() > 0: lbessard@182: undo, redo = self.Manager.GetCurrentBufferState() lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, undo) lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, redo) lbessard@182: else: lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, False) lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, False) etisserant@0: etisserant@0: def RefreshProfileMenu(self): lbessard@182: if self.EditMenu: lbessard@182: profile = self.Manager.GetCurrentProfileName() lbessard@254: edititem = self.EditMenu.FindItemById(ID_OBJDICTEDITEDITMENUITEMS7) lbessard@182: if edititem: lbessard@182: length = self.AddMenu.GetMenuItemCount() lbessard@182: for i in xrange(length-6): lbessard@182: additem = self.AddMenu.FindItemByPosition(6) lbessard@182: self.AddMenu.Delete(additem.GetId()) lbessard@182: if profile not in ("None", "DS-301"): lbessard@182: edititem.SetText("%s Profile"%profile) lbessard@182: edititem.Enable(True) lbessard@182: self.AddMenu.AppendSeparator() lbessard@182: for text, indexes in self.Manager.GetCurrentSpecificMenu(): lbessard@182: new_id = wx.NewId() lbessard@182: self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) lbessard@182: self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) lbessard@182: else: lbessard@182: edititem.SetText("Other Profile") lbessard@182: edititem.Enable(False) etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Buffer Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def RefreshBufferState(self): etisserant@0: fileopened = self.Manager.GetAllFilenames() etisserant@0: for idx, filename in enumerate(fileopened): etisserant@0: self.FileOpened.SetPageText(idx, filename) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshTitle() etisserant@0: etisserant@0: def OnUndoMenu(self, event): etisserant@0: self.Manager.LoadCurrentPrevious() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshBufferState() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnRedoMenu(self, event): etisserant@0: self.Manager.LoadCurrentNext() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshBufferState() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Load and Save Funtions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnNewMenu(self, event): etisserant@0: self.FilePath = "" lbessard@258: dialog = CreateNodeDialog(self) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@205: name, id, nodetype, description = dialog.GetValues() lbessard@59: profile, filepath = dialog.GetProfile() lbessard@59: NMT = dialog.GetNMTManagement() lbessard@59: options = dialog.GetOptions() lbessard@205: result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) lbessard@205: if type(result) == IntType: lbessard@299: new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) lbessard@205: new_editingpanel.SetIndex(result) lbessard@59: self.FileOpened.AddPage(new_editingpanel, "") lbessard@205: self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) lbessard@59: if "DS302" in options: lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) lbessard@59: self.RefreshBufferState() lbessard@59: self.RefreshProfileMenu() lbessard@59: self.RefreshMainMenu() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@299: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnOpenMenu(self, event): etisserant@0: filepath = self.Manager.GetCurrentFilePath() etisserant@0: if filepath != "": etisserant@0: directory = os.path.dirname(filepath) etisserant@0: else: etisserant@0: directory = os.getcwd() lbessard@254: dialog = wx.FileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wx.OPEN|wx.CHANGE_DIR) lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isfile(filepath): etisserant@0: result = self.Manager.OpenFileInCurrent(filepath) lbessard@205: if type(result) == IntType: lbessard@299: new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) lbessard@205: new_editingpanel.SetIndex(result) etisserant@0: self.FileOpened.AddPage(new_editingpanel, "") lbessard@205: self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) etisserant@0: if self.Manager.CurrentDS302Defined(): lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) etisserant@0: else: lbessard@254: self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) etisserant@0: self.RefreshEditMenu() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshMainMenu() etisserant@0: else: lbessard@280: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveMenu(self, event): etisserant@0: self.Save() etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnSaveAsMenu(self, event): etisserant@0: self.SaveAs() lbessard@30: event.Skip() etisserant@0: etisserant@0: def Save(self): etisserant@0: result = self.Manager.SaveCurrentInFile() etisserant@0: if not result: etisserant@0: self.SaveAs() etisserant@0: elif type(result) != StringType: etisserant@0: self.RefreshBufferState() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: etisserant@0: def SaveAs(self): etisserant@0: filepath = self.Manager.GetCurrentFilePath() etisserant@0: if filepath != "": etisserant@0: directory, filename = os.path.split(filepath) etisserant@0: else: etisserant@0: directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] lbessard@254: dialog = wx.FileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isdir(os.path.dirname(filepath)): etisserant@0: result = self.Manager.SaveCurrentInFile(filepath) etisserant@0: if type(result) != StringType: etisserant@0: self.RefreshBufferState() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def OnCloseMenu(self, event): lbessard@254: answer = wx.ID_YES etisserant@0: result = self.Manager.CloseCurrent() etisserant@0: if not result: lbessard@254: dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close File", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) etisserant@0: answer = dialog.ShowModal() etisserant@0: dialog.Destroy() lbessard@254: if answer == wx.ID_YES: etisserant@0: self.OnSaveMenu(event) etisserant@0: if self.Manager.CurrentIsSaved(): etisserant@0: self.Manager.CloseCurrent() lbessard@254: elif answer == wx.ID_NO: etisserant@0: self.Manager.CloseCurrent(True) etisserant@0: if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): etisserant@0: current = self.FileOpened.GetSelection() etisserant@0: self.FileOpened.DeletePage(current) etisserant@0: if self.FileOpened.GetPageCount() > 0: etisserant@0: self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshMainMenu() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Import and Export Functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: lbessard@182: def OnImportEDSMenu(self, event): lbessard@254: dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wx.OPEN|wx.CHANGE_DIR) lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isfile(filepath): lbessard@182: result = self.Manager.ImportCurrentFromEDSFile(filepath) lbessard@205: if type(result) == IntType: lbessard@299: new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) lbessard@205: new_editingpanel.SetIndex(result) lbessard@205: self.FileOpened.AddPage(new_editingpanel, "") lbessard@205: self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: self.RefreshProfileMenu() etisserant@0: self.RefreshMainMenu() lbessard@254: message = wx.MessageDialog(self, "Import successful", "Information", wx.OK|wx.ICON_INFORMATION) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@182: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() lbessard@182: else: lbessard@254: message = wx.MessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wx.OK|wx.ICON_ERROR) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: lbessard@182: lbessard@182: def OnExportEDSMenu(self, event): lbessard@254: dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "EDS files (*.eds)|*.eds|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@182: filepath = dialog.GetPath() lbessard@182: if os.path.isdir(os.path.dirname(filepath)): lbessard@182: path, extend = os.path.splitext(filepath) lbessard@182: if extend in ("", "."): lbessard@182: filepath = path + ".eds" lbessard@182: result = self.Manager.ExportCurrentToEDSFile(filepath) lbessard@182: if not result: lbessard@254: message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() lbessard@182: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() lbessard@182: else: lbessard@254: message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() lbessard@182: dialog.Destroy() lbessard@182: event.Skip() lbessard@182: lbessard@182: def OnExportCMenu(self, event): lbessard@254: dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "CANFestival C files (*.c)|*.c|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: filepath = dialog.GetPath() etisserant@0: if os.path.isdir(os.path.dirname(filepath)): etisserant@0: path, extend = os.path.splitext(filepath) etisserant@0: if extend in ("", "."): etisserant@0: filepath = path + ".c" lbessard@182: result = self.Manager.ExportCurrentToCFile(filepath) lbessard@182: if not result: lbessard@254: message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() lbessard@182: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@182: message.ShowModal() lbessard@182: message.Destroy() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: event.Skip() etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Editing Profiles functions etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnCommunicationMenu(self, event): etisserant@0: dictionary,current = self.Manager.GetCurrentCommunicationLists() etisserant@0: self.EditProfile("Edit DS-301 Profile", dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnOtherCommunicationMenu(self, event): etisserant@0: dictionary,current = self.Manager.GetCurrentDS302Lists() etisserant@0: self.EditProfile("Edit DS-301 Profile", dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def OnEditProfileMenu(self, event): etisserant@0: title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() etisserant@0: dictionary,current = self.Manager.GetCurrentProfileLists() etisserant@0: self.EditProfile(title, dictionary, current) etisserant@0: event.Skip() etisserant@0: etisserant@0: def EditProfile(self, title, dictionary, current): etisserant@0: dialog = CommunicationDialog(self) etisserant@0: dialog.SetTitle(title) etisserant@0: dialog.SetIndexDictionary(dictionary) etisserant@0: dialog.SetCurrentList(current) etisserant@0: dialog.RefreshLists() lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: new_profile = dialog.GetCurrentList() etisserant@0: addinglist = [] etisserant@0: removinglist = [] etisserant@0: for index in new_profile: etisserant@0: if index not in current: etisserant@0: addinglist.append(index) etisserant@0: for index in current: etisserant@0: if index not in new_profile: etisserant@0: removinglist.append(index) etisserant@0: self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) etisserant@0: self.Manager.BufferCurrentNode() etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: def GetProfileCallBack(self, text): etisserant@0: def ProfileCallBack(event): etisserant@0: self.Manager.AddSpecificEntryToCurrent(text) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: event.Skip() etisserant@0: return ProfileCallBack etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Edit Node informations function etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def OnNodeInfosMenu(self, event): etisserant@0: dialog = NodeInfosDialog(self) lbessard@182: name, id, type, description = self.Manager.GetCurrentNodeInfos() lbessard@182: dialog.SetValues(name, id, type, description) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@182: name, id, type, description = dialog.GetValues() lbessard@182: self.Manager.SetCurrentNodeInfos(name, id, type, description) etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshProfileMenu() lbessard@205: selected = self.FileOpened.GetSelection() lbessard@205: if selected >= 0: lbessard@205: window = self.FileOpened.GetPage(selected) lbessard@205: window.RefreshTable() etisserant@0: event.Skip() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Add User Types and Variables etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: def AddMapVariable(self): lbessard@39: index = self.Manager.GetCurrentNextMapIndex() lbessard@39: if index: lbessard@39: dialog = MapVariableDialog(self) lbessard@39: dialog.SetIndex(index) lbessard@254: if dialog.ShowModal() == wx.ID_OK: lbessard@39: index, name, struct, number = dialog.GetValues() lbessard@39: result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) lbessard@39: if type(result) != StringType: lbessard@39: self.RefreshBufferState() lbessard@39: self.RefreshCurrentIndexList() lbessard@39: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) lbessard@39: message.ShowModal() lbessard@39: message.Destroy() lbessard@39: dialog.Destroy() lbessard@39: else: lbessard@254: message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR) lbessard@39: message.ShowModal() lbessard@39: message.Destroy() etisserant@0: etisserant@0: def AddUserType(self): etisserant@0: dialog = UserTypeDialog(self) etisserant@0: dialog.SetTypeList(self.Manager.GetCustomisableTypes()) lbessard@254: if dialog.ShowModal() == wx.ID_OK: etisserant@0: type, min, max, length = dialog.GetValues() etisserant@0: result = self.Manager.AddUserTypeToCurrent(type, min, max, length) lbessard@205: if not result: etisserant@0: self.RefreshBufferState() etisserant@0: self.RefreshCurrentIndexList() etisserant@0: else: lbessard@254: message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: dialog.Destroy() etisserant@0: etisserant@0: etisserant@0: #------------------------------------------------------------------------------- etisserant@0: # Exception Handler etisserant@0: #------------------------------------------------------------------------------- etisserant@0: etisserant@0: Max_Traceback_List_Size = 20 etisserant@0: etisserant@0: def Display_Exception_Dialog(e_type,e_value,e_tb): etisserant@0: trcbck_lst = [] etisserant@0: for i,line in enumerate(traceback.extract_tb(e_tb)): etisserant@0: trcbck = " " + str(i+1) + ". " etisserant@0: if line[0].find(os.getcwd()) == -1: etisserant@0: trcbck += "file : " + str(line[0]) + ", " etisserant@0: else: etisserant@0: trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " etisserant@0: trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) etisserant@0: trcbck_lst.append(trcbck) etisserant@0: etisserant@0: # Allow clicking.... etisserant@0: cap = wx.Window_GetCapture() etisserant@0: if cap: etisserant@0: cap.ReleaseMouse() etisserant@0: etisserant@0: dlg = wx.SingleChoiceDialog(None, etisserant@0: """ etisserant@0: An error happens. etisserant@0: etisserant@0: Click on OK for saving an error report. etisserant@0: etisserant@0: Please contact LOLITech at: etisserant@0: +33 (0)3 29 52 95 67 etisserant@0: bugs_objdictedit@lolitech.fr etisserant@0: etisserant@0: etisserant@0: Error: etisserant@0: """ + etisserant@0: str(e_type) + " : " + str(e_value), etisserant@0: "Error", etisserant@0: trcbck_lst) etisserant@0: try: etisserant@0: res = (dlg.ShowModal() == wx.ID_OK) etisserant@0: finally: etisserant@0: dlg.Destroy() etisserant@0: etisserant@0: return res etisserant@0: etisserant@0: def Display_Error_Dialog(e_value): lbessard@254: message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) etisserant@0: message.ShowModal() etisserant@0: message.Destroy() etisserant@0: etisserant@0: def get_last_traceback(tb): etisserant@0: while tb.tb_next: etisserant@0: tb = tb.tb_next etisserant@0: return tb etisserant@0: etisserant@0: etisserant@0: def format_namespace(d, indent=' '): etisserant@0: return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) etisserant@0: etisserant@0: etisserant@0: ignored_exceptions = [] # a problem with a line in a module is only reported once per session etisserant@0: lbessard@254: def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): etisserant@0: etisserant@0: def handle_exception(e_type, e_value, e_traceback): etisserant@0: traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) etisserant@0: if str(e_value).startswith("!!!"): etisserant@0: Display_Error_Dialog(e_value) etisserant@0: elif ex not in ignored_exceptions: etisserant@0: ignored_exceptions.append(ex) etisserant@0: result = Display_Exception_Dialog(e_type,e_value,e_traceback) etisserant@0: if result: etisserant@0: info = { etisserant@0: 'app-title' : wx.GetApp().GetAppName(), # app_title etisserant@0: 'app-version' : app_version, etisserant@0: 'wx-version' : wx.VERSION_STRING, etisserant@0: 'wx-platform' : wx.Platform, etisserant@0: 'python-version' : platform.python_version(), #sys.version.split()[0], etisserant@0: 'platform' : platform.platform(), etisserant@0: 'e-type' : e_type, etisserant@0: 'e-value' : e_value, etisserant@0: 'date' : time.ctime(), etisserant@0: 'cwd' : os.getcwd(), etisserant@0: } etisserant@0: if e_traceback: etisserant@0: info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) etisserant@0: last_tb = get_last_traceback(e_traceback) etisserant@0: exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred etisserant@0: info['locals'] = format_namespace(exception_locals) etisserant@0: if 'self' in exception_locals: etisserant@0: info['self'] = format_namespace(exception_locals['self'].__dict__) etisserant@0: etisserant@0: output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') etisserant@0: lst = info.keys() etisserant@0: lst.sort() etisserant@0: for a in lst: etisserant@0: output.write(a+":\n"+str(info[a])+"\n\n") etisserant@0: etisserant@0: #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) etisserant@0: sys.excepthook = handle_exception etisserant@0: etisserant@0: if __name__ == '__main__': lbessard@276: def usage(): lbessard@276: print "\nUsage of objdictedit.py :" lbessard@276: print "\n %s [Filepath, ...]\n"%sys.argv[0] lbessard@276: lbessard@276: try: lbessard@276: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) lbessard@276: except getopt.GetoptError: lbessard@276: # print help information and exit: lbessard@276: usage() lbessard@276: sys.exit(2) lbessard@276: lbessard@276: for o, a in opts: lbessard@276: if o in ("-h", "--help"): lbessard@276: usage() lbessard@276: sys.exit() lbessard@276: lbessard@254: app = wx.PySimpleApp() lbessard@254: wx.InitAllImageHandlers() etisserant@0: etisserant@0: # Install a exception handle for bug reports lbessard@254: AddExceptHook(os.getcwd(),__version__) etisserant@0: lbessard@276: frame = objdictedit(None, args) etisserant@0: etisserant@0: frame.Show() etisserant@0: app.MainLoop()