objdictgen/objdictedit.py
changeset 254 f2b0acb54e65
parent 245 d43ebbed895f
child 258 8f7725451453
equal deleted inserted replaced
253:bf58ce630b88 254:f2b0acb54e65
    19 #
    19 #
    20 #You should have received a copy of the GNU Lesser General Public
    20 #You should have received a copy of the GNU Lesser General Public
    21 #License along with this library; if not, write to the Free Software
    21 #License along with this library; if not, write to the Free Software
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 
    23 
    24 from wxPython.wx import *
       
    25 from wxPython.grid import *
       
    26 import wx
    24 import wx
    27 import wx.grid
       
    28 
    25 
    29 from types import *
    26 from types import *
    30 import os, re, platform, sys, time, traceback, getopt
    27 import os, re, platform, sys, time, traceback, getopt
    31 
    28 
    32 __version__ = "$Revision$"
    29 __version__ = "$Revision$"
    37 from subindextable import *
    34 from subindextable import *
    38 from commondialogs import *
    35 from commondialogs import *
    39 from doc_index.DS301_index import *
    36 from doc_index.DS301_index import *
    40 
    37 
    41 try:
    38 try:
    42     from wxPython.html import *
    39     import wx.html
    43 
    40 
    44     wxEVT_HTML_URL_CLICK = wxNewId()
    41     EVT_HTML_URL_CLICK = wx.NewId()
    45 
    42 
    46     def EVT_HTML_URL_CLICK(win, func):
    43     class HtmlWindowUrlClick(wx.PyEvent):
    47         win.Connect(-1, -1, wxEVT_HTML_URL_CLICK, func)
       
    48 
       
    49     class wxHtmlWindowUrlClick(wxPyEvent):
       
    50         def __init__(self, linkinfo):
    44         def __init__(self, linkinfo):
    51             wxPyEvent.__init__(self)
    45             wx.PyEvent.__init__(self)
    52             self.SetEventType(wxEVT_HTML_URL_CLICK)
    46             self.SetEventType(EVT_HTML_URL_CLICK)
    53             self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
    47             self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget())
    54 
    48             
    55     class wxUrlClickHtmlWindow(wxHtmlWindow):
    49     class UrlClickHtmlWindow(wx.html.HtmlWindow):
    56         """ HTML window that generates and OnLinkClicked event.
    50         """ HTML window that generates and OnLinkClicked event.
    57 
    51 
    58         Use this to avoid having to override HTMLWindow
    52         Use this to avoid having to override HTMLWindow
    59         """
    53         """
    60         def OnLinkClicked(self, linkinfo):
    54         def OnLinkClicked(self, linkinfo):
    61             wxPostEvent(self, wxHtmlWindowUrlClick(linkinfo))
    55             wx.PostEvent(self, HtmlWindowUrlClick(linkinfo))
       
    56         
       
    57         def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
       
    58             if event == HtmlWindowUrlClick:
       
    59                 self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler)
       
    60             else:
       
    61                 wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2)
    62     
    62     
    63 #-------------------------------------------------------------------------------
    63 #-------------------------------------------------------------------------------
    64 #                                Html Frame
    64 #                                Html Frame
    65 #-------------------------------------------------------------------------------
    65 #-------------------------------------------------------------------------------
    66 
    66 
    67     [wxID_HTMLFRAME, wxID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
    67     [ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)]
    68 
    68 
    69     class HtmlFrame(wx.Frame):
    69     class HtmlFrame(wx.Frame):
    70         def _init_ctrls(self, prnt):
    70         def _init_ctrls(self, prnt):
    71             # generated method, don't edit
    71             wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame',
    72             wx.Frame.__init__(self, id=wxID_HTMLFRAME, name='HtmlFrame',
       
    73                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
    72                   parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616),
    74                   style=wx.DEFAULT_FRAME_STYLE, title='')
    73                   style=wx.DEFAULT_FRAME_STYLE, title='')
    75             self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_HTMLFRAME)
    74             self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_HTMLFRAME)
    76             
    75             
    77             self.HtmlContent = wxUrlClickHtmlWindow(id=wxID_HTMLFRAMEHTMLCONTENT,
    76             self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT,
    78                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
    77                   name='HtmlContent', parent=self, pos=wx.Point(0, 0),
    79                   size=wx.Size(-1, -1), style=wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION)
    78                   size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION)
    80             EVT_HTML_URL_CLICK(self.HtmlContent, self.OnLinkClick)
    79             self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick)
    81 
    80 
    82         def __init__(self, parent, opened):
    81         def __init__(self, parent, opened):
    83             self._init_ctrls(parent)
    82             self._init_ctrls(parent)
    84             self.HtmlFrameOpened = opened
    83             self.HtmlFrameOpened = opened
    85         
    84         
    96         def OnLinkClick(self, event):
    95         def OnLinkClick(self, event):
    97             url = event.linkinfo[0]
    96             url = event.linkinfo[0]
    98             try:
    97             try:
    99                 import webbrowser
    98                 import webbrowser
   100             except ImportError:
    99             except ImportError:
   101                 wxMessageBox('Please point your browser at: %s' % url)
   100                 wx.MessageBox('Please point your browser at: %s' % url)
   102             else:
   101             else:
   103                 webbrowser.open(url)
   102                 webbrowser.open(url)
   104     
   103 
   105     Html_Window = True
   104     Html_Window = True
   106 except:
   105 except:
   107     Html_Window = False
   106     Html_Window = False
   108 
   107 
   109 def create(parent):
   108 def create(parent):
   127 
   126 
   128 filesOpen = args
   127 filesOpen = args
   129 ScriptDirectory = sys.path[0]
   128 ScriptDirectory = sys.path[0]
   130 
   129 
   131 
   130 
   132 [wxID_OBJDICTEDIT, wxID_OBJDICTEDITFILEOPENED, 
   131 [ID_OBJDICTEDIT, ID_OBJDICTEDITFILEOPENED, 
   133  wxID_OBJDICTEDITHELPBAR,
   132  ID_OBJDICTEDITHELPBAR,
   134 ] = [wx.NewId() for _init_ctrls in range(3)]
   133 ] = [wx.NewId() for _init_ctrls in range(3)]
   135 
   134 
   136 [wxID_OBJDICTEDITADDMENUITEMS0, wxID_OBJDICTEDITADDMENUITEMS1, 
   135 [ID_OBJDICTEDITADDMENUITEMS0, ID_OBJDICTEDITADDMENUITEMS1, 
   137  wxID_OBJDICTEDITADDMENUITEMS2, wxID_OBJDICTEDITADDMENUITEMS3, 
   136  ID_OBJDICTEDITADDMENUITEMS2, ID_OBJDICTEDITADDMENUITEMS3, 
   138  wxID_OBJDICTEDITADDMENUITEMS4, wxID_OBJDICTEDITADDMENUITEMS5, 
   137  ID_OBJDICTEDITADDMENUITEMS4, ID_OBJDICTEDITADDMENUITEMS5, 
   139 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
   138 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
   140 
   139 
   141 [wxID_OBJDICTEDITFILEMENUITEMS0, wxID_OBJDICTEDITFILEMENUITEMS1, 
   140 [ID_OBJDICTEDITFILEMENUITEMS0, ID_OBJDICTEDITFILEMENUITEMS1, 
   142  wxID_OBJDICTEDITFILEMENUITEMS2, wxID_OBJDICTEDITFILEMENUITEMS4, 
   141  ID_OBJDICTEDITFILEMENUITEMS2, ID_OBJDICTEDITFILEMENUITEMS4, 
   143  wxID_OBJDICTEDITFILEMENUITEMS5, wxID_OBJDICTEDITFILEMENUITEMS6, 
   142  ID_OBJDICTEDITFILEMENUITEMS5, ID_OBJDICTEDITFILEMENUITEMS6, 
   144  wxID_OBJDICTEDITFILEMENUITEMS7, wxID_OBJDICTEDITFILEMENUITEMS8,
   143  ID_OBJDICTEDITFILEMENUITEMS7, ID_OBJDICTEDITFILEMENUITEMS8,
   145  wxID_OBJDICTEDITFILEMENUITEMS9,
   144  ID_OBJDICTEDITFILEMENUITEMS9,
   146 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)]
   145 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)]
   147 
   146 
   148 [wxID_OBJDICTEDITEDITMENUITEMS0, wxID_OBJDICTEDITEDITMENUITEMS1, 
   147 [ID_OBJDICTEDITEDITMENUITEMS0, ID_OBJDICTEDITEDITMENUITEMS1, 
   149  wxID_OBJDICTEDITEDITMENUITEMS2, wxID_OBJDICTEDITEDITMENUITEMS4, 
   148  ID_OBJDICTEDITEDITMENUITEMS2, ID_OBJDICTEDITEDITMENUITEMS4, 
   150  wxID_OBJDICTEDITEDITMENUITEMS6, wxID_OBJDICTEDITEDITMENUITEMS7, 
   149  ID_OBJDICTEDITEDITMENUITEMS6, ID_OBJDICTEDITEDITMENUITEMS7, 
   151  wxID_OBJDICTEDITEDITMENUITEMS8, 
   150  ID_OBJDICTEDITEDITMENUITEMS8, 
   152 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
   151 ] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)]
   153 
   152 
   154 [wxID_OBJDICTEDITHELPMENUITEMS0, wxID_OBJDICTEDITHELPMENUITEMS1,
   153 [ID_OBJDICTEDITHELPMENUITEMS0, ID_OBJDICTEDITHELPMENUITEMS1,
   155  wxID_OBJDICTEDITHELPMENUITEMS2,
   154  ID_OBJDICTEDITHELPMENUITEMS2,
   156 ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)]
   155 ] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)]
   157 
   156 
   158 class objdictedit(wx.Frame):
   157 class objdictedit(wx.Frame):
   159     def _init_coll_menuBar1_Menus(self, parent):
   158     def _init_coll_menuBar1_Menus(self, parent):
   160         # generated method, don't edit
       
   161 
       
   162         parent.Append(menu=self.FileMenu, title='File')
   159         parent.Append(menu=self.FileMenu, title='File')
   163         parent.Append(menu=self.EditMenu, title='Edit')
   160         parent.Append(menu=self.EditMenu, title='Edit')
   164         parent.Append(menu=self.AddMenu, title='Add')
   161         parent.Append(menu=self.AddMenu, title='Add')
   165         parent.Append(menu=self.HelpMenu, title='Help')
   162         parent.Append(menu=self.HelpMenu, title='Help')
   166 
   163 
   167     def _init_coll_EditMenu_Items(self, parent):
   164     def _init_coll_EditMenu_Items(self, parent):
   168         # generated method, don't edit
   165         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS4,
   169 
       
   170         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS4,
       
   171               kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
   166               kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R')
   172         parent.AppendSeparator()
   167         parent.AppendSeparator()
   173         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS1,
   168         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS1,
   174               kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
   169               kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z')
   175         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS0,
   170         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS0,
   176               kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
   171               kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y')
   177         parent.AppendSeparator()
   172         parent.AppendSeparator()
   178         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS6,
   173         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS6,
   179               kind=wx.ITEM_NORMAL, text='Node infos')
   174               kind=wx.ITEM_NORMAL, text='Node infos')
   180         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS2,
   175         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS2,
   181               kind=wx.ITEM_NORMAL, text='DS-301 Profile')
   176               kind=wx.ITEM_NORMAL, text='DS-301 Profile')
   182         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS8,
   177         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS8,
   183               kind=wx.ITEM_NORMAL, text='DS-302 Profile')
   178               kind=wx.ITEM_NORMAL, text='DS-302 Profile')
   184         parent.Append(help='', id=wxID_OBJDICTEDITEDITMENUITEMS7,
   179         parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS7,
   185               kind=wx.ITEM_NORMAL, text='Other Profile')
   180               kind=wx.ITEM_NORMAL, text='Other Profile')
   186         self.Bind(wx.EVT_MENU, self.OnUndoMenu,
   181         self.Bind(wx.EVT_MENU, self.OnUndoMenu,
   187               id=wxID_OBJDICTEDITEDITMENUITEMS1)
   182               id=ID_OBJDICTEDITEDITMENUITEMS1)
   188         self.Bind(wx.EVT_MENU, self.OnRedoMenu,
   183         self.Bind(wx.EVT_MENU, self.OnRedoMenu,
   189               id=wxID_OBJDICTEDITEDITMENUITEMS0)
   184               id=ID_OBJDICTEDITEDITMENUITEMS0)
   190         self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
   185         self.Bind(wx.EVT_MENU, self.OnCommunicationMenu,
   191               id=wxID_OBJDICTEDITEDITMENUITEMS2)
   186               id=ID_OBJDICTEDITEDITMENUITEMS2)
   192         self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
   187         self.Bind(wx.EVT_MENU, self.OnRefreshMenu,
   193               id=wxID_OBJDICTEDITEDITMENUITEMS4)
   188               id=ID_OBJDICTEDITEDITMENUITEMS4)
   194         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
   189         self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu,
   195               id=wxID_OBJDICTEDITEDITMENUITEMS6)
   190               id=ID_OBJDICTEDITEDITMENUITEMS6)
   196         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
   191         self.Bind(wx.EVT_MENU, self.OnEditProfileMenu,
   197               id=wxID_OBJDICTEDITEDITMENUITEMS7)
   192               id=ID_OBJDICTEDITEDITMENUITEMS7)
   198         self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
   193         self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu,
   199               id=wxID_OBJDICTEDITEDITMENUITEMS8)
   194               id=ID_OBJDICTEDITEDITMENUITEMS8)
   200 
   195 
   201     def _init_coll_HelpMenu_Items(self, parent):
   196     def _init_coll_HelpMenu_Items(self, parent):
   202         # generated method, don't edit
   197         parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS0,
   203 
       
   204         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS0,
       
   205               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
   198               kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1')
   206         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
   199         self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu,
   207               id=wxID_OBJDICTEDITHELPMENUITEMS0)
   200               id=ID_OBJDICTEDITHELPMENUITEMS0)
   208         parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS1,
   201         parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS1,
   209               kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
   202               kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2')
   210         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
   203         self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu,
   211               id=wxID_OBJDICTEDITHELPMENUITEMS1)
   204               id=ID_OBJDICTEDITHELPMENUITEMS1)
   212         if Html_Window:
   205         if Html_Window:
   213             parent.Append(help='', id=wxID_OBJDICTEDITHELPMENUITEMS2,
   206             parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS2,
   214                   kind=wx.ITEM_NORMAL, text='About')
   207                   kind=wx.ITEM_NORMAL, text='About')
   215             self.Bind(wx.EVT_MENU, self.OnAboutMenu,
   208             self.Bind(wx.EVT_MENU, self.OnAboutMenu,
   216                   id=wxID_OBJDICTEDITHELPMENUITEMS2)
   209                   id=ID_OBJDICTEDITHELPMENUITEMS2)
   217 
   210 
   218     def _init_coll_FileMenu_Items(self, parent):
   211     def _init_coll_FileMenu_Items(self, parent):
   219         # generated method, don't edit
   212         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS5,
   220 
       
   221         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS5,
       
   222               kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
   213               kind=wx.ITEM_NORMAL, text='New\tCTRL+N')
   223         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS0,
   214         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS0,
   224               kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
   215               kind=wx.ITEM_NORMAL, text='Open\tCTRL+O')
   225         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS1,
   216         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS1,
   226               kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
   217               kind=wx.ITEM_NORMAL, text='Save\tCTRL+S')
   227         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS6,
   218         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS6,
   228               kind=wx.ITEM_NORMAL, text='Save As...\tALT+S')
   219               kind=wx.ITEM_NORMAL, text='Save As...\tALT+S')
   229         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS2,
   220         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS2,
   230               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
   221               kind=wx.ITEM_NORMAL, text='Close\tCTRL+W')
   231         parent.AppendSeparator()
   222         parent.AppendSeparator()
   232         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS7,
   223         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS7,
   233               kind=wx.ITEM_NORMAL, text='Import EDS file')
   224               kind=wx.ITEM_NORMAL, text='Import EDS file')
   234         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS9,
   225         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS9,
   235               kind=wx.ITEM_NORMAL, text='Export to EDS file')
   226               kind=wx.ITEM_NORMAL, text='Export to EDS file')
   236         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS8,
   227         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS8,
   237               kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B')
   228               kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B')
   238         parent.AppendSeparator()
   229         parent.AppendSeparator()
   239         parent.Append(help='', id=wxID_OBJDICTEDITFILEMENUITEMS4,
   230         parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS4,
   240               kind=wx.ITEM_NORMAL, text='Exit')
   231               kind=wx.ITEM_NORMAL, text='Exit')
   241         self.Bind(wx.EVT_MENU, self.OnOpenMenu,
   232         self.Bind(wx.EVT_MENU, self.OnOpenMenu,
   242               id=wxID_OBJDICTEDITFILEMENUITEMS0)
   233               id=ID_OBJDICTEDITFILEMENUITEMS0)
   243         self.Bind(wx.EVT_MENU, self.OnSaveMenu,
   234         self.Bind(wx.EVT_MENU, self.OnSaveMenu,
   244               id=wxID_OBJDICTEDITFILEMENUITEMS1)
   235               id=ID_OBJDICTEDITFILEMENUITEMS1)
   245         self.Bind(wx.EVT_MENU, self.OnCloseMenu,
   236         self.Bind(wx.EVT_MENU, self.OnCloseMenu,
   246               id=wxID_OBJDICTEDITFILEMENUITEMS2)
   237               id=ID_OBJDICTEDITFILEMENUITEMS2)
   247         self.Bind(wx.EVT_MENU, self.OnQuitMenu,
   238         self.Bind(wx.EVT_MENU, self.OnQuitMenu,
   248               id=wxID_OBJDICTEDITFILEMENUITEMS4)
   239               id=ID_OBJDICTEDITFILEMENUITEMS4)
   249         self.Bind(wx.EVT_MENU, self.OnNewMenu,
   240         self.Bind(wx.EVT_MENU, self.OnNewMenu,
   250               id=wxID_OBJDICTEDITFILEMENUITEMS5)
   241               id=ID_OBJDICTEDITFILEMENUITEMS5)
   251         self.Bind(wx.EVT_MENU, self.OnSaveAsMenu,
   242         self.Bind(wx.EVT_MENU, self.OnSaveAsMenu,
   252               id=wxID_OBJDICTEDITFILEMENUITEMS6)
   243               id=ID_OBJDICTEDITFILEMENUITEMS6)
   253         self.Bind(wx.EVT_MENU, self.OnImportEDSMenu,
   244         self.Bind(wx.EVT_MENU, self.OnImportEDSMenu,
   254               id=wxID_OBJDICTEDITFILEMENUITEMS7)
   245               id=ID_OBJDICTEDITFILEMENUITEMS7)
   255         self.Bind(wx.EVT_MENU, self.OnExportCMenu,
   246         self.Bind(wx.EVT_MENU, self.OnExportCMenu,
   256               id=wxID_OBJDICTEDITFILEMENUITEMS8)
   247               id=ID_OBJDICTEDITFILEMENUITEMS8)
   257         self.Bind(wx.EVT_MENU, self.OnExportEDSMenu,
   248         self.Bind(wx.EVT_MENU, self.OnExportEDSMenu,
   258               id=wxID_OBJDICTEDITFILEMENUITEMS9)
   249               id=ID_OBJDICTEDITFILEMENUITEMS9)
   259 
   250 
   260     def _init_coll_AddMenu_Items(self, parent):
   251     def _init_coll_AddMenu_Items(self, parent):
   261         # generated method, don't edit
   252         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS0,
   262 
       
   263         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS0,
       
   264               kind=wx.ITEM_NORMAL, text='SDO Server')
   253               kind=wx.ITEM_NORMAL, text='SDO Server')
   265         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS1,
   254         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS1,
   266               kind=wx.ITEM_NORMAL, text='SDO Client')
   255               kind=wx.ITEM_NORMAL, text='SDO Client')
   267         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS2,
   256         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS2,
   268               kind=wx.ITEM_NORMAL, text='PDO Transmit')
   257               kind=wx.ITEM_NORMAL, text='PDO Transmit')
   269         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS3,
   258         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS3,
   270               kind=wx.ITEM_NORMAL, text='PDO Receive')
   259               kind=wx.ITEM_NORMAL, text='PDO Receive')
   271         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS4,
   260         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS4,
   272               kind=wx.ITEM_NORMAL, text='Map Variable')
   261               kind=wx.ITEM_NORMAL, text='Map Variable')
   273         parent.Append(help='', id=wxID_OBJDICTEDITADDMENUITEMS5,
   262         parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS5,
   274               kind=wx.ITEM_NORMAL, text='User Type')
   263               kind=wx.ITEM_NORMAL, text='User Type')
   275         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
   264         self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu,
   276               id=wxID_OBJDICTEDITADDMENUITEMS0)
   265               id=ID_OBJDICTEDITADDMENUITEMS0)
   277         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
   266         self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu,
   278               id=wxID_OBJDICTEDITADDMENUITEMS1)
   267               id=ID_OBJDICTEDITADDMENUITEMS1)
   279         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
   268         self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu,
   280               id=wxID_OBJDICTEDITADDMENUITEMS2)
   269               id=ID_OBJDICTEDITADDMENUITEMS2)
   281         self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
   270         self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu,
   282               id=wxID_OBJDICTEDITADDMENUITEMS3)
   271               id=ID_OBJDICTEDITADDMENUITEMS3)
   283         self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
   272         self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu,
   284               id=wxID_OBJDICTEDITADDMENUITEMS4)
   273               id=ID_OBJDICTEDITADDMENUITEMS4)
   285         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
   274         self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu,
   286               id=wxID_OBJDICTEDITADDMENUITEMS5)
   275               id=ID_OBJDICTEDITADDMENUITEMS5)
   287 
   276 
   288     def _init_coll_HelpBar_Fields(self, parent):
   277     def _init_coll_HelpBar_Fields(self, parent):
   289         # generated method, don't edit
       
   290         parent.SetFieldsCount(3)
   278         parent.SetFieldsCount(3)
   291 
   279 
   292         parent.SetStatusText(number=0, text='')
   280         parent.SetStatusText(number=0, text='')
   293         parent.SetStatusText(number=1, text='')
   281         parent.SetStatusText(number=1, text='')
   294         parent.SetStatusText(number=2, text='')
   282         parent.SetStatusText(number=2, text='')
   295 
   283 
   296         parent.SetStatusWidths([100, 110, -1])
   284         parent.SetStatusWidths([100, 110, -1])
   297 
   285 
   298     def _init_utils(self):
   286     def _init_utils(self):
   299         # generated method, don't edit
       
   300         self.menuBar1 = wx.MenuBar()
   287         self.menuBar1 = wx.MenuBar()
   301         self.menuBar1.SetEvtHandlerEnabled(True)
   288         self.menuBar1.SetEvtHandlerEnabled(True)
   302 
   289 
   303         self.FileMenu = wx.Menu(title='')
   290         self.FileMenu = wx.Menu(title='')
   304 
       
   305         self.EditMenu = wx.Menu(title='')
   291         self.EditMenu = wx.Menu(title='')
   306 
       
   307         self.AddMenu = wx.Menu(title='')
   292         self.AddMenu = wx.Menu(title='')
   308 
       
   309         self.HelpMenu = wx.Menu(title='')
   293         self.HelpMenu = wx.Menu(title='')
   310 
   294 
   311         self._init_coll_menuBar1_Menus(self.menuBar1)
   295         self._init_coll_menuBar1_Menus(self.menuBar1)
   312         self._init_coll_FileMenu_Items(self.FileMenu)
   296         self._init_coll_FileMenu_Items(self.FileMenu)
   313         self._init_coll_EditMenu_Items(self.EditMenu)
   297         self._init_coll_EditMenu_Items(self.EditMenu)
   314         self._init_coll_AddMenu_Items(self.AddMenu)
   298         self._init_coll_AddMenu_Items(self.AddMenu)
   315         self._init_coll_HelpMenu_Items(self.HelpMenu)
   299         self._init_coll_HelpMenu_Items(self.HelpMenu)
   316 
   300 
   317     def _init_ctrls(self, prnt):
   301     def _init_ctrls(self, prnt):
   318         # generated method, don't edit
   302         wx.Frame.__init__(self, id=ID_OBJDICTEDIT, name='objdictedit',
   319         wx.Frame.__init__(self, id=wxID_OBJDICTEDIT, name='objdictedit',
       
   320               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
   303               parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700),
   321               style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit')
   304               style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit')
   322         self._init_utils()
   305         self._init_utils()
   323         self.SetClientSize(wx.Size(1000, 700))
   306         self.SetClientSize(wx.Size(1000, 700))
   324         self.SetMenuBar(self.menuBar1)
   307         self.SetMenuBar(self.menuBar1)
   325         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=wxID_OBJDICTEDIT)
   308         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_OBJDICTEDIT)
   326 
   309 
   327         self.FileOpened = wx.Notebook(id=wxID_OBJDICTEDITFILEOPENED,
   310         self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED,
   328               name='FileOpened', parent=self, pos=wx.Point(0, 0),
   311               name='FileOpened', parent=self, pos=wx.Point(0, 0),
   329               size=wx.Size(0, 0), style=0)
   312               size=wx.Size(0, 0), style=0)
   330         self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
   313         self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
   331               self.OnFileSelectedChanged, id=wxID_OBJDICTEDITFILEOPENED)
   314               self.OnFileSelectedChanged, id=ID_OBJDICTEDITFILEOPENED)
   332 
   315 
   333         self.HelpBar = wx.StatusBar(id=wxID_OBJDICTEDITHELPBAR, name='HelpBar',
   316         self.HelpBar = wx.StatusBar(id=ID_OBJDICTEDITHELPBAR, name='HelpBar',
   334               parent=self, style=wxST_SIZEGRIP)
   317               parent=self, style=wx.ST_SIZEGRIP)
   335         self._init_coll_HelpBar_Fields(self.HelpBar)
   318         self._init_coll_HelpBar_Fields(self.HelpBar)
   336         self.SetStatusBar(self.HelpBar)
   319         self.SetStatusBar(self.HelpBar)
   337 
   320 
   338     def __init__(self, parent):
   321     def __init__(self, parent):
   339         self._init_ctrls(parent)
   322         self._init_ctrls(parent)
   350             window = self.FileOpened.GetPage(0)
   333             window = self.FileOpened.GetPage(0)
   351             if window:
   334             if window:
   352                 self.Manager.ChangeCurrentNode(window.GetIndex())
   335                 self.Manager.ChangeCurrentNode(window.GetIndex())
   353                 self.FileOpened.SetSelection(0)
   336                 self.FileOpened.SetSelection(0)
   354         if self.Manager.CurrentDS302Defined(): 
   337         if self.Manager.CurrentDS302Defined(): 
   355             self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
   338             self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True)
   356         else:
   339         else:
   357             self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
   340             self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False)
   358         self.RefreshEditMenu()
   341         self.RefreshEditMenu()
   359         self.RefreshBufferState()
   342         self.RefreshBufferState()
   360         self.RefreshProfileMenu()
   343         self.RefreshProfileMenu()
   361         self.RefreshTitle()
   344         self.RefreshTitle()
   362         self.RefreshMainMenu()
   345         self.RefreshMainMenu()
   417             if result:
   400             if result:
   418                 find_index = True
   401                 find_index = True
   419                 index, subIndex = result
   402                 index, subIndex = result
   420                 result = OpenPDFDocIndex(index, ScriptDirectory)
   403                 result = OpenPDFDocIndex(index, ScriptDirectory)
   421                 if type(result) == StringType:
   404                 if type(result) == StringType:
   422                     message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
   405                     message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   423                     message.ShowModal()
   406                     message.ShowModal()
   424                     message.Destroy()
   407                     message.Destroy()
   425         if not find_index:
   408         if not find_index:
   426             result = OpenPDFDocIndex(None, ScriptDirectory)
   409             result = OpenPDFDocIndex(None, ScriptDirectory)
   427             if type(result) == StringType:
   410             if type(result) == StringType:
   428                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
   411                 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   429                 message.ShowModal()
   412                 message.ShowModal()
   430                 message.Destroy()
   413                 message.Destroy()
   431         event.Skip()
   414         event.Skip()
   432         
   415         
   433     def OnHelpCANFestivalMenu(self, event):
   416     def OnHelpCANFestivalMenu(self, event):
   452         self.Close()
   435         self.Close()
   453         event.Skip()
   436         event.Skip()
   454     
   437     
   455     def OnCloseFrame(self, event):
   438     def OnCloseFrame(self, event):
   456         if self.Manager.OneFileHasChanged():
   439         if self.Manager.OneFileHasChanged():
   457             dialog = wxMessageDialog(self, "There are changes, do you want to save?",  "Close Application", wxYES_NO|wxCANCEL|wxICON_QUESTION)
   440             dialog = wx.MessageDialog(self, "There are changes, do you want to save?",  "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   458             answer = dialog.ShowModal()
   441             answer = dialog.ShowModal()
   459             dialog.Destroy()
   442             dialog.Destroy()
   460             if answer == wxID_YES:
   443             if answer == wx.ID_YES:
   461                 self.Manager.ChangeCurrentNode(0)
   444                 self.Manager.ChangeCurrentNode(0)
   462                 for i in xrange(self.FileOpened.GetPageCount()):
   445                 for i in xrange(self.FileOpened.GetPageCount()):
   463                     window = self.FileOpened.GetPage(i)
   446                     window = self.FileOpened.GetPage(i)
   464                     self.Manager.ChangeCurrentNode(window.GetIndex())
   447                     self.Manager.ChangeCurrentNode(window.GetIndex())
   465                     if self.Manager.CurrentIsSaved():
   448                     if self.Manager.CurrentIsSaved():
   466                         self.Manager.CloseCurrent()
   449                         self.Manager.CloseCurrent()
   467                     else:
   450                     else:
   468                         self.Save()
   451                         self.Save()
   469                         self.Manager.CloseCurrent(True)
   452                         self.Manager.CloseCurrent(True)
   470                 event.Skip()
   453                 event.Skip()
   471             elif answer == wxID_NO:
   454             elif answer == wx.ID_NO:
   472                 for i in xrange(self.FileOpened.GetPageCount()):
   455                 for i in xrange(self.FileOpened.GetPageCount()):
   473                     self.Manager.CloseCurrent(True)
   456                     self.Manager.CloseCurrent(True)
   474                 wxCallAfter(self.Close)
   457                 wx.CallAfter(self.Close)
   475                 event.Skip()
   458                 event.Skip()
   476         else:
   459         else:
   477             event.Skip()
   460             event.Skip()
   478 
   461 
   479 #-------------------------------------------------------------------------------
   462 #-------------------------------------------------------------------------------
   531     def RefreshMainMenu(self):
   514     def RefreshMainMenu(self):
   532         if self.FileMenu:
   515         if self.FileMenu:
   533             if self.FileOpened.GetPageCount() > 0:
   516             if self.FileOpened.GetPageCount() > 0:
   534                 self.menuBar1.EnableTop(1, True)
   517                 self.menuBar1.EnableTop(1, True)
   535                 self.menuBar1.EnableTop(2, True)
   518                 self.menuBar1.EnableTop(2, True)
   536                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, True)
   519                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, True)
   537                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, True)
   520                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, True)
   538                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, True)
   521                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, True)
   539                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, True)
   522                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, True)
   540                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, True)
   523                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, True)
   541             else:
   524             else:
   542                 self.menuBar1.EnableTop(1, False)      
   525                 self.menuBar1.EnableTop(1, False)      
   543                 self.menuBar1.EnableTop(2, False)
   526                 self.menuBar1.EnableTop(2, False)
   544                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS1, False)
   527                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, False)
   545                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS2, False)
   528                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, False)
   546                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS6, False)
   529                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, False)
   547                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS8, False)
   530                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, False)
   548                 self.FileMenu.Enable(wxID_OBJDICTEDITFILEMENUITEMS9, False)
   531                 self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, False)
   549 
   532 
   550     def RefreshEditMenu(self):
   533     def RefreshEditMenu(self):
   551         if self.FileMenu:
   534         if self.FileMenu:
   552             if self.FileOpened.GetPageCount() > 0:
   535             if self.FileOpened.GetPageCount() > 0:
   553                 undo, redo = self.Manager.GetCurrentBufferState()
   536                 undo, redo = self.Manager.GetCurrentBufferState()
   554                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, undo)
   537                 self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, undo)
   555                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, redo)
   538                 self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, redo)
   556             else:
   539             else:
   557                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS1, False)
   540                 self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, False)
   558                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS0, False)
   541                 self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, False)
   559 
   542 
   560     def RefreshProfileMenu(self):
   543     def RefreshProfileMenu(self):
   561         if self.EditMenu:
   544         if self.EditMenu:
   562             profile = self.Manager.GetCurrentProfileName()
   545             profile = self.Manager.GetCurrentProfileName()
   563             edititem = self.EditMenu.FindItemById(wxID_OBJDICTEDITEDITMENUITEMS7)
   546             edititem = self.EditMenu.FindItemById(ID_OBJDICTEDITEDITMENUITEMS7)
   564             if edititem:
   547             if edititem:
   565                 length = self.AddMenu.GetMenuItemCount()
   548                 length = self.AddMenu.GetMenuItemCount()
   566                 for i in xrange(length-6):
   549                 for i in xrange(length-6):
   567                     additem = self.AddMenu.FindItemByPosition(6)
   550                     additem = self.AddMenu.FindItemByPosition(6)
   568                     self.AddMenu.Delete(additem.GetId())
   551                     self.AddMenu.Delete(additem.GetId())
   608 #-------------------------------------------------------------------------------
   591 #-------------------------------------------------------------------------------
   609 
   592 
   610     def OnNewMenu(self, event):
   593     def OnNewMenu(self, event):
   611         self.FilePath = ""
   594         self.FilePath = ""
   612         dialog = CreateNodeDialog(self, ScriptDirectory)
   595         dialog = CreateNodeDialog(self, ScriptDirectory)
   613         if dialog.ShowModal() == wxID_OK:
   596         if dialog.ShowModal() == wx.ID_OK:
   614             name, id, nodetype, description = dialog.GetValues()
   597             name, id, nodetype, description = dialog.GetValues()
   615             profile, filepath = dialog.GetProfile()
   598             profile, filepath = dialog.GetProfile()
   616             NMT = dialog.GetNMTManagement()
   599             NMT = dialog.GetNMTManagement()
   617             options = dialog.GetOptions()
   600             options = dialog.GetOptions()
   618             result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options)
   601             result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options)
   619             if type(result) == IntType:
   602             if type(result) == IntType:
   620                 new_editingpanel = EditingPanel(self, self.Manager)
   603                 new_editingpanel = EditingPanel(self, self.Manager)
   621                 new_editingpanel.SetIndex(result)
   604                 new_editingpanel.SetIndex(result)
   622                 self.FileOpened.AddPage(new_editingpanel, "")
   605                 self.FileOpened.AddPage(new_editingpanel, "")
   623                 self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   606                 self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   624                 self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
   607                 self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False)
   625                 if "DS302" in options:
   608                 if "DS302" in options:
   626                     self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
   609                     self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True)
   627                 self.RefreshBufferState()
   610                 self.RefreshBufferState()
   628                 self.RefreshProfileMenu()
   611                 self.RefreshProfileMenu()
   629                 self.RefreshMainMenu()
   612                 self.RefreshMainMenu()
   630             else:
   613             else:
   631                 message = wxMessageDialog(self, result, "ERROR", wxOK|wxICON_ERROR)
   614                 message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR)
   632                 message.ShowModal()
   615                 message.ShowModal()
   633                 message.Destroy()
   616                 message.Destroy()
   634         event.Skip()
   617         event.Skip()
   635 
   618 
   636     def OnOpenMenu(self, event):
   619     def OnOpenMenu(self, event):
   637         filepath = self.Manager.GetCurrentFilePath()
   620         filepath = self.Manager.GetCurrentFilePath()
   638         if filepath != "":
   621         if filepath != "":
   639             directory = os.path.dirname(filepath)
   622             directory = os.path.dirname(filepath)
   640         else:
   623         else:
   641             directory = os.getcwd()
   624             directory = os.getcwd()
   642         dialog = wxFileDialog(self, "Choose a file", directory, "",  "OD files (*.od)|*.od|All files|*.*", wxOPEN|wxCHANGE_DIR)
   625         dialog = wx.FileDialog(self, "Choose a file", directory, "",  "OD files (*.od)|*.od|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
   643         if dialog.ShowModal() == wxID_OK:
   626         if dialog.ShowModal() == wx.ID_OK:
   644             filepath = dialog.GetPath()
   627             filepath = dialog.GetPath()
   645             if os.path.isfile(filepath):
   628             if os.path.isfile(filepath):
   646                 result = self.Manager.OpenFileInCurrent(filepath)
   629                 result = self.Manager.OpenFileInCurrent(filepath)
   647                 if type(result) == IntType:
   630                 if type(result) == IntType:
   648                     new_editingpanel = EditingPanel(self, self.Manager)
   631                     new_editingpanel = EditingPanel(self, self.Manager)
   649                     new_editingpanel.SetIndex(result)
   632                     new_editingpanel.SetIndex(result)
   650                     self.FileOpened.AddPage(new_editingpanel, "")
   633                     self.FileOpened.AddPage(new_editingpanel, "")
   651                     self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   634                     self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   652                     if self.Manager.CurrentDS302Defined(): 
   635                     if self.Manager.CurrentDS302Defined(): 
   653                         self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, True)
   636                         self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True)
   654                     else:
   637                     else:
   655                         self.EditMenu.Enable(wxID_OBJDICTEDITEDITMENUITEMS8, False)
   638                         self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False)
   656                     self.RefreshEditMenu()
   639                     self.RefreshEditMenu()
   657                     self.RefreshBufferState()
   640                     self.RefreshBufferState()
   658                     self.RefreshProfileMenu()
   641                     self.RefreshProfileMenu()
   659                     self.RefreshMainMenu()
   642                     self.RefreshMainMenu()
   660                 else:
   643                 else:
   661                     message = wxMessageDialog(self, e.args[0], "Error", wxOK|wxICON_ERROR)
   644                     message = wx.MessageDialog(self, e.args[0], "Error", wx.OK|wx.ICON_ERROR)
   662                     message.ShowModal()
   645                     message.ShowModal()
   663                     message.Destroy()
   646                     message.Destroy()
   664         dialog.Destroy()
   647         dialog.Destroy()
   665         event.Skip()
   648         event.Skip()
   666 
   649 
   677         if not result:
   660         if not result:
   678             self.SaveAs()
   661             self.SaveAs()
   679         elif type(result) != StringType:
   662         elif type(result) != StringType:
   680             self.RefreshBufferState()
   663             self.RefreshBufferState()
   681         else:
   664         else:
   682             message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   665             message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   683             message.ShowModal()
   666             message.ShowModal()
   684             message.Destroy()
   667             message.Destroy()
   685 
   668 
   686     def SaveAs(self):
   669     def SaveAs(self):
   687         filepath = self.Manager.GetCurrentFilePath()
   670         filepath = self.Manager.GetCurrentFilePath()
   688         if filepath != "":
   671         if filepath != "":
   689             directory, filename = os.path.split(filepath)
   672             directory, filename = os.path.split(filepath)
   690         else:
   673         else:
   691             directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0]
   674             directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0]
   692         dialog = wxFileDialog(self, "Choose a file", directory, filename,  "OD files (*.od)|*.od|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
   675         dialog = wx.FileDialog(self, "Choose a file", directory, filename,  "OD files (*.od)|*.od|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR)
   693         if dialog.ShowModal() == wxID_OK:
   676         if dialog.ShowModal() == wx.ID_OK:
   694             filepath = dialog.GetPath()
   677             filepath = dialog.GetPath()
   695             if os.path.isdir(os.path.dirname(filepath)):
   678             if os.path.isdir(os.path.dirname(filepath)):
   696                 result = self.Manager.SaveCurrentInFile(filepath)
   679                 result = self.Manager.SaveCurrentInFile(filepath)
   697                 if type(result) != StringType:
   680                 if type(result) != StringType:
   698                     self.RefreshBufferState()
   681                     self.RefreshBufferState()
   699                 else:
   682                 else:
   700                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   683                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   701                     message.ShowModal()
   684                     message.ShowModal()
   702                     message.Destroy()
   685                     message.Destroy()
   703             else:
   686             else:
   704                 message = wxMessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
   687                 message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR)
   705                 message.ShowModal()
   688                 message.ShowModal()
   706                 message.Destroy()
   689                 message.Destroy()
   707         dialog.Destroy()
   690         dialog.Destroy()
   708 
   691 
   709     def OnCloseMenu(self, event):
   692     def OnCloseMenu(self, event):
   710         answer = wxID_YES
   693         answer = wx.ID_YES
   711         result = self.Manager.CloseCurrent()
   694         result = self.Manager.CloseCurrent()
   712         if not result:
   695         if not result:
   713             dialog = wxMessageDialog(self, "There are changes, do you want to save?",  "Close File", wxYES_NO|wxCANCEL|wxICON_QUESTION)
   696             dialog = wx.MessageDialog(self, "There are changes, do you want to save?",  "Close File", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION)
   714             answer = dialog.ShowModal()
   697             answer = dialog.ShowModal()
   715             dialog.Destroy()
   698             dialog.Destroy()
   716             if answer == wxID_YES:
   699             if answer == wx.ID_YES:
   717                 self.OnSaveMenu(event)
   700                 self.OnSaveMenu(event)
   718                 if self.Manager.CurrentIsSaved():
   701                 if self.Manager.CurrentIsSaved():
   719                     self.Manager.CloseCurrent()
   702                     self.Manager.CloseCurrent()
   720             elif answer == wxID_NO:
   703             elif answer == wx.ID_NO:
   721                 self.Manager.CloseCurrent(True)
   704                 self.Manager.CloseCurrent(True)
   722         if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber():
   705         if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber():
   723             current = self.FileOpened.GetSelection()
   706             current = self.FileOpened.GetSelection()
   724             self.FileOpened.DeletePage(current)
   707             self.FileOpened.DeletePage(current)
   725             if self.FileOpened.GetPageCount() > 0:
   708             if self.FileOpened.GetPageCount() > 0:
   732 #-------------------------------------------------------------------------------
   715 #-------------------------------------------------------------------------------
   733 #                         Import and Export Functions
   716 #                         Import and Export Functions
   734 #-------------------------------------------------------------------------------
   717 #-------------------------------------------------------------------------------
   735 
   718 
   736     def OnImportEDSMenu(self, event):
   719     def OnImportEDSMenu(self, event):
   737         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), "",  "EDS files (*.eds)|*.eds|All files|*.*", wxOPEN|wxCHANGE_DIR)
   720         dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), "",  "EDS files (*.eds)|*.eds|All files|*.*", wx.OPEN|wx.CHANGE_DIR)
   738         if dialog.ShowModal() == wxID_OK:
   721         if dialog.ShowModal() == wx.ID_OK:
   739             filepath = dialog.GetPath()
   722             filepath = dialog.GetPath()
   740             if os.path.isfile(filepath):
   723             if os.path.isfile(filepath):
   741                 result = self.Manager.ImportCurrentFromEDSFile(filepath)
   724                 result = self.Manager.ImportCurrentFromEDSFile(filepath)
   742                 if type(result) == IntType:
   725                 if type(result) == IntType:
   743                     new_editingpanel = EditingPanel(self, self.Manager)
   726                     new_editingpanel = EditingPanel(self, self.Manager)
   746                     self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   729                     self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1)
   747                     self.RefreshBufferState()
   730                     self.RefreshBufferState()
   748                     self.RefreshCurrentIndexList()
   731                     self.RefreshCurrentIndexList()
   749                     self.RefreshProfileMenu()
   732                     self.RefreshProfileMenu()
   750                     self.RefreshMainMenu()
   733                     self.RefreshMainMenu()
   751                     message = wxMessageDialog(self, "Import successful", "Information", wxOK|wxICON_INFORMATION)
   734                     message = wx.MessageDialog(self, "Import successful", "Information", wx.OK|wx.ICON_INFORMATION)
   752                     message.ShowModal()
   735                     message.ShowModal()
   753                     message.Destroy()
   736                     message.Destroy()
   754                 else:
   737                 else:
   755                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   738                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   756                     message.ShowModal()
   739                     message.ShowModal()
   757                     message.Destroy()
   740                     message.Destroy()
   758             else:
   741             else:
   759                 message = wxMessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wxOK|wxICON_ERROR)
   742                 message = wx.MessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wx.OK|wx.ICON_ERROR)
   760                 message.ShowModal()
   743                 message.ShowModal()
   761                 message.Destroy()
   744                 message.Destroy()
   762         dialog.Destroy()
   745         dialog.Destroy()
   763         event.Skip()
   746         event.Skip()
   764 
   747 
   765 
   748 
   766     def OnExportEDSMenu(self, event):
   749     def OnExportEDSMenu(self, event):
   767         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0], "EDS files (*.eds)|*.eds|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
   750         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)
   768         if dialog.ShowModal() == wxID_OK:
   751         if dialog.ShowModal() == wx.ID_OK:
   769             filepath = dialog.GetPath()
   752             filepath = dialog.GetPath()
   770             if os.path.isdir(os.path.dirname(filepath)):
   753             if os.path.isdir(os.path.dirname(filepath)):
   771                 path, extend = os.path.splitext(filepath)
   754                 path, extend = os.path.splitext(filepath)
   772                 if extend in ("", "."):
   755                 if extend in ("", "."):
   773                     filepath = path + ".eds"
   756                     filepath = path + ".eds"
   774                 result = self.Manager.ExportCurrentToEDSFile(filepath)
   757                 result = self.Manager.ExportCurrentToEDSFile(filepath)
   775                 if not result:
   758                 if not result:
   776                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
   759                     message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION)
   777                     message.ShowModal()
   760                     message.ShowModal()
   778                     message.Destroy()
   761                     message.Destroy()
   779                 else:
   762                 else:
   780                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   763                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   781                     message.ShowModal()
   764                     message.ShowModal()
   782                     message.Destroy()
   765                     message.Destroy()
   783             else:
   766             else:
   784                 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
   767                 message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR)
   785                 message.ShowModal()
   768                 message.ShowModal()
   786                 message.Destroy()
   769                 message.Destroy()
   787         dialog.Destroy()
   770         dialog.Destroy()
   788         event.Skip()
   771         event.Skip()
   789 
   772 
   790     def OnExportCMenu(self, event):
   773     def OnExportCMenu(self, event):
   791         dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival C files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
   774         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)
   792         if dialog.ShowModal() == wxID_OK:
   775         if dialog.ShowModal() == wx.ID_OK:
   793             filepath = dialog.GetPath()
   776             filepath = dialog.GetPath()
   794             if os.path.isdir(os.path.dirname(filepath)):
   777             if os.path.isdir(os.path.dirname(filepath)):
   795                 path, extend = os.path.splitext(filepath)
   778                 path, extend = os.path.splitext(filepath)
   796                 if extend in ("", "."):
   779                 if extend in ("", "."):
   797                     filepath = path + ".c"
   780                     filepath = path + ".c"
   798                 result = self.Manager.ExportCurrentToCFile(filepath)
   781                 result = self.Manager.ExportCurrentToCFile(filepath)
   799                 if not result:
   782                 if not result:
   800                     message = wxMessageDialog(self, "Export successful", "Information", wxOK|wxICON_INFORMATION)
   783                     message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION)
   801                     message.ShowModal()
   784                     message.ShowModal()
   802                     message.Destroy()
   785                     message.Destroy()
   803                 else:
   786                 else:
   804                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   787                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   805                     message.ShowModal()
   788                     message.ShowModal()
   806                     message.Destroy()
   789                     message.Destroy()
   807             else:
   790             else:
   808                 message = wxMessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wxOK|wxICON_ERROR)
   791                 message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR)
   809                 message.ShowModal()
   792                 message.ShowModal()
   810                 message.Destroy()
   793                 message.Destroy()
   811         dialog.Destroy()
   794         dialog.Destroy()
   812         event.Skip()
   795         event.Skip()
   813 
   796 
   835         dialog = CommunicationDialog(self)
   818         dialog = CommunicationDialog(self)
   836         dialog.SetTitle(title)
   819         dialog.SetTitle(title)
   837         dialog.SetIndexDictionary(dictionary)
   820         dialog.SetIndexDictionary(dictionary)
   838         dialog.SetCurrentList(current)
   821         dialog.SetCurrentList(current)
   839         dialog.RefreshLists()
   822         dialog.RefreshLists()
   840         if dialog.ShowModal() == wxID_OK:
   823         if dialog.ShowModal() == wx.ID_OK:
   841             new_profile = dialog.GetCurrentList()
   824             new_profile = dialog.GetCurrentList()
   842             addinglist = []
   825             addinglist = []
   843             removinglist = []
   826             removinglist = []
   844             for index in new_profile:
   827             for index in new_profile:
   845                 if index not in current:
   828                 if index not in current:
   867 
   850 
   868     def OnNodeInfosMenu(self, event):
   851     def OnNodeInfosMenu(self, event):
   869         dialog = NodeInfosDialog(self)
   852         dialog = NodeInfosDialog(self)
   870         name, id, type, description = self.Manager.GetCurrentNodeInfos()
   853         name, id, type, description = self.Manager.GetCurrentNodeInfos()
   871         dialog.SetValues(name, id, type, description)
   854         dialog.SetValues(name, id, type, description)
   872         if dialog.ShowModal() == wxID_OK:
   855         if dialog.ShowModal() == wx.ID_OK:
   873             name, id, type, description = dialog.GetValues()
   856             name, id, type, description = dialog.GetValues()
   874             self.Manager.SetCurrentNodeInfos(name, id, type, description)
   857             self.Manager.SetCurrentNodeInfos(name, id, type, description)
   875             self.RefreshBufferState()
   858             self.RefreshBufferState()
   876             self.RefreshProfileMenu()
   859             self.RefreshProfileMenu()
   877             selected = self.FileOpened.GetSelection()
   860             selected = self.FileOpened.GetSelection()
   888     def AddMapVariable(self):
   871     def AddMapVariable(self):
   889         index = self.Manager.GetCurrentNextMapIndex()
   872         index = self.Manager.GetCurrentNextMapIndex()
   890         if index:
   873         if index:
   891             dialog = MapVariableDialog(self)
   874             dialog = MapVariableDialog(self)
   892             dialog.SetIndex(index)
   875             dialog.SetIndex(index)
   893             if dialog.ShowModal() == wxID_OK:
   876             if dialog.ShowModal() == wx.ID_OK:
   894                 index, name, struct, number = dialog.GetValues()
   877                 index, name, struct, number = dialog.GetValues()
   895                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
   878                 result = self.Manager.AddMapVariableToCurrent(index, name, struct, number)
   896                 if type(result) != StringType:
   879                 if type(result) != StringType:
   897                     self.RefreshBufferState()
   880                     self.RefreshBufferState()
   898                     self.RefreshCurrentIndexList()
   881                     self.RefreshCurrentIndexList()
   899                 else:
   882                 else:
   900                     message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   883                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   901                     message.ShowModal()
   884                     message.ShowModal()
   902                     message.Destroy()
   885                     message.Destroy()
   903             dialog.Destroy()
   886             dialog.Destroy()
   904         else:
   887         else:
   905             message = wxMessageDialog(self, result, "No map variable index left!", wxOK|wxICON_ERROR)
   888             message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR)
   906             message.ShowModal()
   889             message.ShowModal()
   907             message.Destroy()
   890             message.Destroy()
   908         
   891         
   909     def AddUserType(self):
   892     def AddUserType(self):
   910         dialog = UserTypeDialog(self)
   893         dialog = UserTypeDialog(self)
   911         dialog.SetTypeList(self.Manager.GetCustomisableTypes())
   894         dialog.SetTypeList(self.Manager.GetCustomisableTypes())
   912         if dialog.ShowModal() == wxID_OK:
   895         if dialog.ShowModal() == wx.ID_OK:
   913             type, min, max, length = dialog.GetValues()
   896             type, min, max, length = dialog.GetValues()
   914             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
   897             result = self.Manager.AddUserTypeToCurrent(type, min, max, length)
   915             if not result:
   898             if not result:
   916                 self.RefreshBufferState()
   899                 self.RefreshBufferState()
   917                 self.RefreshCurrentIndexList()
   900                 self.RefreshCurrentIndexList()
   918             else:
   901             else:
   919                 message = wxMessageDialog(self, result, "Error", wxOK|wxICON_ERROR)
   902                 message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
   920                 message.ShowModal()
   903                 message.ShowModal()
   921                 message.Destroy()
   904                 message.Destroy()
   922         dialog.Destroy()
   905         dialog.Destroy()
   923     
   906     
   924 
   907 
   966         dlg.Destroy()
   949         dlg.Destroy()
   967 
   950 
   968     return res
   951     return res
   969 
   952 
   970 def Display_Error_Dialog(e_value):
   953 def Display_Error_Dialog(e_value):
   971     message = wxMessageDialog(None, str(e_value), "Error", wxOK|wxICON_ERROR)
   954     message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR)
   972     message.ShowModal()
   955     message.ShowModal()
   973     message.Destroy()
   956     message.Destroy()
   974 
   957 
   975 def get_last_traceback(tb):
   958 def get_last_traceback(tb):
   976     while tb.tb_next:
   959     while tb.tb_next:
   982     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
   965     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
   983 
   966 
   984 
   967 
   985 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
   968 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
   986 
   969 
   987 def wxAddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
   970 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
   988     
   971     
   989     def handle_exception(e_type, e_value, e_traceback):
   972     def handle_exception(e_type, e_value, e_traceback):
   990         traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
   973         traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
   991         last_tb = get_last_traceback(e_traceback)
   974         last_tb = get_last_traceback(e_traceback)
   992         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
   975         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
  1024 
  1007 
  1025     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
  1008     #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
  1026     sys.excepthook = handle_exception
  1009     sys.excepthook = handle_exception
  1027 
  1010 
  1028 if __name__ == '__main__':
  1011 if __name__ == '__main__':
  1029     app = wxPySimpleApp()
  1012     app = wx.PySimpleApp()
  1030     wxInitAllImageHandlers()
  1013     wx.InitAllImageHandlers()
  1031     
  1014     
  1032     # Install a exception handle for bug reports
  1015     # Install a exception handle for bug reports
  1033     wxAddExceptHook(os.getcwd(),__version__)
  1016     AddExceptHook(os.getcwd(),__version__)
  1034     
  1017     
  1035     frame = objdictedit(None)
  1018     frame = objdictedit(None)
  1036 
  1019 
  1037     frame.Show()
  1020     frame.Show()
  1038     app.MainLoop()
  1021     app.MainLoop()