author | groke6 |
Thu, 17 Jan 2008 16:21:07 +0100 | |
changeset 360 | 09af3515dd42 |
parent 348 | c50feb2bb590 |
child 386 | 0f56a144ba5f |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of CanFestival, a library implementing CanOpen Stack. |
|
5 |
# |
|
6 |
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU Lesser General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#Lesser General Public License for more details. |
|
19 |
# |
|
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 |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
24 |
import wx |
|
25 |
||
26 |
from types import * |
|
27 |
import os, re, platform, sys, time, traceback, getopt |
|
28 |
||
29 |
__version__ = "$Revision$" |
|
30 |
||
206 | 31 |
from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes |
32 |
||
0 | 33 |
from nodemanager import * |
205 | 34 |
from subindextable import * |
35 |
from commondialogs import * |
|
0 | 36 |
from doc_index.DS301_index import * |
37 |
||
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
38 |
try: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
39 |
import wx.html |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
40 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
41 |
EVT_HTML_URL_CLICK = wx.NewId() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
42 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
43 |
class HtmlWindowUrlClick(wx.PyEvent): |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
44 |
def __init__(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
45 |
wx.PyEvent.__init__(self) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
46 |
self.SetEventType(EVT_HTML_URL_CLICK) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
47 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
48 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
49 |
class UrlClickHtmlWindow(wx.html.HtmlWindow): |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
50 |
""" HTML window that generates and OnLinkClicked event. |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
51 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
52 |
Use this to avoid having to override HTMLWindow |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
53 |
""" |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
54 |
def OnLinkClicked(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
55 |
wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
56 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
57 |
def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
58 |
if event == HtmlWindowUrlClick: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
59 |
self.Connect(-1, -1, EVT_HTML_URL_CLICK, handler) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
60 |
else: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
61 |
wx.html.HtmlWindow.Bind(event, handler, source=source, id=id, id2=id2) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
62 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
63 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
64 |
# Html Frame |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
65 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
66 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
67 |
[ID_HTMLFRAME, ID_HTMLFRAMEHTMLCONTENT] = [wx.NewId() for _init_ctrls in range(2)] |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
68 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
69 |
class HtmlFrame(wx.Frame): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
70 |
def _init_ctrls(self, prnt): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
71 |
wx.Frame.__init__(self, id=ID_HTMLFRAME, name='HtmlFrame', |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
72 |
parent=prnt, pos=wx.Point(320, 231), size=wx.Size(853, 616), |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
73 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
273 | 74 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
75 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
76 |
self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
77 |
name='HtmlContent', parent=self, pos=wx.Point(0, 0), |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
78 |
size=wx.Size(-1, -1), style=wx.html.HW_SCROLLBAR_AUTO|wx.html.HW_NO_SELECTION) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
79 |
self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
80 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
81 |
def __init__(self, parent, opened): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
82 |
self._init_ctrls(parent) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
83 |
self.HtmlFrameOpened = opened |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
84 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
85 |
def SetHtmlCode(self, htmlcode): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
86 |
self.HtmlContent.SetPage(htmlcode) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
87 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
88 |
def SetHtmlPage(self, htmlpage): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
89 |
self.HtmlContent.LoadPage(htmlpage) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
90 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
91 |
def OnCloseFrame(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
92 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
93 |
event.Skip() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
94 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
95 |
def OnLinkClick(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
96 |
url = event.linkinfo[0] |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
97 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
98 |
import webbrowser |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
99 |
except ImportError: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
100 |
wx.MessageBox('Please point your browser at: %s' % url) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
101 |
else: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
102 |
webbrowser.open(url) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
103 |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
104 |
Html_Window = True |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
105 |
except: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
106 |
Html_Window = False |
0 | 107 |
|
318
cef08361bab1
Fix problem with symbolic link ( --> os.path.realpath() )
greg
parents:
300
diff
changeset
|
108 |
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0] |
0 | 109 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
110 |
[ID_OBJDICTEDIT, ID_OBJDICTEDITFILEOPENED, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
111 |
ID_OBJDICTEDITHELPBAR, |
0 | 112 |
] = [wx.NewId() for _init_ctrls in range(3)] |
113 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
114 |
[ID_OBJDICTEDITADDMENUITEMS0, ID_OBJDICTEDITADDMENUITEMS1, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
115 |
ID_OBJDICTEDITADDMENUITEMS2, ID_OBJDICTEDITADDMENUITEMS3, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
116 |
ID_OBJDICTEDITADDMENUITEMS4, ID_OBJDICTEDITADDMENUITEMS5, |
0 | 117 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
118 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
119 |
[ID_OBJDICTEDITFILEMENUITEMS0, ID_OBJDICTEDITFILEMENUITEMS1, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
120 |
ID_OBJDICTEDITFILEMENUITEMS2, ID_OBJDICTEDITFILEMENUITEMS4, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
121 |
ID_OBJDICTEDITFILEMENUITEMS5, ID_OBJDICTEDITFILEMENUITEMS6, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
122 |
ID_OBJDICTEDITFILEMENUITEMS7, ID_OBJDICTEDITFILEMENUITEMS8, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
123 |
ID_OBJDICTEDITFILEMENUITEMS9, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
124 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(9)] |
0 | 125 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
126 |
[ID_OBJDICTEDITEDITMENUITEMS0, ID_OBJDICTEDITEDITMENUITEMS1, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
127 |
ID_OBJDICTEDITEDITMENUITEMS2, ID_OBJDICTEDITEDITMENUITEMS4, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
128 |
ID_OBJDICTEDITEDITMENUITEMS6, ID_OBJDICTEDITEDITMENUITEMS7, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
129 |
ID_OBJDICTEDITEDITMENUITEMS8, |
0 | 130 |
] = [wx.NewId() for _init_coll_EditMenu_Items in range(7)] |
131 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
132 |
[ID_OBJDICTEDITHELPMENUITEMS0, ID_OBJDICTEDITHELPMENUITEMS1, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
133 |
ID_OBJDICTEDITHELPMENUITEMS2, |
0 | 134 |
] = [wx.NewId() for _init_coll_HelpMenu_Items in range(3)] |
135 |
||
136 |
class objdictedit(wx.Frame): |
|
137 |
def _init_coll_menuBar1_Menus(self, parent): |
|
138 |
parent.Append(menu=self.FileMenu, title='File') |
|
139 |
parent.Append(menu=self.EditMenu, title='Edit') |
|
140 |
parent.Append(menu=self.AddMenu, title='Add') |
|
141 |
parent.Append(menu=self.HelpMenu, title='Help') |
|
142 |
||
143 |
def _init_coll_EditMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
144 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS4, |
0 | 145 |
kind=wx.ITEM_NORMAL, text='Refresh\tCTRL+R') |
146 |
parent.AppendSeparator() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
147 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS1, |
0 | 148 |
kind=wx.ITEM_NORMAL, text='Undo\tCTRL+Z') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
149 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS0, |
0 | 150 |
kind=wx.ITEM_NORMAL, text='Redo\tCTRL+Y') |
151 |
parent.AppendSeparator() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
152 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS6, |
0 | 153 |
kind=wx.ITEM_NORMAL, text='Node infos') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
154 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS2, |
0 | 155 |
kind=wx.ITEM_NORMAL, text='DS-301 Profile') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
156 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS8, |
0 | 157 |
kind=wx.ITEM_NORMAL, text='DS-302 Profile') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
158 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUITEMS7, |
0 | 159 |
kind=wx.ITEM_NORMAL, text='Other Profile') |
160 |
self.Bind(wx.EVT_MENU, self.OnUndoMenu, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
161 |
id=ID_OBJDICTEDITEDITMENUITEMS1) |
0 | 162 |
self.Bind(wx.EVT_MENU, self.OnRedoMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
163 |
id=ID_OBJDICTEDITEDITMENUITEMS0) |
0 | 164 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
165 |
id=ID_OBJDICTEDITEDITMENUITEMS2) |
0 | 166 |
self.Bind(wx.EVT_MENU, self.OnRefreshMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
167 |
id=ID_OBJDICTEDITEDITMENUITEMS4) |
0 | 168 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
169 |
id=ID_OBJDICTEDITEDITMENUITEMS6) |
0 | 170 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
171 |
id=ID_OBJDICTEDITEDITMENUITEMS7) |
0 | 172 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
173 |
id=ID_OBJDICTEDITEDITMENUITEMS8) |
0 | 174 |
|
175 |
def _init_coll_HelpMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
176 |
parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS0, |
0 | 177 |
kind=wx.ITEM_NORMAL, text='DS-301 Standard\tF1') |
178 |
self.Bind(wx.EVT_MENU, self.OnHelpDS301Menu, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
179 |
id=ID_OBJDICTEDITHELPMENUITEMS0) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
180 |
parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS1, |
205 | 181 |
kind=wx.ITEM_NORMAL, text='CAN Festival Docs\tF2') |
182 |
self.Bind(wx.EVT_MENU, self.OnHelpCANFestivalMenu, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
183 |
id=ID_OBJDICTEDITHELPMENUITEMS1) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
184 |
if Html_Window: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
185 |
parent.Append(help='', id=ID_OBJDICTEDITHELPMENUITEMS2, |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
186 |
kind=wx.ITEM_NORMAL, text='About') |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
187 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
188 |
id=ID_OBJDICTEDITHELPMENUITEMS2) |
0 | 189 |
|
190 |
def _init_coll_FileMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
191 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS5, |
0 | 192 |
kind=wx.ITEM_NORMAL, text='New\tCTRL+N') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
193 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS0, |
0 | 194 |
kind=wx.ITEM_NORMAL, text='Open\tCTRL+O') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
195 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS1, |
0 | 196 |
kind=wx.ITEM_NORMAL, text='Save\tCTRL+S') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
197 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS6, |
0 | 198 |
kind=wx.ITEM_NORMAL, text='Save As...\tALT+S') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
199 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS2, |
0 | 200 |
kind=wx.ITEM_NORMAL, text='Close\tCTRL+W') |
201 |
parent.AppendSeparator() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
202 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS7, |
171 | 203 |
kind=wx.ITEM_NORMAL, text='Import EDS file') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
204 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS9, |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
205 |
kind=wx.ITEM_NORMAL, text='Export to EDS file') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
206 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS8, |
0 | 207 |
kind=wx.ITEM_NORMAL, text='Build Dictionary\tCTRL+B') |
208 |
parent.AppendSeparator() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
209 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUITEMS4, |
0 | 210 |
kind=wx.ITEM_NORMAL, text='Exit') |
211 |
self.Bind(wx.EVT_MENU, self.OnOpenMenu, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
212 |
id=ID_OBJDICTEDITFILEMENUITEMS0) |
0 | 213 |
self.Bind(wx.EVT_MENU, self.OnSaveMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
214 |
id=ID_OBJDICTEDITFILEMENUITEMS1) |
0 | 215 |
self.Bind(wx.EVT_MENU, self.OnCloseMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
216 |
id=ID_OBJDICTEDITFILEMENUITEMS2) |
0 | 217 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
218 |
id=ID_OBJDICTEDITFILEMENUITEMS4) |
0 | 219 |
self.Bind(wx.EVT_MENU, self.OnNewMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
220 |
id=ID_OBJDICTEDITFILEMENUITEMS5) |
0 | 221 |
self.Bind(wx.EVT_MENU, self.OnSaveAsMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
222 |
id=ID_OBJDICTEDITFILEMENUITEMS6) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
223 |
self.Bind(wx.EVT_MENU, self.OnImportEDSMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
224 |
id=ID_OBJDICTEDITFILEMENUITEMS7) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
225 |
self.Bind(wx.EVT_MENU, self.OnExportCMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
226 |
id=ID_OBJDICTEDITFILEMENUITEMS8) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
227 |
self.Bind(wx.EVT_MENU, self.OnExportEDSMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
228 |
id=ID_OBJDICTEDITFILEMENUITEMS9) |
0 | 229 |
|
230 |
def _init_coll_AddMenu_Items(self, parent): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
231 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS0, |
0 | 232 |
kind=wx.ITEM_NORMAL, text='SDO Server') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
233 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS1, |
0 | 234 |
kind=wx.ITEM_NORMAL, text='SDO Client') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
235 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS2, |
0 | 236 |
kind=wx.ITEM_NORMAL, text='PDO Transmit') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
237 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS3, |
0 | 238 |
kind=wx.ITEM_NORMAL, text='PDO Receive') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
239 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS4, |
0 | 240 |
kind=wx.ITEM_NORMAL, text='Map Variable') |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
241 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUITEMS5, |
0 | 242 |
kind=wx.ITEM_NORMAL, text='User Type') |
243 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
244 |
id=ID_OBJDICTEDITADDMENUITEMS0) |
0 | 245 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
246 |
id=ID_OBJDICTEDITADDMENUITEMS1) |
0 | 247 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
248 |
id=ID_OBJDICTEDITADDMENUITEMS2) |
0 | 249 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
250 |
id=ID_OBJDICTEDITADDMENUITEMS3) |
0 | 251 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
252 |
id=ID_OBJDICTEDITADDMENUITEMS4) |
0 | 253 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
254 |
id=ID_OBJDICTEDITADDMENUITEMS5) |
0 | 255 |
|
256 |
def _init_coll_HelpBar_Fields(self, parent): |
|
257 |
parent.SetFieldsCount(3) |
|
258 |
||
259 |
parent.SetStatusText(number=0, text='') |
|
260 |
parent.SetStatusText(number=1, text='') |
|
261 |
parent.SetStatusText(number=2, text='') |
|
262 |
||
263 |
parent.SetStatusWidths([100, 110, -1]) |
|
264 |
||
265 |
def _init_utils(self): |
|
266 |
self.menuBar1 = wx.MenuBar() |
|
267 |
self.menuBar1.SetEvtHandlerEnabled(True) |
|
268 |
||
269 |
self.FileMenu = wx.Menu(title='') |
|
270 |
self.EditMenu = wx.Menu(title='') |
|
271 |
self.AddMenu = wx.Menu(title='') |
|
272 |
self.HelpMenu = wx.Menu(title='') |
|
273 |
||
274 |
self._init_coll_menuBar1_Menus(self.menuBar1) |
|
275 |
self._init_coll_FileMenu_Items(self.FileMenu) |
|
276 |
self._init_coll_EditMenu_Items(self.EditMenu) |
|
277 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
278 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
279 |
||
280 |
def _init_ctrls(self, prnt): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
281 |
wx.Frame.__init__(self, id=ID_OBJDICTEDIT, name='objdictedit', |
0 | 282 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
283 |
style=wx.DEFAULT_FRAME_STYLE, title='Objdictedit') |
|
284 |
self._init_utils() |
|
285 |
self.SetClientSize(wx.Size(1000, 700)) |
|
286 |
self.SetMenuBar(self.menuBar1) |
|
273 | 287 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
288 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
289 |
self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED, |
0 | 290 |
name='FileOpened', parent=self, pos=wx.Point(0, 0), |
291 |
size=wx.Size(0, 0), style=0) |
|
292 |
self.FileOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
293 |
self.OnFileSelectedChanged, id=ID_OBJDICTEDITFILEOPENED) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
294 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
295 |
self.HelpBar = wx.StatusBar(id=ID_OBJDICTEDITHELPBAR, name='HelpBar', |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
296 |
parent=self, style=wx.ST_SIZEGRIP) |
0 | 297 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
298 |
self.SetStatusBar(self.HelpBar) |
|
299 |
||
276 | 300 |
def __init__(self, parent, filesOpen = []): |
0 | 301 |
self._init_ctrls(parent) |
302 |
self.HtmlFrameOpened = [] |
|
245
d43ebbed895f
Modifying gen_cfile.py for generating C file from a node as data rather than a manager
lbessard
parents:
232
diff
changeset
|
303 |
self.ModeSolo = True |
0 | 304 |
|
258 | 305 |
self.Manager = NodeManager() |
0 | 306 |
for filepath in filesOpen: |
232 | 307 |
result = self.Manager.OpenFileInCurrent(filepath) |
308 |
if type(result) == IntType: |
|
299 | 309 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
232 | 310 |
new_editingpanel.SetIndex(result) |
311 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
312 |
window = self.FileOpened.GetPage(0) |
|
313 |
if window: |
|
314 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
315 |
self.FileOpened.SetSelection(0) |
|
258 | 316 |
if self.Manager.CurrentDS302Defined(): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
317 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) |
0 | 318 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
319 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) |
0 | 320 |
self.RefreshEditMenu() |
321 |
self.RefreshBufferState() |
|
322 |
self.RefreshProfileMenu() |
|
323 |
self.RefreshTitle() |
|
324 |
self.RefreshMainMenu() |
|
325 |
||
326 |
def OnAddSDOServerMenu(self, event): |
|
327 |
self.Manager.AddSDOServerToCurrent() |
|
328 |
self.RefreshBufferState() |
|
329 |
self.RefreshCurrentIndexList() |
|
330 |
event.Skip() |
|
331 |
||
332 |
def OnAddSDOClientMenu(self, event): |
|
333 |
self.Manager.AddSDOClientToCurrent() |
|
334 |
self.RefreshBufferState() |
|
335 |
self.RefreshCurrentIndexList() |
|
336 |
event.Skip() |
|
337 |
||
338 |
def OnAddPDOTransmitMenu(self, event): |
|
339 |
self.Manager.AddPDOTransmitToCurrent() |
|
340 |
self.RefreshBufferState() |
|
341 |
self.RefreshCurrentIndexList() |
|
342 |
event.Skip() |
|
343 |
||
344 |
def OnAddPDOReceiveMenu(self, event): |
|
345 |
self.Manager.AddPDOReceiveToCurrent() |
|
346 |
self.RefreshBufferState() |
|
347 |
self.RefreshCurrentIndexList() |
|
348 |
event.Skip() |
|
349 |
||
350 |
def OnAddMapVariableMenu(self, event): |
|
351 |
self.AddMapVariable() |
|
352 |
event.Skip() |
|
353 |
||
354 |
def OnAddUserTypeMenu(self, event): |
|
355 |
self.AddUserType() |
|
356 |
event.Skip() |
|
357 |
||
358 |
def OnFileSelectedChanged(self, event): |
|
43 | 359 |
selected = event.GetSelection() |
37 | 360 |
# At init selected = -1 |
361 |
if selected >= 0: |
|
205 | 362 |
window = self.FileOpened.GetPage(selected) |
223 | 363 |
if window: |
364 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
300
b83d063c4dc4
Bug on new file and open file with wxPython 2.8.4.2 on GTK fixed
lbessard
parents:
299
diff
changeset
|
365 |
wx.CallAfter(self.RefreshBufferState) |
223 | 366 |
self.RefreshStatusBar() |
367 |
self.RefreshProfileMenu() |
|
0 | 368 |
event.Skip() |
369 |
||
370 |
def OnHelpDS301Menu(self, event): |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
371 |
find_index = False |
0 | 372 |
selected = self.FileOpened.GetSelection() |
373 |
if selected >= 0: |
|
374 |
window = self.FileOpened.GetPage(selected) |
|
375 |
result = window.GetSelection() |
|
376 |
if result: |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
377 |
find_index = True |
0 | 378 |
index, subIndex = result |
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
379 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
0 | 380 |
if type(result) == StringType: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
381 |
message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 382 |
message.ShowModal() |
383 |
message.Destroy() |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
384 |
if not find_index: |
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
385 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
386 |
if type(result) == StringType: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
387 |
message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
388 |
message.ShowModal() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
389 |
message.Destroy() |
0 | 390 |
event.Skip() |
391 |
||
392 |
def OnHelpCANFestivalMenu(self, event): |
|
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
393 |
#self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) |
341 | 394 |
if wx.Platform == '__WXMSW__': |
395 |
os.system("Reader %s -n %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
|
396 |
else: |
|
397 |
os.system("xpdf -remote CANFESTIVAL %s %d &"%(os.path.join(ScriptDirectory, "doc/manual_en.pdf"),16)) |
|
0 | 398 |
event.Skip() |
399 |
||
400 |
def OnAboutMenu(self, event): |
|
158
b505f7116a1c
Moved DS-301 PDF into objdictgen. Fixed installation on linux. Now TestMasterSlave is also installed in $PREFIX/bin.
etisserant
parents:
149
diff
changeset
|
401 |
self.OpenHtmlFrame("About CAN Festival", os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
0 | 402 |
event.Skip() |
403 |
||
404 |
def OpenHtmlFrame(self, title, file, size): |
|
405 |
if title not in self.HtmlFrameOpened: |
|
406 |
self.HtmlFrameOpened.append(title) |
|
407 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
408 |
window.SetTitle(title) |
|
409 |
window.SetHtmlPage(file) |
|
410 |
window.SetClientSize(size) |
|
411 |
window.Show() |
|
412 |
||
413 |
def OnQuitMenu(self, event): |
|
414 |
self.Close() |
|
415 |
event.Skip() |
|
416 |
||
417 |
def OnCloseFrame(self, event): |
|
418 |
if self.Manager.OneFileHasChanged(): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
419 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close Application", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
0 | 420 |
answer = dialog.ShowModal() |
421 |
dialog.Destroy() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
422 |
if answer == wx.ID_YES: |
0 | 423 |
self.Manager.ChangeCurrentNode(0) |
424 |
for i in xrange(self.FileOpened.GetPageCount()): |
|
223 | 425 |
window = self.FileOpened.GetPage(i) |
426 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
0 | 427 |
if self.Manager.CurrentIsSaved(): |
428 |
self.Manager.CloseCurrent() |
|
429 |
else: |
|
430 |
self.Save() |
|
431 |
self.Manager.CloseCurrent(True) |
|
432 |
event.Skip() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
433 |
elif answer == wx.ID_NO: |
0 | 434 |
for i in xrange(self.FileOpened.GetPageCount()): |
435 |
self.Manager.CloseCurrent(True) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
436 |
wx.CallAfter(self.Close) |
0 | 437 |
event.Skip() |
438 |
else: |
|
439 |
event.Skip() |
|
440 |
||
441 |
#------------------------------------------------------------------------------- |
|
442 |
# Refresh Functions |
|
443 |
#------------------------------------------------------------------------------- |
|
444 |
||
445 |
def RefreshTitle(self): |
|
446 |
if self.FileOpened.GetPageCount() > 0: |
|
447 |
self.SetTitle("Objdictedit - %s"%self.Manager.GetCurrentFilename()) |
|
448 |
else: |
|
449 |
self.SetTitle("Objdictedit") |
|
450 |
||
451 |
def OnRefreshMenu(self, event): |
|
452 |
self.RefreshCurrentIndexList() |
|
453 |
event.Skip() |
|
454 |
||
455 |
def RefreshCurrentIndexList(self): |
|
456 |
selected = self.FileOpened.GetSelection() |
|
457 |
window = self.FileOpened.GetPage(selected) |
|
458 |
window.RefreshIndexList() |
|
459 |
||
460 |
def RefreshStatusBar(self): |
|
348 | 461 |
if self and self.HelpBar: |
209 | 462 |
selected = self.FileOpened.GetSelection() |
463 |
if selected >= 0: |
|
464 |
window = self.FileOpened.GetPage(selected) |
|
465 |
selection = window.GetSelection() |
|
466 |
if selection: |
|
467 |
index, subIndex = selection |
|
468 |
if self.Manager.IsCurrentEntry(index): |
|
469 |
self.HelpBar.SetStatusText("Index: 0x%04X"%index, 0) |
|
470 |
self.HelpBar.SetStatusText("Subindex: 0x%02X"%subIndex, 1) |
|
471 |
entryinfos = self.Manager.GetEntryInfos(index) |
|
472 |
name = entryinfos["name"] |
|
473 |
category = "Optional" |
|
474 |
if entryinfos["need"]: |
|
475 |
category = "Mandatory" |
|
476 |
struct = "VAR" |
|
477 |
number = "" |
|
478 |
if entryinfos["struct"] & OD_IdenticalIndexes: |
|
479 |
number = " possibly defined %d times"%entryinfos["nbmax"] |
|
480 |
if entryinfos["struct"] & OD_IdenticalSubindexes: |
|
481 |
struct = "REC" |
|
482 |
elif entryinfos["struct"] & OD_MultipleSubindexes: |
|
483 |
struct = "ARRAY" |
|
484 |
text = "%s: %s entry of struct %s%s."%(name,category,struct,number) |
|
485 |
self.HelpBar.SetStatusText(text, 2) |
|
486 |
else: |
|
487 |
for i in xrange(3): |
|
488 |
self.HelpBar.SetStatusText("", i) |
|
205 | 489 |
else: |
490 |
for i in xrange(3): |
|
491 |
self.HelpBar.SetStatusText("", i) |
|
0 | 492 |
|
493 |
def RefreshMainMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
494 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
495 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
496 |
self.menuBar1.EnableTop(1, True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
497 |
self.menuBar1.EnableTop(2, True) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
498 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, True) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
499 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, True) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
500 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, True) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
501 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, True) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
502 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, True) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
503 |
else: |
258 | 504 |
self.menuBar1.EnableTop(1, False) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
505 |
self.menuBar1.EnableTop(2, False) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
506 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS1, False) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
507 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS2, False) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
508 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS6, False) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
509 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS8, False) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
510 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUITEMS9, False) |
0 | 511 |
|
512 |
def RefreshEditMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
513 |
if self.FileMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
514 |
if self.FileOpened.GetPageCount() > 0: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
515 |
undo, redo = self.Manager.GetCurrentBufferState() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
516 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, undo) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
517 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, redo) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
518 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
519 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS1, False) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
520 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS0, False) |
0 | 521 |
|
522 |
def RefreshProfileMenu(self): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
523 |
if self.EditMenu: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
524 |
profile = self.Manager.GetCurrentProfileName() |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
525 |
edititem = self.EditMenu.FindItemById(ID_OBJDICTEDITEDITMENUITEMS7) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
526 |
if edititem: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
527 |
length = self.AddMenu.GetMenuItemCount() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
528 |
for i in xrange(length-6): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
529 |
additem = self.AddMenu.FindItemByPosition(6) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
530 |
self.AddMenu.Delete(additem.GetId()) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
531 |
if profile not in ("None", "DS-301"): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
532 |
edititem.SetText("%s Profile"%profile) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
533 |
edititem.Enable(True) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
534 |
self.AddMenu.AppendSeparator() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
535 |
for text, indexes in self.Manager.GetCurrentSpecificMenu(): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
536 |
new_id = wx.NewId() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
537 |
self.AddMenu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=text) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
538 |
self.Bind(wx.EVT_MENU, self.GetProfileCallBack(text), id=new_id) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
539 |
else: |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
540 |
edititem.SetText("Other Profile") |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
541 |
edititem.Enable(False) |
0 | 542 |
|
543 |
||
544 |
#------------------------------------------------------------------------------- |
|
545 |
# Buffer Functions |
|
546 |
#------------------------------------------------------------------------------- |
|
547 |
||
548 |
def RefreshBufferState(self): |
|
549 |
fileopened = self.Manager.GetAllFilenames() |
|
550 |
for idx, filename in enumerate(fileopened): |
|
551 |
self.FileOpened.SetPageText(idx, filename) |
|
552 |
self.RefreshEditMenu() |
|
553 |
self.RefreshTitle() |
|
554 |
||
555 |
def OnUndoMenu(self, event): |
|
556 |
self.Manager.LoadCurrentPrevious() |
|
557 |
self.RefreshCurrentIndexList() |
|
558 |
self.RefreshBufferState() |
|
559 |
event.Skip() |
|
560 |
||
561 |
def OnRedoMenu(self, event): |
|
562 |
self.Manager.LoadCurrentNext() |
|
563 |
self.RefreshCurrentIndexList() |
|
564 |
self.RefreshBufferState() |
|
565 |
event.Skip() |
|
566 |
||
567 |
||
568 |
#------------------------------------------------------------------------------- |
|
569 |
# Load and Save Funtions |
|
570 |
#------------------------------------------------------------------------------- |
|
571 |
||
572 |
def OnNewMenu(self, event): |
|
573 |
self.FilePath = "" |
|
258 | 574 |
dialog = CreateNodeDialog(self) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
575 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 576 |
name, id, nodetype, description = dialog.GetValues() |
59 | 577 |
profile, filepath = dialog.GetProfile() |
578 |
NMT = dialog.GetNMTManagement() |
|
579 |
options = dialog.GetOptions() |
|
205 | 580 |
result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) |
581 |
if type(result) == IntType: |
|
299 | 582 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 583 |
new_editingpanel.SetIndex(result) |
59 | 584 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 585 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
586 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) |
59 | 587 |
if "DS302" in options: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
588 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) |
59 | 589 |
self.RefreshBufferState() |
590 |
self.RefreshProfileMenu() |
|
591 |
self.RefreshMainMenu() |
|
0 | 592 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
593 |
message = wx.MessageDialog(self, result, "ERROR", wx.OK|wx.ICON_ERROR) |
0 | 594 |
message.ShowModal() |
595 |
message.Destroy() |
|
299 | 596 |
dialog.Destroy() |
0 | 597 |
event.Skip() |
598 |
||
599 |
def OnOpenMenu(self, event): |
|
600 |
filepath = self.Manager.GetCurrentFilePath() |
|
601 |
if filepath != "": |
|
602 |
directory = os.path.dirname(filepath) |
|
603 |
else: |
|
604 |
directory = os.getcwd() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
605 |
dialog = wx.FileDialog(self, "Choose a file", directory, "", "OD files (*.od)|*.od|All files|*.*", wx.OPEN|wx.CHANGE_DIR) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
606 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 607 |
filepath = dialog.GetPath() |
608 |
if os.path.isfile(filepath): |
|
609 |
result = self.Manager.OpenFileInCurrent(filepath) |
|
205 | 610 |
if type(result) == IntType: |
299 | 611 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 612 |
new_editingpanel.SetIndex(result) |
0 | 613 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 614 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
0 | 615 |
if self.Manager.CurrentDS302Defined(): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
616 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, True) |
0 | 617 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
618 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUITEMS8, False) |
0 | 619 |
self.RefreshEditMenu() |
620 |
self.RefreshBufferState() |
|
621 |
self.RefreshProfileMenu() |
|
622 |
self.RefreshMainMenu() |
|
623 |
else: |
|
280
d9b232ec7057
Bug on MessageDialog popup when unable to load a file fixed
lbessard
parents:
276
diff
changeset
|
624 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
0 | 625 |
message.ShowModal() |
626 |
message.Destroy() |
|
627 |
dialog.Destroy() |
|
628 |
event.Skip() |
|
629 |
||
630 |
def OnSaveMenu(self, event): |
|
631 |
self.Save() |
|
632 |
event.Skip() |
|
633 |
||
634 |
def OnSaveAsMenu(self, event): |
|
635 |
self.SaveAs() |
|
30 | 636 |
event.Skip() |
0 | 637 |
|
638 |
def Save(self): |
|
639 |
result = self.Manager.SaveCurrentInFile() |
|
640 |
if not result: |
|
641 |
self.SaveAs() |
|
642 |
elif type(result) != StringType: |
|
643 |
self.RefreshBufferState() |
|
644 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
645 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
0 | 646 |
message.ShowModal() |
647 |
message.Destroy() |
|
648 |
||
649 |
def SaveAs(self): |
|
650 |
filepath = self.Manager.GetCurrentFilePath() |
|
651 |
if filepath != "": |
|
652 |
directory, filename = os.path.split(filepath) |
|
653 |
else: |
|
654 |
directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
655 |
dialog = wx.FileDialog(self, "Choose a file", directory, filename, "OD files (*.od)|*.od|All files|*.*", wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
656 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 657 |
filepath = dialog.GetPath() |
658 |
if os.path.isdir(os.path.dirname(filepath)): |
|
659 |
result = self.Manager.SaveCurrentInFile(filepath) |
|
660 |
if type(result) != StringType: |
|
661 |
self.RefreshBufferState() |
|
662 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
663 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
0 | 664 |
message.ShowModal() |
665 |
message.Destroy() |
|
666 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
667 |
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
0 | 668 |
message.ShowModal() |
669 |
message.Destroy() |
|
670 |
dialog.Destroy() |
|
671 |
||
672 |
def OnCloseMenu(self, event): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
673 |
answer = wx.ID_YES |
0 | 674 |
result = self.Manager.CloseCurrent() |
675 |
if not result: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
676 |
dialog = wx.MessageDialog(self, "There are changes, do you want to save?", "Close File", wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
0 | 677 |
answer = dialog.ShowModal() |
678 |
dialog.Destroy() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
679 |
if answer == wx.ID_YES: |
0 | 680 |
self.OnSaveMenu(event) |
681 |
if self.Manager.CurrentIsSaved(): |
|
682 |
self.Manager.CloseCurrent() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
683 |
elif answer == wx.ID_NO: |
0 | 684 |
self.Manager.CloseCurrent(True) |
685 |
if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): |
|
686 |
current = self.FileOpened.GetSelection() |
|
687 |
self.FileOpened.DeletePage(current) |
|
688 |
if self.FileOpened.GetPageCount() > 0: |
|
689 |
self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) |
|
690 |
self.RefreshBufferState() |
|
691 |
self.RefreshMainMenu() |
|
692 |
event.Skip() |
|
693 |
||
694 |
||
695 |
#------------------------------------------------------------------------------- |
|
696 |
# Import and Export Functions |
|
697 |
#------------------------------------------------------------------------------- |
|
698 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
699 |
def OnImportEDSMenu(self, event): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
700 |
dialog = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "EDS files (*.eds)|*.eds|All files|*.*", wx.OPEN|wx.CHANGE_DIR) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
701 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 702 |
filepath = dialog.GetPath() |
703 |
if os.path.isfile(filepath): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
704 |
result = self.Manager.ImportCurrentFromEDSFile(filepath) |
205 | 705 |
if type(result) == IntType: |
299 | 706 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 707 |
new_editingpanel.SetIndex(result) |
708 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
709 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
|
0 | 710 |
self.RefreshBufferState() |
711 |
self.RefreshCurrentIndexList() |
|
712 |
self.RefreshProfileMenu() |
|
713 |
self.RefreshMainMenu() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
714 |
message = wx.MessageDialog(self, "Import successful", "Information", wx.OK|wx.ICON_INFORMATION) |
0 | 715 |
message.ShowModal() |
716 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
717 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
718 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
719 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
720 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
721 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
722 |
message = wx.MessageDialog(self, "\"%s\" is not a valid file!"%filepath, "Error", wx.OK|wx.ICON_ERROR) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
723 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
724 |
message.Destroy() |
0 | 725 |
dialog.Destroy() |
726 |
event.Skip() |
|
727 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
728 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
729 |
def OnExportEDSMenu(self, event): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
730 |
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) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
731 |
if dialog.ShowModal() == wx.ID_OK: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
732 |
filepath = dialog.GetPath() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
733 |
if os.path.isdir(os.path.dirname(filepath)): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
734 |
path, extend = os.path.splitext(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
735 |
if extend in ("", "."): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
736 |
filepath = path + ".eds" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
737 |
result = self.Manager.ExportCurrentToEDSFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
738 |
if not result: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
739 |
message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
740 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
741 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
742 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
743 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
744 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
745 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
746 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
747 |
message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
748 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
749 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
750 |
dialog.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
751 |
event.Skip() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
752 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
753 |
def OnExportCMenu(self, event): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
754 |
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) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
755 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 756 |
filepath = dialog.GetPath() |
757 |
if os.path.isdir(os.path.dirname(filepath)): |
|
758 |
path, extend = os.path.splitext(filepath) |
|
759 |
if extend in ("", "."): |
|
760 |
filepath = path + ".c" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
761 |
result = self.Manager.ExportCurrentToCFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
762 |
if not result: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
763 |
message = wx.MessageDialog(self, "Export successful", "Information", wx.OK|wx.ICON_INFORMATION) |
0 | 764 |
message.ShowModal() |
765 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
766 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
767 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
768 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
769 |
message.Destroy() |
0 | 770 |
else: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
771 |
message = wx.MessageDialog(self, "\"%s\" is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR) |
0 | 772 |
message.ShowModal() |
773 |
message.Destroy() |
|
774 |
dialog.Destroy() |
|
775 |
event.Skip() |
|
776 |
||
777 |
#------------------------------------------------------------------------------- |
|
778 |
# Editing Profiles functions |
|
779 |
#------------------------------------------------------------------------------- |
|
780 |
||
781 |
def OnCommunicationMenu(self, event): |
|
782 |
dictionary,current = self.Manager.GetCurrentCommunicationLists() |
|
783 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
784 |
event.Skip() |
|
785 |
||
786 |
def OnOtherCommunicationMenu(self, event): |
|
787 |
dictionary,current = self.Manager.GetCurrentDS302Lists() |
|
788 |
self.EditProfile("Edit DS-301 Profile", dictionary, current) |
|
789 |
event.Skip() |
|
790 |
||
791 |
def OnEditProfileMenu(self, event): |
|
792 |
title = "Edit %s Profile"%self.Manager.GetCurrentProfileName() |
|
793 |
dictionary,current = self.Manager.GetCurrentProfileLists() |
|
794 |
self.EditProfile(title, dictionary, current) |
|
795 |
event.Skip() |
|
796 |
||
797 |
def EditProfile(self, title, dictionary, current): |
|
798 |
dialog = CommunicationDialog(self) |
|
799 |
dialog.SetTitle(title) |
|
800 |
dialog.SetIndexDictionary(dictionary) |
|
801 |
dialog.SetCurrentList(current) |
|
802 |
dialog.RefreshLists() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
803 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 804 |
new_profile = dialog.GetCurrentList() |
805 |
addinglist = [] |
|
806 |
removinglist = [] |
|
807 |
for index in new_profile: |
|
808 |
if index not in current: |
|
809 |
addinglist.append(index) |
|
810 |
for index in current: |
|
811 |
if index not in new_profile: |
|
812 |
removinglist.append(index) |
|
813 |
self.Manager.ManageEntriesOfCurrent(addinglist, removinglist) |
|
814 |
self.Manager.BufferCurrentNode() |
|
815 |
self.RefreshBufferState() |
|
816 |
self.RefreshCurrentIndexList() |
|
817 |
dialog.Destroy() |
|
818 |
||
819 |
def GetProfileCallBack(self, text): |
|
820 |
def ProfileCallBack(event): |
|
821 |
self.Manager.AddSpecificEntryToCurrent(text) |
|
822 |
self.RefreshBufferState() |
|
823 |
self.RefreshCurrentIndexList() |
|
824 |
event.Skip() |
|
825 |
return ProfileCallBack |
|
826 |
||
827 |
#------------------------------------------------------------------------------- |
|
828 |
# Edit Node informations function |
|
829 |
#------------------------------------------------------------------------------- |
|
830 |
||
831 |
def OnNodeInfosMenu(self, event): |
|
832 |
dialog = NodeInfosDialog(self) |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
833 |
name, id, type, description = self.Manager.GetCurrentNodeInfos() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
834 |
dialog.SetValues(name, id, type, description) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
835 |
if dialog.ShowModal() == wx.ID_OK: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
836 |
name, id, type, description = dialog.GetValues() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
837 |
self.Manager.SetCurrentNodeInfos(name, id, type, description) |
0 | 838 |
self.RefreshBufferState() |
839 |
self.RefreshProfileMenu() |
|
205 | 840 |
selected = self.FileOpened.GetSelection() |
841 |
if selected >= 0: |
|
842 |
window = self.FileOpened.GetPage(selected) |
|
843 |
window.RefreshTable() |
|
0 | 844 |
event.Skip() |
845 |
||
846 |
||
847 |
#------------------------------------------------------------------------------- |
|
848 |
# Add User Types and Variables |
|
849 |
#------------------------------------------------------------------------------- |
|
850 |
||
851 |
def AddMapVariable(self): |
|
39 | 852 |
index = self.Manager.GetCurrentNextMapIndex() |
853 |
if index: |
|
854 |
dialog = MapVariableDialog(self) |
|
855 |
dialog.SetIndex(index) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
856 |
if dialog.ShowModal() == wx.ID_OK: |
39 | 857 |
index, name, struct, number = dialog.GetValues() |
858 |
result = self.Manager.AddMapVariableToCurrent(index, name, struct, number) |
|
859 |
if type(result) != StringType: |
|
860 |
self.RefreshBufferState() |
|
861 |
self.RefreshCurrentIndexList() |
|
862 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
863 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
39 | 864 |
message.ShowModal() |
865 |
message.Destroy() |
|
866 |
dialog.Destroy() |
|
867 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
868 |
message = wx.MessageDialog(self, result, "No map variable index left!", wx.OK|wx.ICON_ERROR) |
39 | 869 |
message.ShowModal() |
870 |
message.Destroy() |
|
0 | 871 |
|
872 |
def AddUserType(self): |
|
873 |
dialog = UserTypeDialog(self) |
|
874 |
dialog.SetTypeList(self.Manager.GetCustomisableTypes()) |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
875 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 876 |
type, min, max, length = dialog.GetValues() |
877 |
result = self.Manager.AddUserTypeToCurrent(type, min, max, length) |
|
205 | 878 |
if not result: |
0 | 879 |
self.RefreshBufferState() |
880 |
self.RefreshCurrentIndexList() |
|
881 |
else: |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
882 |
message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR) |
0 | 883 |
message.ShowModal() |
884 |
message.Destroy() |
|
885 |
dialog.Destroy() |
|
886 |
||
887 |
||
888 |
#------------------------------------------------------------------------------- |
|
889 |
# Exception Handler |
|
890 |
#------------------------------------------------------------------------------- |
|
891 |
||
892 |
Max_Traceback_List_Size = 20 |
|
893 |
||
894 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
895 |
trcbck_lst = [] |
|
896 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
897 |
trcbck = " " + str(i+1) + ". " |
|
898 |
if line[0].find(os.getcwd()) == -1: |
|
899 |
trcbck += "file : " + str(line[0]) + ", " |
|
900 |
else: |
|
901 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
|
902 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
|
903 |
trcbck_lst.append(trcbck) |
|
904 |
||
905 |
# Allow clicking.... |
|
906 |
cap = wx.Window_GetCapture() |
|
907 |
if cap: |
|
908 |
cap.ReleaseMouse() |
|
909 |
||
910 |
dlg = wx.SingleChoiceDialog(None, |
|
911 |
""" |
|
912 |
An error happens. |
|
913 |
||
914 |
Click on OK for saving an error report. |
|
915 |
||
916 |
Please contact LOLITech at: |
|
917 |
+33 (0)3 29 52 95 67 |
|
918 |
bugs_objdictedit@lolitech.fr |
|
919 |
||
920 |
||
921 |
Error: |
|
922 |
""" + |
|
923 |
str(e_type) + " : " + str(e_value), |
|
924 |
"Error", |
|
925 |
trcbck_lst) |
|
926 |
try: |
|
927 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
928 |
finally: |
|
929 |
dlg.Destroy() |
|
930 |
||
931 |
return res |
|
932 |
||
933 |
def Display_Error_Dialog(e_value): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
934 |
message = wx.MessageDialog(None, str(e_value), "Error", wx.OK|wx.ICON_ERROR) |
0 | 935 |
message.ShowModal() |
936 |
message.Destroy() |
|
937 |
||
938 |
def get_last_traceback(tb): |
|
939 |
while tb.tb_next: |
|
940 |
tb = tb.tb_next |
|
941 |
return tb |
|
942 |
||
943 |
||
944 |
def format_namespace(d, indent=' '): |
|
945 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
946 |
||
947 |
||
948 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
949 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
950 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 951 |
|
952 |
def handle_exception(e_type, e_value, e_traceback): |
|
953 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
954 |
last_tb = get_last_traceback(e_traceback) |
|
955 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
956 |
if str(e_value).startswith("!!!"): |
|
957 |
Display_Error_Dialog(e_value) |
|
958 |
elif ex not in ignored_exceptions: |
|
959 |
ignored_exceptions.append(ex) |
|
960 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
961 |
if result: |
|
962 |
info = { |
|
963 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
964 |
'app-version' : app_version, |
|
965 |
'wx-version' : wx.VERSION_STRING, |
|
966 |
'wx-platform' : wx.Platform, |
|
967 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
968 |
'platform' : platform.platform(), |
|
969 |
'e-type' : e_type, |
|
970 |
'e-value' : e_value, |
|
971 |
'date' : time.ctime(), |
|
972 |
'cwd' : os.getcwd(), |
|
973 |
} |
|
974 |
if e_traceback: |
|
975 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
976 |
last_tb = get_last_traceback(e_traceback) |
|
977 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
978 |
info['locals'] = format_namespace(exception_locals) |
|
979 |
if 'self' in exception_locals: |
|
980 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
981 |
||
982 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
983 |
lst = info.keys() |
|
984 |
lst.sort() |
|
985 |
for a in lst: |
|
986 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
987 |
||
988 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
989 |
sys.excepthook = handle_exception |
|
990 |
||
991 |
if __name__ == '__main__': |
|
276 | 992 |
def usage(): |
993 |
print "\nUsage of objdictedit.py :" |
|
994 |
print "\n %s [Filepath, ...]\n"%sys.argv[0] |
|
995 |
||
996 |
try: |
|
997 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
998 |
except getopt.GetoptError: |
|
999 |
# print help information and exit: |
|
1000 |
usage() |
|
1001 |
sys.exit(2) |
|
1002 |
||
1003 |
for o, a in opts: |
|
1004 |
if o in ("-h", "--help"): |
|
1005 |
usage() |
|
1006 |
sys.exit() |
|
1007 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
1008 |
app = wx.PySimpleApp() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
1009 |
wx.InitAllImageHandlers() |
0 | 1010 |
|
1011 |
# Install a exception handle for bug reports |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
1012 |
AddExceptHook(os.getcwd(),__version__) |
0 | 1013 |
|
276 | 1014 |
frame = objdictedit(None, args) |
0 | 1015 |
|
1016 |
frame.Show() |
|
1017 |
app.MainLoop() |