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