diff -r 6787754b251b -r b6572d0336c3 doc/doxygen/html/objdictedit_8py-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/doxygen/html/objdictedit_8py-source.html Mon Jun 04 17:59:50 2007 +0200 @@ -0,0 +1,1052 @@ + +
+00001 #!/usr/bin/env python +00002 # -*- coding: utf-8 -*- +00003 +00004 #This file is part of CanFestival, a library implementing CanOpen Stack. +00005 # +00006 #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD +00007 # +00008 #See COPYING file for copyrights details. +00009 # +00010 #This library is free software; you can redistribute it and/or +00011 #modify it under the terms of the GNU Lesser General Public +00012 #License as published by the Free Software Foundation; either +00013 #version 2.1 of the License, or (at your option) any later version. +00014 # +00015 #This library is distributed in the hope that it will be useful, +00016 #but WITHOUT ANY WARRANTY; without even the implied warranty of +00017 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +00018 #Lesser General Public License for more details. +00019 # +00020 #You should have received a copy of the GNU Lesser General Public +00021 #License along with this library; if not, write to the Free Software +00022 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +00023 +00024 from wxPython.wx import * +00025 from wxPython.grid import * +00026 import wx +00027 import wx.grid +00028 +00029 from types import * +00030 import os, re, platform, sys, time, traceback, getopt +00031 +00032 __version__ = "$Revision$" +00033 +00034 from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes +00035 +00036 from nodemanager import * +00037 from subindextable import * +00038 from commondialogs import * +00039 from doc_index.DS301_index import * +00040 +00041 try: +00042 from wxPython.html import * +00043 +00044 wxEVT_HTML_URL_CLICK = wxNewId() +00045 +00046 def EVT_HTML_URL_CLICK(win, func): +00047 win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func) +00048 +00049 class wxHtmlWindowUrlClick(wxPyEvent): +00050 def __init__(self, linkinfo): +00051 wxPyEvent.__init__(self) +00052 self.SetEventType(wxEVT_HTML_URL_CLICK) +00053 self.linkinfolinkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) +00054 +00055 class wxUrlClickHtmlWindow(wxHtmlWindow): +00056 """ HTML window that generates and OnLinkClicked event. +00057 +00058 Use this to avoid having to override HTMLWindow +00059 """ +00060 def OnLinkClicked(self, linkinfo): +00061 wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo)) +00062 +00063 #------------------------------------------------------------------------------- +00064 # Html Frame +00065 #------------------------------------------------------------------------------- +00066 +00067 [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] +00068 +00069 class HtmlFrame(wx.Frame): +00070 def _init_ctrls(self, prnt): +00071 # generated method, don't edit +00072 wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame', +00073 parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), +00074 style=wx.DEFAULT_FRAME_STYLE, title='') +00075 self.Bind(wx.EVT_CLOSE, self.OnCloseFrameOnCloseFrame, id=wxID_HTMLFRAME) +00076 +00077 self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT, +00078 name='HtmlContent', parent=self, pos=wx.Point(0, 0), +00079 size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION) +00080 EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClickOnLinkClick) +00081 +00082 def __init__(self, parent, opened): +00083 self._init_ctrls_init_ctrls(parent) +00084 self.HtmlFrameOpenedHtmlFrameOpened = opened +00085 +00086 def SetHtmlCode(self, htmlcode): +00087 self.HtmlContent.SetPage(htmlcode) +00088 +00089 def SetHtmlPage(self, htmlpage): +00090 self.HtmlContent.LoadPage(htmlpage) +00091 +00092 def OnCloseFrame(self, event): +00093 self.HtmlFrameOpenedHtmlFrameOpened.remove(self.GetTitle()) +00094 event.Skip() +00095 +00096 def OnLinkClick(self, event): +00097 url = event.linkinfo[0] +00098 try: +00099 import webbrowser +00100 except ImportError: +00101 wxMessageBox('Please point your browser at: %s' % url) +00102 else: +00103 webbrowser.open(url) +00104 +00105 Html_Window = True +00106 except: +00107 Html_Window = False +00108 +00109 def create(parent): +00110 return objdictedit(parent) +00111 +00112 def usage(): +00113 print "\nUsage of objdictedit.py :" +00114 print "\n %s [Filepath, ...]\n"%sys.argv[0] +00115 +00116 try: +00117 opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) +00118 except getopt.GetoptError: +00119 # print help information and exit: +00120 usage() +00121 sys.exit(2) +00122 +00123 for o, a in opts: +00124 if o in ("-h", "--help"): +00125 usage() +00126 sys.exit() +00127 +00128 filesOpen = args +00129 ScriptDirectory = sys.path[0] +00130 +00131 +00132 [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, +00133 wxID_OBJDICTEDITHELPBAR, +00134 ] = [wx.NewId() for _init_ctrls in range(3)] +00135 +00136 [wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, +00137 wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, +00138 wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, +00139 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] +00140 +00141 [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, +00142 wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, +00143 wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, +00144 wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8, +00145 wxID_OBJDICTEDITFILEMENUITEMS9, +00146 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] +00147 +00148 [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, +00149 wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, +00150 wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, +00151 wxID_OBJDICTEDITEDITMENUITEMS8, +00152 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] +00153 +00154 [wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1, +00155 wxID_OBJDICTEDITHELPMENUITEMS2, +00156 ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] +00157 +00158 class objdictedit(wx.Frame): +00159 def _init_coll_menuBar1_Menus(self, parent): +00160 # generated method, don't edit +00161 +00162 parent.Append(menu=self.FileMenu, title='File') +00163 parent.Append(menu=self.EditMenu, title='Edit') +00164 parent.Append(menu=self.AddMenu, title='Add') +00165 parent.Append(menu=self.HelpMenu, title='Help') +00166 +00167 def _init_coll_EditMenu_Items(self, parent): +00168 # generated method, don't edit +00169 +00170 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4, +00171 kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') +00172 parent.AppendSeparator() +00173 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1, +00174 kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') +00175 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0, +00176 kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') +00177 parent.AppendSeparator() +00178 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6, +00179 kind=wx.ITEM_NORMAL, text='Node infos') +00180 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2, +00181 kind=wx.ITEM_NORMAL, text='DS-301 Profile') +00182 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8, +00183 kind=wx.ITEM_NORMAL, text='DS-302 Profile') +00184 parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7, +00185 kind=wx.ITEM_NORMAL, text='Other Profile') +00186 self.Bind(wx.EVT_MENU, self.OnUndoMenuOnUndoMenu, +00187 id=wxID_OBJDICTEDITEDITMENUITEMS1) +00188 self.Bind(wx.EVT_MENU, self.OnRedoMenuOnRedoMenu, +00189 id=wxID_OBJDICTEDITEDITMENUITEMS0) +00190 self.Bind(wx.EVT_MENU, self.OnCommunicationMenuOnCommunicationMenu, +00191 id=wxID_OBJDICTEDITEDITMENUITEMS2) +00192 self.Bind(wx.EVT_MENU, self.OnRefreshMenuOnRefreshMenu, +00193 id=wxID_OBJDICTEDITEDITMENUITEMS4) +00194 self.Bind(wx.EVT_MENU, self.OnNodeInfosMenuOnNodeInfosMenu, +00195 id=wxID_OBJDICTEDITEDITMENUITEMS6) +00196 self.Bind(wx.EVT_MENU, self.OnEditProfileMenuOnEditProfileMenu, +00197 id=wxID_OBJDICTEDITEDITMENUITEMS7) +00198 self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenuOnOtherCommunicationMenu, +00199 id=wxID_OBJDICTEDITEDITMENUITEMS8) +00200 +00201 def _init_coll_HelpMenu_Items(self, parent): +00202 # generated method, don't edit +00203 +00204 parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0, +00205 kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') +00206 self.Bind(wx.EVT_MENU, self.OnHelpDS301MenuOnHelpDS301Menu, +00207 id=wxID_OBJDICTEDITHELPMENUITEMS0) +00208 parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1, +00209 kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') +00210 self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenuOnHelpCANFestivalMenu, +00211 id=wxID_OBJDICTEDITHELPMENUITEMS1) +00212 if Html_Window: +00213 parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2, +00214 kind=wx.ITEM_NORMAL, text='About') +00215 self.Bind(wx.EVT_MENU, self.OnAboutMenuOnAboutMenu, +00216 id=wxID_OBJDICTEDITHELPMENUITEMS2) +00217 +00218 def _init_coll_FileMenu_Items(self, parent): +00219 # generated method, don't edit +00220 +00221 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5, +00222 kind=wx.ITEM_NORMAL, text='New\tCTRL+N') +00223 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0, +00224 kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') +00225 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1, +00226 kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') +00227 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6, +00228 kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') +00229 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2, +00230 kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') +00231 parent.AppendSeparator() +00232 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7, +00233 kind=wx.ITEM_NORMAL, text='Import EDS file') +00234 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS9, +00235 kind=wx.ITEM_NORMAL, text='Export to EDS file') +00236 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8, +00237 kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') +00238 parent.AppendSeparator() +00239 parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4, +00240 kind=wx.ITEM_NORMAL, text='Exit') +00241 self.Bind(wx.EVT_MENU, self.OnOpenMenuOnOpenMenu, +00242 id=wxID_OBJDICTEDITFILEMENUITEMS0) +00243 self.Bind(wx.EVT_MENU, self.OnSaveMenuOnSaveMenu, +00244 id=wxID_OBJDICTEDITFILEMENUITEMS1) +00245 self.Bind(wx.EVT_MENU, self.OnCloseMenuOnCloseMenu, +00246 id=wxID_OBJDICTEDITFILEMENUITEMS2) +00247 self.Bind(wx.EVT_MENU, self.OnQuitMenuOnQuitMenu, +00248 id=wxID_OBJDICTEDITFILEMENUITEMS4) +00249 self.Bind(wx.EVT_MENU, self.OnNewMenuOnNewMenu, +00250 id=wxID_OBJDICTEDITFILEMENUITEMS5) +00251 self.Bind(wx.EVT_MENU, self.OnSaveAsMenuOnSaveAsMenu, +00252 id=wxID_OBJDICTEDITFILEMENUITEMS6) +00253 self.Bind(wx.EVT_MENU, self.OnImportEDSMenuOnImportEDSMenu, +00254 id=wxID_OBJDICTEDITFILEMENUITEMS7) +00255 self.Bind(wx.EVT_MENU, self.OnExportCMenuOnExportCMenu, +00256 id=wxID_OBJDICTEDITFILEMENUITEMS8) +00257 self.Bind(wx.EVT_MENU, self.OnExportEDSMenuOnExportEDSMenu, +00258 id=wxID_OBJDICTEDITFILEMENUITEMS9) +00259 +00260 def _init_coll_AddMenu_Items(self, parent): +00261 # generated method, don't edit +00262 +00263 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0, +00264 kind=wx.ITEM_NORMAL, text='SDO Server') +00265 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1, +00266 kind=wx.ITEM_NORMAL, text='SDO Client') +00267 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2, +00268 kind=wx.ITEM_NORMAL, text='PDO Transmit') +00269 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3, +00270 kind=wx.ITEM_NORMAL, text='PDO Receive') +00271 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4, +00272 kind=wx.ITEM_NORMAL, text='Map Variable') +00273 parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5, +00274 kind=wx.ITEM_NORMAL, text='User Type') +00275 self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenuOnAddSDOServerMenu, +00276 id=wxID_OBJDICTEDITADDMENUITEMS0) +00277 self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenuOnAddSDOClientMenu, +00278 id=wxID_OBJDICTEDITADDMENUITEMS1) +00279 self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenuOnAddPDOTransmitMenu, +00280 id=wxID_OBJDICTEDITADDMENUITEMS2) +00281 self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenuOnAddPDOReceiveMenu, +00282 id=wxID_OBJDICTEDITADDMENUITEMS3) +00283 self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenuOnAddMapVariableMenu, +00284 id=wxID_OBJDICTEDITADDMENUITEMS4) +00285 self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenuOnAddUserTypeMenu, +00286 id=wxID_OBJDICTEDITADDMENUITEMS5) +00287 +00288 def _init_coll_HelpBar_Fields(self, parent): +00289 # generated method, don't edit +00290 parent.SetFieldsCount(3) +00291 +00292 parent.SetStatusText(number=0, text='') +00293 parent.SetStatusText(number=1, text='') +00294 parent.SetStatusText(number=2, text='') +00295 +00296 parent.SetStatusWidths([100, 110, -1]) +00297 +00298 def _init_utils(self): +00299 # generated method, don't edit +00300 self.menuBar1 = wx.MenuBar() +00301 self.menuBar1.SetEvtHandlerEnabled(True) +00302 +00303 self.FileMenu = wx.Menu(title='') +00304 +00305 self.EditMenu = wx.Menu(title='') +00306 +00307 self.AddMenu = wx.Menu(title='') +00308 +00309 self.HelpMenu = wx.Menu(title='') +00310 +00311 self._init_coll_menuBar1_Menus_init_coll_menuBar1_Menus(self.menuBar1) +00312 self._init_coll_FileMenu_Items_init_coll_FileMenu_Items(self.FileMenu) +00313 self._init_coll_EditMenu_Items_init_coll_EditMenu_Items(self.EditMenu) +00314 self._init_coll_AddMenu_Items_init_coll_AddMenu_Items(self.AddMenu) +00315 self._init_coll_HelpMenu_Items_init_coll_HelpMenu_Items(self.HelpMenu) +00316 +00317 def _init_ctrls(self, prnt): +00318 # generated method, don't edit +00319 wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit', +00320 parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), +00321 style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') +00322 self._init_utils_init_utils() +00323 self.SetClientSize(wx.Size(1000, 700)) +00324 self.SetMenuBar(self.menuBar1) +00325 self.Bind(wx.EVT_CLOSE, self.OnCloseFrameOnCloseFrame, id=wxID_OBJDICTEDIT) +00326 +00327 self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED, +00328 name='FileOpened', parent=self, pos=wx.Point(0, 0), +00329 size=wx.Size(0, 0), style=0) +00330 self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, +00331 self.OnFileSelectedChangedOnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED) +00332 +00333 self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar', +00334 parent=self, style=wxST_SIZEGRIP) +00335 self._init_coll_HelpBar_Fields_init_coll_HelpBar_Fields(self.HelpBar) +00336 self.SetStatusBar(self.HelpBar) +00337 +00338 def __init__(self, parent): +00339 self._init_ctrls_init_ctrls(parent) +00340 self.HtmlFrameOpenedHtmlFrameOpened = [] +00341 +00342 self.ManagerManager = NodeManager(ScriptDirectory) +00343 for filepath in filesOpen: +00344 self.ManagerManager.OpenFileInCurrent(filepath) +00345 new_editingpanel = EditingPanel(self, self.ManagerManager) +00346 self.FileOpened.AddPage(new_editingpanel, "") +00347 self.FileOpened.SetSelection(self.ManagerManager.GetCurrentNodeIndex()) +00348 if self.ManagerManager.CurrentDS302Defined(): +00349 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) +00350 else: +00351 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) +00352 self.RefreshEditMenuRefreshEditMenu() +00353 self.RefreshBufferStateRefreshBufferState() +00354 self.RefreshProfileMenuRefreshProfileMenu() +00355 self.RefreshTitleRefreshTitle() +00356 self.RefreshMainMenuRefreshMainMenu() +00357 +00358 def GetNoteBook(self): +00359 return self.FileOpened +00360 +00361 def OnAddSDOServerMenu(self, event): +00362 self.ManagerManager.AddSDOServerToCurrent() +00363 self.RefreshBufferStateRefreshBufferState() +00364 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00365 event.Skip() +00366 +00367 def OnAddSDOClientMenu(self, event): +00368 self.ManagerManager.AddSDOClientToCurrent() +00369 self.RefreshBufferStateRefreshBufferState() +00370 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00371 event.Skip() +00372 +00373 def OnAddPDOTransmitMenu(self, event): +00374 self.ManagerManager.AddPDOTransmitToCurrent() +00375 self.RefreshBufferStateRefreshBufferState() +00376 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00377 event.Skip() +00378 +00379 def OnAddPDOReceiveMenu(self, event): +00380 self.ManagerManager.AddPDOReceiveToCurrent() +00381 self.RefreshBufferStateRefreshBufferState() +00382 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00383 event.Skip() +00384 +00385 def OnAddMapVariableMenu(self, event): +00386 self.AddMapVariableAddMapVariable() +00387 event.Skip() +00388 +00389 def OnAddUserTypeMenu(self, event): +00390 self.AddUserTypeAddUserType() +00391 event.Skip() +00392 +00393 def OnFileSelectedChanged(self, event): +00394 selected = event.GetSelection() +00395 # At init selected = -1 +00396 if selected >= 0: +00397 window = self.FileOpened.GetPage(selected) +00398 self.ManagerManager.ChangeCurrentNode(window.GetIndex()) +00399 self.RefreshBufferStateRefreshBufferState() +00400 self.RefreshStatusBarRefreshStatusBar() +00401 self.RefreshProfileMenuRefreshProfileMenu() +00402 event.Skip() +00403 +00404 def OnHelpDS301Menu(self, event): +00405 find_index = False +00406 selected = self.FileOpened.GetSelection() +00407 if selected >= 0: +00408 window = self.FileOpened.GetPage(selected) +00409 result = window.GetSelection() +00410 if result: +00411 find_index = True +00412 index, subIndex = result +00413 result = OpenPDFDocIndex(index, ScriptDirectory) +00414 if type(result) == StringType: +00415 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) +00416 message.ShowModal() +00417 message.Destroy() +00418 if not find_index: +00419 result = OpenPDFDocIndex(None, ScriptDirectory) +00420 if type(result) == StringType: +00421 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) +00422 message.ShowModal() +00423 message.Destroy() +00424 event.Skip() +00425 +00426 def OnHelpCANFestivalMenu(self, event): +00427 #self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) +00428 os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) +00429 event.Skip() +00430 +00431 def OnAboutMenu(self, event): +00432 self.OpenHtmlFrameOpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) +00433 event.Skip() +00434 +00435 def OpenHtmlFrame(self, title, file, size): +00436 if title not in self.HtmlFrameOpenedHtmlFrameOpened: +00437 self.HtmlFrameOpenedHtmlFrameOpened.append(title) +00438 window = HtmlFrame(self, self.HtmlFrameOpenedHtmlFrameOpened) +00439 window.SetTitle(title) +00440 window.SetHtmlPage(file) +00441 window.SetClientSize(size) +00442 window.Show() +00443 +00444 def OnQuitMenu(self, event): +00445 self.Close() +00446 event.Skip() +00447 +00448 def OnCloseFrame(self, event): +00449 if self.ManagerManager.OneFileHasChanged(): +00450 dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION) +00451 answer = dialog.ShowModal() +00452 dialog.Destroy() +00453 if answer == wxID_YES: +00454 self.ManagerManager.ChangeCurrentNode(0) +00455 for i in xrange(self.FileOpened.GetPageCount()): +00456 if self.ManagerManager.CurrentIsSaved(): +00457 self.ManagerManager.CloseCurrent() +00458 else: +00459 self.SaveSave() +00460 self.ManagerManager.CloseCurrent(True) +00461 event.Skip() +00462 elif answer == wxID_NO: +00463 for i in xrange(self.FileOpened.GetPageCount()): +00464 self.ManagerManager.CloseCurrent(True) +00465 wxCallAfter(self.Close) +00466 event.Skip() +00467 else: +00468 event.Skip() +00469 +00470 #------------------------------------------------------------------------------- +00471 # Refresh Functions +00472 #------------------------------------------------------------------------------- +00473 +00474 def RefreshTitle(self): +00475 if self.FileOpened.GetPageCount() > 0: +00476 self.SetTitle("Objdictedit - %s"%self.ManagerManager.GetCurrentFilename()) +00477 else: +00478 self.SetTitle("Objdictedit") +00479 +00480 def OnRefreshMenu(self, event): +00481 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00482 event.Skip() +00483 +00484 def RefreshCurrentIndexList(self): +00485 selected = self.FileOpened.GetSelection() +00486 window = self.FileOpened.GetPage(selected) +00487 window.RefreshIndexList() +00488 +00489 def RefreshStatusBar(self): +00490 if self.HelpBar: +00491 window = self.FileOpened.GetPage(self.FileOpened.GetSelection()) +00492 selection = window.GetSelection() +00493 if selection: +00494 index, subIndex = selection +00495 if self.ManagerManager.IsCurrentEntry(index): +00496 self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) +00497 self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) +00498 entryinfos = self.ManagerManager.GetEntryInfos(index) +00499 name = entryinfos["name"] +00500 category = "Optional" +00501 if entryinfos["need"]: +00502 category = "Mandatory" +00503 struct = "VAR" +00504 number = "" +00505 if entryinfos["struct"] & OD_IdenticalIndexes: +00506 number = " possibly defined %d times"%entryinfos["nbmax"] +00507 if entryinfos["struct"] & OD_IdenticalSubindexes: +00508 struct = "REC" +00509 elif entryinfos["struct"] & OD_MultipleSubindexes: +00510 struct = "ARRAY" +00511 text = "%s: %s entry of struct %s%s."%(name,category,struct,number) +00512 self.HelpBar.SetStatusText(text, 2) +00513 else: +00514 for i in xrange(3): +00515 self.HelpBar.SetStatusText("", i) +00516 else: +00517 for i in xrange(3): +00518 self.HelpBar.SetStatusText("", i) +00519 +00520 def RefreshMainMenu(self): +00521 if self.FileMenu: +00522 if self.FileOpened.GetPageCount() > 0: +00523 self.menuBar1.EnableTop(1, True) +00524 self.menuBar1.EnableTop(2, True) +00525 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True) +00526 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True) +00527 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True) +00528 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True) +00529 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, True) +00530 else: +00531 self.menuBar1.EnableTop(1, False) +00532 self.menuBar1.EnableTop(2, False) +00533 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False) +00534 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False) +00535 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False) +00536 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False) +00537 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, False) +00538 +00539 def RefreshEditMenu(self): +00540 if self.FileMenu: +00541 if self.FileOpened.GetPageCount() > 0: +00542 undo, redo = self.ManagerManager.GetCurrentBufferState() +00543 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, undo) +00544 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, redo) +00545 else: +00546 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, False) +00547 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, False) +00548 +00549 def RefreshProfileMenu(self): +00550 if self.EditMenu: +00551 profile = self.ManagerManager.GetCurrentProfileName() +00552 edititem = self.EditMenu.FindItemById(wxID_OBJDICTEDITEDITMENUITEMS7) +00553 if edititem: +00554 length = self.AddMenu.GetMenuItemCount() +00555 for i in xrange(length-6): +00556 additem = self.AddMenu.FindItemByPosition(6) +00557 self.AddMenu.Delete(additem.GetId()) +00558 if profile not in ("None", "DS-301"): +00559 edititem.SetText("%s Profile"%profile) +00560 edititem.Enable(True) +00561 self.AddMenu.AppendSeparator() +00562 for text, indexes in self.ManagerManager.GetCurrentSpecificMenu(): +00563 new_id = wx.NewId() +00564 self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) +00565 self.Bind(wx.EVT_MENU, self.GetProfileCallBackGetProfileCallBack(text), id=new_id) +00566 else: +00567 edititem.SetText("Other Profile") +00568 edititem.Enable(False) +00569 +00570 +00571 #------------------------------------------------------------------------------- +00572 # Buffer Functions +00573 #------------------------------------------------------------------------------- +00574 +00575 def RefreshBufferState(self): +00576 fileopened = self.ManagerManager.GetAllFilenames() +00577 for idx, filename in enumerate(fileopened): +00578 self.FileOpened.SetPageText(idx, filename) +00579 self.RefreshEditMenuRefreshEditMenu() +00580 self.RefreshTitleRefreshTitle() +00581 +00582 def OnUndoMenu(self, event): +00583 self.ManagerManager.LoadCurrentPrevious() +00584 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00585 self.RefreshBufferStateRefreshBufferState() +00586 event.Skip() +00587 +00588 def OnRedoMenu(self, event): +00589 self.ManagerManager.LoadCurrentNext() +00590 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00591 self.RefreshBufferStateRefreshBufferState() +00592 event.Skip() +00593 +00594 +00595 #------------------------------------------------------------------------------- +00596 # Load and Save Funtions +00597 #------------------------------------------------------------------------------- +00598 +00599 def OnNewMenu(self, event): +00600 self.FilePathFilePath = "" +00601 dialog = CreateNodeDialog(self, ScriptDirectory) +00602 if dialog.ShowModal() == wxID_OK: +00603 name, id, nodetype, description = dialog.GetValues() +00604 profile, filepath = dialog.GetProfile() +00605 NMT = dialog.GetNMTManagement() +00606 options = dialog.GetOptions() +00607 result = self.ManagerManager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) +00608 if type(result) == IntType: +00609 new_editingpanel = EditingPanel(self, self.ManagerManager) +00610 new_editingpanel.SetIndex(result) +00611 self.FileOpened.AddPage(new_editingpanel, "") +00612 self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) +00613 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) +00614 if "DS302" in options: +00615 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) +00616 self.RefreshBufferStateRefreshBufferState() +00617 self.RefreshProfileMenuRefreshProfileMenu() +00618 self.RefreshMainMenuRefreshMainMenu() +00619 else: +00620 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR) +00621 message.ShowModal() +00622 message.Destroy() +00623 event.Skip() +00624 +00625 def OnOpenMenu(self, event): +00626 filepath = self.ManagerManager.GetCurrentFilePath() +00627 if filepath != "": +00628 directory = os.path.dirname(filepath) +00629 else: +00630 directory = os.getcwd() +00631 dialog = wxFileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR) +00632 if dialog.ShowModal() == wxID_OK: +00633 filepath = dialog.GetPath() +00634 if os.path.isfile(filepath): +00635 result = self.ManagerManager.OpenFileInCurrent(filepath) +00636 if type(result) == IntType: +00637 new_editingpanel = EditingPanel(self, self.ManagerManager) +00638 new_editingpanel.SetIndex(result) +00639 self.FileOpened.AddPage(new_editingpanel, "") +00640 self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) +00641 if self.ManagerManager.CurrentDS302Defined(): +00642 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True) +00643 else: +00644 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False) +00645 self.RefreshEditMenuRefreshEditMenu() +00646 self.RefreshBufferStateRefreshBufferState() +00647 self.RefreshProfileMenuRefreshProfileMenu() +00648 self.RefreshMainMenuRefreshMainMenu() +00649 else: +00650 message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR) +00651 message.ShowModal() +00652 message.Destroy() +00653 dialog.Destroy() +00654 event.Skip() +00655 +00656 def OnSaveMenu(self, event): +00657 self.SaveSave() +00658 event.Skip() +00659 +00660 def OnSaveAsMenu(self, event): +00661 self.SaveAsSaveAs() +00662 event.Skip() +00663 +00664 def Save(self): +00665 result = self.ManagerManager.SaveCurrentInFile() +00666 if not result: +00667 self.SaveAsSaveAs() +00668 elif type(result) != StringType: +00669 self.RefreshBufferStateRefreshBufferState() +00670 else: +00671 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00672 message.ShowModal() +00673 message.Destroy() +00674 +00675 def SaveAs(self): +00676 filepath = self.ManagerManager.GetCurrentFilePath() +00677 if filepath != "": +00678 directory, filename = os.path.split(filepath) +00679 else: +00680 directory, filename = os.getcwd(), "%s.od"%self.ManagerManager.GetCurrentNodeInfos()[0] +00681 dialog = wxFileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) +00682 if dialog.ShowModal() == wxID_OK: +00683 filepath = dialog.GetPath() +00684 if os.path.isdir(os.path.dirname(filepath)): +00685 result = self.ManagerManager.SaveCurrentInFile(filepath) +00686 if type(result) != StringType: +00687 self.RefreshBufferStateRefreshBufferState() +00688 else: +00689 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00690 message.ShowModal() +00691 message.Destroy() +00692 else: +00693 message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) +00694 message.ShowModal() +00695 message.Destroy() +00696 dialog.Destroy() +00697 +00698 def OnCloseMenu(self, event): +00699 answer = wxID_YES +00700 result = self.ManagerManager.CloseCurrent() +00701 if not result: +00702 dialog = wxMessageDialog(self, "There are changes, do you want to save?", "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION) +00703 answer = dialog.ShowModal() +00704 dialog.Destroy() +00705 if answer == wxID_YES: +00706 self.OnSaveMenuOnSaveMenu(event) +00707 if self.ManagerManager.CurrentIsSaved(): +00708 self.ManagerManager.CloseCurrent() +00709 elif answer == wxID_NO: +00710 self.ManagerManager.CloseCurrent(True) +00711 if self.FileOpened.GetPageCount() > self.ManagerManager.GetBufferNumber(): +00712 current = self.FileOpened.GetSelection() +00713 self.FileOpened.DeletePage(current) +00714 if self.FileOpened.GetPageCount() > 0: +00715 self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) +00716 self.RefreshBufferStateRefreshBufferState() +00717 self.RefreshMainMenuRefreshMainMenu() +00718 event.Skip() +00719 +00720 +00721 #------------------------------------------------------------------------------- +00722 # Import and Export Functions +00723 #------------------------------------------------------------------------------- +00724 +00725 def OnImportEDSMenu(self, event): +00726 dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR) +00727 if dialog.ShowModal() == wxID_OK: +00728 filepath = dialog.GetPath() +00729 if os.path.isfile(filepath): +00730 result = self.ManagerManager.ImportCurrentFromEDSFile(filepath) +00731 if type(result) == IntType: +00732 new_editingpanel = EditingPanel(self, self.ManagerManager) +00733 new_editingpanel.SetIndex(result) +00734 self.FileOpened.AddPage(new_editingpanel, "") +00735 self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) +00736 self.RefreshBufferStateRefreshBufferState() +00737 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00738 self.RefreshProfileMenuRefreshProfileMenu() +00739 self.RefreshMainMenuRefreshMainMenu() +00740 message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION) +00741 message.ShowModal() +00742 message.Destroy() +00743 else: +00744 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00745 message.ShowModal() +00746 message.Destroy() +00747 else: +00748 message = wxMessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wxOK|wxICON_ERROR) +00749 message.ShowModal() +00750 message.Destroy() +00751 dialog.Destroy() +00752 event.Skip() +00753 +00754 +00755 def OnExportEDSMenu(self, event): +00756 dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.ManagerManager.GetCurrentNodeInfos()[0], "EDS files (*.eds)|*.eds|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) +00757 if dialog.ShowModal() == wxID_OK: +00758 filepath = dialog.GetPath() +00759 if os.path.isdir(os.path.dirname(filepath)): +00760 path, extend = os.path.splitext(filepath) +00761 if extend in ("", "."): +00762 filepath = path + ".eds" +00763 result = self.ManagerManager.ExportCurrentToEDSFile(filepath) +00764 if not result: +00765 message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) +00766 message.ShowModal() +00767 message.Destroy() +00768 else: +00769 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00770 message.ShowModal() +00771 message.Destroy() +00772 else: +00773 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) +00774 message.ShowModal() +00775 message.Destroy() +00776 dialog.Destroy() +00777 event.Skip() +00778 +00779 def OnExportCMenu(self, event): +00780 dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.ManagerManager.GetCurrentNodeInfos()[0], "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR) +00781 if dialog.ShowModal() == wxID_OK: +00782 filepath = dialog.GetPath() +00783 if os.path.isdir(os.path.dirname(filepath)): +00784 path, extend = os.path.splitext(filepath) +00785 if extend in ("", "."): +00786 filepath = path + ".c" +00787 result = self.ManagerManager.ExportCurrentToCFile(filepath) +00788 if not result: +00789 message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION) +00790 message.ShowModal() +00791 message.Destroy() +00792 else: +00793 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00794 message.ShowModal() +00795 message.Destroy() +00796 else: +00797 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR) +00798 message.ShowModal() +00799 message.Destroy() +00800 dialog.Destroy() +00801 event.Skip() +00802 +00803 #------------------------------------------------------------------------------- +00804 # Editing Profiles functions +00805 #------------------------------------------------------------------------------- +00806 +00807 def OnCommunicationMenu(self, event): +00808 dictionary,current = self.ManagerManager.GetCurrentCommunicationLists() +00809 self.EditProfileEditProfile("Edit DS-301 Profile", dictionary, current) +00810 event.Skip() +00811 +00812 def OnOtherCommunicationMenu(self, event): +00813 dictionary,current = self.ManagerManager.GetCurrentDS302Lists() +00814 self.EditProfileEditProfile("Edit DS-301 Profile", dictionary, current) +00815 event.Skip() +00816 +00817 def OnEditProfileMenu(self, event): +00818 title = "Edit %s Profile"%self.ManagerManager.GetCurrentProfileName() +00819 dictionary,current = self.ManagerManager.GetCurrentProfileLists() +00820 self.EditProfileEditProfile(title, dictionary, current) +00821 event.Skip() +00822 +00823 def EditProfile(self, title, dictionary, current): +00824 dialog = CommunicationDialog(self) +00825 dialog.SetTitle(title) +00826 dialog.SetIndexDictionary(dictionary) +00827 dialog.SetCurrentList(current) +00828 dialog.RefreshLists() +00829 if dialog.ShowModal() == wxID_OK: +00830 new_profile = dialog.GetCurrentList() +00831 addinglist = [] +00832 removinglist = [] +00833 for index in new_profile: +00834 if index not in current: +00835 addinglist.append(index) +00836 for index in current: +00837 if index not in new_profile: +00838 removinglist.append(index) +00839 self.ManagerManager.ManageEntriesOfCurrent(addinglist, removinglist) +00840 self.ManagerManager.GenerateMapList() +00841 self.ManagerManager.BufferCurrentNode() +00842 self.RefreshBufferStateRefreshBufferState() +00843 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00844 dialog.Destroy() +00845 +00846 def GetProfileCallBack(self, text): +00847 def ProfileCallBack(event): +00848 self.ManagerManager.AddSpecificEntryToCurrent(text) +00849 self.RefreshBufferStateRefreshBufferState() +00850 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00851 event.Skip() +00852 return ProfileCallBack +00853 +00854 #------------------------------------------------------------------------------- +00855 # Edit Node informations function +00856 #------------------------------------------------------------------------------- +00857 +00858 def OnNodeInfosMenu(self, event): +00859 dialog = NodeInfosDialog(self) +00860 name, id, type, description = self.ManagerManager.GetCurrentNodeInfos() +00861 dialog.SetValues(name, id, type, description) +00862 if dialog.ShowModal() == wxID_OK: +00863 name, id, type, description = dialog.GetValues() +00864 self.ManagerManager.SetCurrentNodeInfos(name, id, type, description) +00865 self.RefreshBufferStateRefreshBufferState() +00866 self.RefreshProfileMenuRefreshProfileMenu() +00867 selected = self.FileOpened.GetSelection() +00868 if selected >= 0: +00869 window = self.FileOpened.GetPage(selected) +00870 window.RefreshTable() +00871 event.Skip() +00872 +00873 +00874 #------------------------------------------------------------------------------- +00875 # Add User Types and Variables +00876 #------------------------------------------------------------------------------- +00877 +00878 def AddMapVariable(self): +00879 index = self.ManagerManager.GetCurrentNextMapIndex() +00880 if index: +00881 dialog = MapVariableDialog(self) +00882 dialog.SetIndex(index) +00883 if dialog.ShowModal() == wxID_OK: +00884 index, name, struct, number = dialog.GetValues() +00885 result = self.ManagerManager.AddMapVariableToCurrent(index, name, struct, number) +00886 if type(result) != StringType: +00887 self.RefreshBufferStateRefreshBufferState() +00888 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00889 else: +00890 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00891 message.ShowModal() +00892 message.Destroy() +00893 dialog.Destroy() +00894 else: +00895 message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR) +00896 message.ShowModal() +00897 message.Destroy() +00898 +00899 def AddUserType(self): +00900 dialog = UserTypeDialog(self) +00901 dialog.SetTypeList(self.ManagerManager.GetCustomisableTypes()) +00902 if dialog.ShowModal() == wxID_OK: +00903 type, min, max, length = dialog.GetValues() +00904 result = self.ManagerManager.AddUserTypeToCurrent(type, min, max, length) +00905 if not result: +00906 self.RefreshBufferStateRefreshBufferState() +00907 self.RefreshCurrentIndexListRefreshCurrentIndexList() +00908 else: +00909 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR) +00910 message.ShowModal() +00911 message.Destroy() +00912 dialog.Destroy() +00913 +00914 +00915 #------------------------------------------------------------------------------- +00916 # Exception Handler +00917 #------------------------------------------------------------------------------- +00918 +00919 Max_Traceback_List_Size = 20 +00920 +00921 def Display_Exception_Dialog(e_type,e_value,e_tb): +00922 trcbck_lst = [] +00923 for i,line in enumerate(traceback.extract_tb(e_tb)): +00924 trcbck = " " + str(i+1) + ". " +00925 if line[0].find(os.getcwd()) == -1: +00926 trcbck += "file : " + str(line[0]) + ", " +00927 else: +00928 trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " +00929 trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) +00930 trcbck_lst.append(trcbck) +00931 +00932 # Allow clicking.... +00933 cap = wx.Window_GetCapture() +00934 if cap: +00935 cap.ReleaseMouse() +00936 +00937 dlg = wx.SingleChoiceDialog(None, +00938 """ +00939 An error happens. +00940 +00941 Click on OK for saving an error report. +00942 +00943 Please contact LOLITech at: +00944 +33 (0)3 29 52 95 67 +00945 bugs_objdictedit@lolitech.fr +00946 +00947 +00948 Error: +00949 """ + +00950 str(e_type) + " : " + str(e_value), +00951 "Error", +00952 trcbck_lst) +00953 try: +00954 res = (dlg.ShowModal() == wx.ID_OK) +00955 finally: +00956 dlg.Destroy() +00957 +00958 return res +00959 +00960 def Display_Error_Dialog(e_value): +00961 message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR) +00962 message.ShowModal() +00963 message.Destroy() +00964 +00965 def get_last_traceback(tb): +00966 while tb.tb_next: +00967 tb = tb.tb_next +00968 return tb +00969 +00970 +00971 def format_namespace(d, indent=' '): +00972 return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) +00973 +00974 +00975 ignored_exceptions = [] # a problem with a line in a module is only reported once per session +00976 +00977 def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): +00978 +00979 def handle_exception(e_type, e_value, e_traceback): +00980 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func +00981 last_tb = get_last_traceback(e_traceback) +00982 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) +00983 if str(e_value).startswith("!!!"): +00984 Display_Error_Dialog(e_value) +00985 elif ex not in ignored_exceptions: +00986 ignored_exceptions.append(ex) +00987 result = Display_Exception_Dialog(e_type,e_value,e_traceback) +00988 if result: +00989 info = { +00990 'app-title' : wx.GetApp().GetAppName(), # app_title +00991 'app-version' : app_version, +00992 'wx-version' : wx.VERSION_STRING, +00993 'wx-platform' : wx.Platform, +00994 'python-version' : platform.python_version(), #sys.version.split()[0], +00995 'platform' : platform.platform(), +00996 'e-type' : e_type, +00997 'e-value' : e_value, +00998 'date' : time.ctime(), +00999 'cwd' : os.getcwd(), +01000 } +01001 if e_traceback: +01002 info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) +01003 last_tb = get_last_traceback(e_traceback) +01004 exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred +01005 info['locals'] = format_namespace(exception_locals) +01006 if 'self' in exception_locals: +01007 info['self'] = format_namespace(exception_locals['self'].__dict__) +01008 +01009 output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') +01010 lst = info.keys() +01011 lst.sort() +01012 for a in lst: +01013 output.write(a+":\n"+str(info[a])+"\n\n") +01014 +01015 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) +01016 sys.excepthook = handle_exception +01017 +01018 if __name__ == '__main__': +01019 app = wxPySimpleApp() +01020 wxInitAllImageHandlers() +01021 +01022 # Install a exception handle for bug reports +01023 wxAddExceptHook(os.getcwd(),__version__) +01024 +01025 frame = objdictedit(None) +01026 +01027 frame.Show() +01028 app.MainLoop() +