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