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