author | Edouard Tisserant |
Mon, 23 Apr 2018 12:32:03 +0200 | |
changeset 805 | 570e3a444023 |
parent 778 | 9edaa9d21cf9 |
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 |
|
76 |
from nodemanager import * |
|
778
9edaa9d21cf9
Fixed conflict in internationalization with Beremiz CanFestival extension
Laurent Bessard
parents:
715
diff
changeset
|
77 |
from nodeeditortemplate import NodeEditorTemplate |
205 | 78 |
from subindextable import * |
79 |
from commondialogs import * |
|
0 | 80 |
from doc_index.DS301_index import * |
81 |
||
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
82 |
try: |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
83 |
import wx.html |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
84 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
85 |
EVT_HTML_URL_CLICK = wx.NewId() |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
86 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
87 |
class HtmlWindowUrlClick(wx.PyEvent): |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
88 |
def __init__(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
89 |
wx.PyEvent.__init__(self) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
90 |
self.SetEventType(EVT_HTML_URL_CLICK) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
91 |
self.linkinfo = (linkinfo.GetHref(), linkinfo.GetTarget()) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
92 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
93 |
class UrlClickHtmlWindow(wx.html.HtmlWindow): |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
94 |
""" HTML window that generates and OnLinkClicked event. |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
95 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
96 |
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
|
97 |
""" |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
98 |
def OnLinkClicked(self, linkinfo): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
99 |
wx.PostEvent(self, HtmlWindowUrlClick(linkinfo)) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
100 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
101 |
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
|
102 |
if event == HtmlWindowUrlClick: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
103 |
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
|
104 |
else: |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
105 |
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
|
106 |
|
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 |
# Html Frame |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
109 |
#------------------------------------------------------------------------------- |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
110 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
111 |
[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
|
112 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
113 |
class HtmlFrame(wx.Frame): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
114 |
def _init_ctrls(self, prnt): |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
style=wx.DEFAULT_FRAME_STYLE, title='') |
273 | 118 |
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
|
119 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
120 |
self.HtmlContent = UrlClickHtmlWindow(id=ID_HTMLFRAMEHTMLCONTENT, |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
self.HtmlContent.Bind(HtmlWindowUrlClick, self.OnLinkClick) |
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
124 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
125 |
def __init__(self, parent, opened): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
126 |
self._init_ctrls(parent) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
127 |
self.HtmlFrameOpened = opened |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
128 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
129 |
def SetHtmlCode(self, htmlcode): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
130 |
self.HtmlContent.SetPage(htmlcode) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
131 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
132 |
def SetHtmlPage(self, htmlpage): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
133 |
self.HtmlContent.LoadPage(htmlpage) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
134 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
135 |
def OnCloseFrame(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
136 |
self.HtmlFrameOpened.remove(self.GetTitle()) |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
137 |
event.Skip() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
138 |
|
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
139 |
def OnLinkClick(self, event): |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
140 |
url = event.linkinfo[0] |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
141 |
try: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
142 |
import webbrowser |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
143 |
except ImportError: |
580 | 144 |
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
|
145 |
else: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
146 |
webbrowser.open(url) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
147 |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
148 |
Html_Window = True |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
149 |
except: |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
150 |
Html_Window = False |
0 | 151 |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
152 |
[ID_OBJDICTEDIT, ID_OBJDICTEDITFILEOPENED, |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
153 |
ID_OBJDICTEDITHELPBAR, |
0 | 154 |
] = [wx.NewId() for _init_ctrls in range(3)] |
155 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
156 |
[ID_OBJDICTEDITFILEMENUIMPORTEDS, ID_OBJDICTEDITFILEMENUEXPORTEDS, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
157 |
ID_OBJDICTEDITFILEMENUEXPORTC, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
158 |
] = [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
|
159 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
160 |
[ID_OBJDICTEDITEDITMENUNODEINFOS, ID_OBJDICTEDITEDITMENUDS301PROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
161 |
ID_OBJDICTEDITEDITMENUDS302PROFILE, ID_OBJDICTEDITEDITMENUOTHERPROFILE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
162 |
] = [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
|
163 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
164 |
[ID_OBJDICTEDITADDMENUSDOSERVER, ID_OBJDICTEDITADDMENUSDOCLIENT, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
165 |
ID_OBJDICTEDITADDMENUPDOTRANSMIT, ID_OBJDICTEDITADDMENUPDORECEIVE, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
166 |
ID_OBJDICTEDITADDMENUMAPVARIABLE, ID_OBJDICTEDITADDMENUUSERTYPE, |
0 | 167 |
] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)] |
168 |
||
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
169 |
class objdictedit(wx.Frame, NodeEditorTemplate): |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
170 |
|
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
171 |
EDITMENU_ID = ID_OBJDICTEDITEDITMENUOTHERPROFILE |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
172 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
173 |
def _init_coll_MenuBar_Menus(self, parent): |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
174 |
if self.ModeSolo: |
580 | 175 |
parent.Append(menu=self.FileMenu, title=_('File')) |
176 |
parent.Append(menu=self.EditMenu, title=_('Edit')) |
|
177 |
parent.Append(menu=self.AddMenu, title=_('Add')) |
|
178 |
parent.Append(menu=self.HelpMenu, title=_('Help')) |
|
0 | 179 |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
180 |
def _init_coll_FileMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
181 |
parent.Append(help='', id=wx.ID_NEW, |
580 | 182 |
kind=wx.ITEM_NORMAL, text=_('New\tCTRL+N')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
183 |
parent.Append(help='', id=wx.ID_OPEN, |
580 | 184 |
kind=wx.ITEM_NORMAL, text=_('Open\tCTRL+O')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
185 |
parent.Append(help='', id=wx.ID_CLOSE, |
580 | 186 |
kind=wx.ITEM_NORMAL, text=_('Close\tCTRL+W')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
187 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
188 |
parent.Append(help='', id=wx.ID_SAVE, |
580 | 189 |
kind=wx.ITEM_NORMAL, text=_('Save\tCTRL+S')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
190 |
parent.Append(help='', id=wx.ID_SAVEAS, |
580 | 191 |
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
|
192 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
193 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUIMPORTEDS, |
580 | 194 |
kind=wx.ITEM_NORMAL, text=_('Import EDS file')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
195 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUEXPORTEDS, |
580 | 196 |
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
|
197 |
parent.Append(help='', id=ID_OBJDICTEDITFILEMENUEXPORTC, |
580 | 198 |
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
|
199 |
parent.AppendSeparator() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
200 |
parent.Append(help='', id=wx.ID_EXIT, |
580 | 201 |
kind=wx.ITEM_NORMAL, text=_('Exit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
self.Bind(wx.EVT_MENU, self.OnImportEDSMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
208 |
id=ID_OBJDICTEDITFILEMENUIMPORTEDS) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
209 |
self.Bind(wx.EVT_MENU, self.OnExportEDSMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
210 |
id=ID_OBJDICTEDITFILEMENUEXPORTEDS) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
211 |
self.Bind(wx.EVT_MENU, self.OnExportCMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
212 |
id=ID_OBJDICTEDITFILEMENUEXPORTC) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
213 |
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
|
214 |
|
0 | 215 |
def _init_coll_EditMenu_Items(self, parent): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
216 |
parent.Append(help='', id=wx.ID_REFRESH, |
580 | 217 |
kind=wx.ITEM_NORMAL, text=_('Refresh\tCTRL+R')) |
0 | 218 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
219 |
parent.Append(help='', id=wx.ID_UNDO, |
580 | 220 |
kind=wx.ITEM_NORMAL, text=_('Undo\tCTRL+Z')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
221 |
parent.Append(help='', id=wx.ID_REDO, |
580 | 222 |
kind=wx.ITEM_NORMAL, text=_('Redo\tCTRL+Y')) |
0 | 223 |
parent.AppendSeparator() |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
224 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUNODEINFOS, |
580 | 225 |
kind=wx.ITEM_NORMAL, text=_('Node infos')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
226 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUDS301PROFILE, |
580 | 227 |
kind=wx.ITEM_NORMAL, text=_('DS-301 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
228 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUDS302PROFILE, |
580 | 229 |
kind=wx.ITEM_NORMAL, text=_('DS-302 Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
230 |
parent.Append(help='', id=ID_OBJDICTEDITEDITMENUOTHERPROFILE, |
580 | 231 |
kind=wx.ITEM_NORMAL, text=_('Other Profile')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
self.Bind(wx.EVT_MENU, self.OnNodeInfosMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
236 |
id=ID_OBJDICTEDITEDITMENUNODEINFOS) |
0 | 237 |
self.Bind(wx.EVT_MENU, self.OnCommunicationMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
238 |
id=ID_OBJDICTEDITEDITMENUDS301PROFILE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
239 |
self.Bind(wx.EVT_MENU, self.OnOtherCommunicationMenu, |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
240 |
id=ID_OBJDICTEDITEDITMENUDS302PROFILE) |
0 | 241 |
self.Bind(wx.EVT_MENU, self.OnEditProfileMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
242 |
id=ID_OBJDICTEDITEDITMENUOTHERPROFILE) |
0 | 243 |
|
244 |
def _init_coll_AddMenu_Items(self, parent): |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
245 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUSDOSERVER, |
580 | 246 |
kind=wx.ITEM_NORMAL, text=_('SDO Server')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
247 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUSDOCLIENT, |
580 | 248 |
kind=wx.ITEM_NORMAL, text=_('SDO Client')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
249 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUPDOTRANSMIT, |
580 | 250 |
kind=wx.ITEM_NORMAL, text=_('PDO Transmit')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
251 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUPDORECEIVE, |
580 | 252 |
kind=wx.ITEM_NORMAL, text=_('PDO Receive')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
253 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUMAPVARIABLE, |
580 | 254 |
kind=wx.ITEM_NORMAL, text=_('Map Variable')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
255 |
parent.Append(help='', id=ID_OBJDICTEDITADDMENUUSERTYPE, |
580 | 256 |
kind=wx.ITEM_NORMAL, text=_('User Type')) |
0 | 257 |
self.Bind(wx.EVT_MENU, self.OnAddSDOServerMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
258 |
id=ID_OBJDICTEDITADDMENUSDOSERVER) |
0 | 259 |
self.Bind(wx.EVT_MENU, self.OnAddSDOClientMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
260 |
id=ID_OBJDICTEDITADDMENUSDOCLIENT) |
0 | 261 |
self.Bind(wx.EVT_MENU, self.OnAddPDOTransmitMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
262 |
id=ID_OBJDICTEDITADDMENUPDOTRANSMIT) |
0 | 263 |
self.Bind(wx.EVT_MENU, self.OnAddPDOReceiveMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
264 |
id=ID_OBJDICTEDITADDMENUPDORECEIVE) |
0 | 265 |
self.Bind(wx.EVT_MENU, self.OnAddMapVariableMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
266 |
id=ID_OBJDICTEDITADDMENUMAPVARIABLE) |
0 | 267 |
self.Bind(wx.EVT_MENU, self.OnAddUserTypeMenu, |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
268 |
id=ID_OBJDICTEDITADDMENUUSERTYPE) |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
269 |
|
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
270 |
def _init_coll_HelpMenu_Items(self, parent): |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
271 |
parent.Append(help='', id=wx.ID_HELP, |
580 | 272 |
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
|
273 |
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
|
274 |
parent.Append(help='', id=wx.ID_HELP_CONTEXT, |
580 | 275 |
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
|
276 |
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
|
277 |
if Html_Window and self.ModeSolo: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
278 |
parent.Append(help='', id=wx.ID_ABOUT, |
580 | 279 |
kind=wx.ITEM_NORMAL, text=_('About')) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
280 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
0 | 281 |
|
282 |
def _init_coll_HelpBar_Fields(self, parent): |
|
283 |
parent.SetFieldsCount(3) |
|
284 |
||
285 |
parent.SetStatusText(number=0, text='') |
|
286 |
parent.SetStatusText(number=1, text='') |
|
287 |
parent.SetStatusText(number=2, text='') |
|
288 |
||
289 |
parent.SetStatusWidths([100, 110, -1]) |
|
290 |
||
291 |
def _init_utils(self): |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
292 |
self.MenuBar = wx.MenuBar() |
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
293 |
self.MenuBar.SetEvtHandlerEnabled(True) |
0 | 294 |
|
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
295 |
if self.ModeSolo: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
296 |
self.FileMenu = wx.Menu(title='') |
0 | 297 |
self.EditMenu = wx.Menu(title='') |
298 |
self.AddMenu = wx.Menu(title='') |
|
299 |
self.HelpMenu = wx.Menu(title='') |
|
300 |
||
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
301 |
self._init_coll_MenuBar_Menus(self.MenuBar) |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
302 |
if self.ModeSolo: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
303 |
self._init_coll_FileMenu_Items(self.FileMenu) |
0 | 304 |
self._init_coll_EditMenu_Items(self.EditMenu) |
305 |
self._init_coll_AddMenu_Items(self.AddMenu) |
|
306 |
self._init_coll_HelpMenu_Items(self.HelpMenu) |
|
307 |
||
308 |
def _init_ctrls(self, prnt): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
309 |
wx.Frame.__init__(self, id=ID_OBJDICTEDIT, name='objdictedit', |
0 | 310 |
parent=prnt, pos=wx.Point(149, 178), size=wx.Size(1000, 700), |
580 | 311 |
style=wx.DEFAULT_FRAME_STYLE, title=_('Objdictedit')) |
0 | 312 |
self._init_utils() |
313 |
self.SetClientSize(wx.Size(1000, 700)) |
|
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
314 |
self.SetMenuBar(self.MenuBar) |
273 | 315 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
316 |
if not self.ModeSolo: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
self.SetAcceleratorTable(accel) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
320 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
321 |
self.FileOpened = wx.Notebook(id=ID_OBJDICTEDITFILEOPENED, |
0 | 322 |
name='FileOpened', parent=self, pos=wx.Point(0, 0), |
323 |
size=wx.Size(0, 0), style=0) |
|
324 |
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
|
325 |
self.OnFileSelectedChanged, id=ID_OBJDICTEDITFILEOPENED) |
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
326 |
|
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
327 |
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
|
328 |
parent=self, style=wx.ST_SIZEGRIP) |
0 | 329 |
self._init_coll_HelpBar_Fields(self.HelpBar) |
330 |
self.SetStatusBar(self.HelpBar) |
|
331 |
||
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
332 |
def __init__(self, parent, manager = None, filesOpen = []): |
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
333 |
if manager is None: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
334 |
NodeEditorTemplate.__init__(self, NodeManager(), self, True) |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
335 |
else: |
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
336 |
NodeEditorTemplate.__init__(self, manager, self, False) |
0 | 337 |
self._init_ctrls(parent) |
338 |
self.HtmlFrameOpened = [] |
|
339 |
||
410 | 340 |
icon = wx.Icon(os.path.join(ScriptDirectory,"networkedit.ico"),wx.BITMAP_TYPE_ICO) |
409 | 341 |
self.SetIcon(icon) |
342 |
||
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
343 |
if self.ModeSolo: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
344 |
for filepath in filesOpen: |
527
7d5c74cc8f91
- Fix bug with relative path when node opened from command line
greg
parents:
512
diff
changeset
|
345 |
result = self.Manager.OpenFileInCurrent(os.path.abspath(filepath)) |
512 | 346 |
if isinstance(result, (IntType, LongType)): |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
347 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
348 |
new_editingpanel.SetIndex(result) |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
349 |
self.FileOpened.AddPage(new_editingpanel, "") |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
350 |
else: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
351 |
for index in self.Manager.GetBufferIndexes(): |
299 | 352 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
353 |
new_editingpanel.SetIndex(index) |
232 | 354 |
self.FileOpened.AddPage(new_editingpanel, "") |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
355 |
|
491 | 356 |
if self.Manager.GetBufferNumber() > 0: |
357 |
window = self.FileOpened.GetPage(0) |
|
358 |
if window: |
|
359 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
360 |
self.FileOpened.SetSelection(0) |
|
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
361 |
|
258 | 362 |
if self.Manager.CurrentDS302Defined(): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
363 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, True) |
0 | 364 |
else: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
365 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, False) |
0 | 366 |
self.RefreshEditMenu() |
367 |
self.RefreshBufferState() |
|
368 |
self.RefreshProfileMenu() |
|
369 |
self.RefreshTitle() |
|
370 |
self.RefreshMainMenu() |
|
371 |
||
372 |
def OnFileSelectedChanged(self, event): |
|
491 | 373 |
if not self.Closing: |
374 |
selected = event.GetSelection() |
|
375 |
# At init selected = -1 |
|
376 |
if selected >= 0: |
|
377 |
window = self.FileOpened.GetPage(selected) |
|
378 |
if window: |
|
379 |
self.Manager.ChangeCurrentNode(window.GetIndex()) |
|
380 |
wx.CallAfter(self.RefreshBufferState) |
|
381 |
self.RefreshStatusBar() |
|
382 |
self.RefreshProfileMenu() |
|
0 | 383 |
event.Skip() |
384 |
||
385 |
def OnHelpDS301Menu(self, event): |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
386 |
find_index = False |
0 | 387 |
selected = self.FileOpened.GetSelection() |
388 |
if selected >= 0: |
|
389 |
window = self.FileOpened.GetPage(selected) |
|
390 |
result = window.GetSelection() |
|
391 |
if result: |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
392 |
find_index = True |
0 | 393 |
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
|
394 |
result = OpenPDFDocIndex(index, ScriptDirectory) |
512 | 395 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 396 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
0 | 397 |
message.ShowModal() |
398 |
message.Destroy() |
|
72
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
399 |
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
|
400 |
result = OpenPDFDocIndex(None, ScriptDirectory) |
512 | 401 |
if isinstance(result, (StringType, UnicodeType)): |
580 | 402 |
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
|
403 |
message.ShowModal() |
68524f7c58b5
Code for avoiding possible problem on Window while importing html module
lbessard
parents:
68
diff
changeset
|
404 |
message.Destroy() |
0 | 405 |
|
406 |
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
|
407 |
#self.OpenHtmlFrame("CAN Festival Reference", os.path.join(ScriptDirectory, "doc/canfestival.html"), wx.Size(1000, 600)) |
341 | 408 |
if wx.Platform == '__WXMSW__': |
386
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
348
diff
changeset
|
409 |
readerpath = get_acroversion() |
0f56a144ba5f
Now, PDF doc of objdictgen can be opened with acrobat reader on windows
etisserant
parents:
348
diff
changeset
|
410 |
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
|
411 |
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
|
412 |
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
|
413 |
else: |
580 | 414 |
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
|
415 |
message.ShowModal() |
ecaac955c16a
fix message dialog when objdictedit can't find the pdf reader
greg
parents:
548
diff
changeset
|
416 |
message.Destroy() |
ecaac955c16a
fix message dialog when objdictedit can't find the pdf reader
greg
parents:
548
diff
changeset
|
417 |
else: |
ecaac955c16a
fix message dialog when objdictedit can't find the pdf reader
greg
parents:
548
diff
changeset
|
418 |
try: |
ecaac955c16a
fix message dialog when objdictedit can't find the pdf reader
greg
parents:
548
diff
changeset
|
419 |
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
|
420 |
except: |
580 | 421 |
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
|
422 |
message.ShowModal() |
ecaac955c16a
fix message dialog when objdictedit can't find the pdf reader
greg
parents:
548
diff
changeset
|
423 |
message.Destroy() |
608 | 424 |
|
0 | 425 |
def OnAboutMenu(self, event): |
580 | 426 |
self.OpenHtmlFrame(_("About CAN Festival"), os.path.join(ScriptDirectory, "doc/about.html"), wx.Size(500, 450)) |
608 | 427 |
|
0 | 428 |
def OpenHtmlFrame(self, title, file, size): |
429 |
if title not in self.HtmlFrameOpened: |
|
430 |
self.HtmlFrameOpened.append(title) |
|
431 |
window = HtmlFrame(self, self.HtmlFrameOpened) |
|
432 |
window.SetTitle(title) |
|
433 |
window.SetHtmlPage(file) |
|
434 |
window.SetClientSize(size) |
|
435 |
window.Show() |
|
436 |
||
437 |
def OnQuitMenu(self, event): |
|
438 |
self.Close() |
|
608 | 439 |
|
0 | 440 |
def OnCloseFrame(self, event): |
491 | 441 |
self.Closing = True |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
442 |
if not self.ModeSolo: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
443 |
if getattr(self, "_onclose", None) != None: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
444 |
self._onclose() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
445 |
event.Skip() |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
446 |
elif self.Manager.OneFileHasChanged(): |
580 | 447 |
dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), _("Close Application"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
0 | 448 |
answer = dialog.ShowModal() |
449 |
dialog.Destroy() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
450 |
if answer == wx.ID_YES: |
491 | 451 |
for i in xrange(self.Manager.GetBufferNumber()): |
0 | 452 |
if self.Manager.CurrentIsSaved(): |
453 |
self.Manager.CloseCurrent() |
|
454 |
else: |
|
455 |
self.Save() |
|
456 |
self.Manager.CloseCurrent(True) |
|
457 |
event.Skip() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
458 |
elif answer == wx.ID_NO: |
0 | 459 |
event.Skip() |
491 | 460 |
else: |
461 |
event.Veto() |
|
0 | 462 |
else: |
463 |
event.Skip() |
|
464 |
||
465 |
#------------------------------------------------------------------------------- |
|
466 |
# Refresh Functions |
|
467 |
#------------------------------------------------------------------------------- |
|
468 |
||
469 |
def RefreshTitle(self): |
|
470 |
if self.FileOpened.GetPageCount() > 0: |
|
580 | 471 |
self.SetTitle(_("Objdictedit - %s")%self.Manager.GetCurrentFilename()) |
472 |
else: |
|
473 |
self.SetTitle(_("Objdictedit")) |
|
0 | 474 |
|
475 |
def RefreshCurrentIndexList(self): |
|
476 |
selected = self.FileOpened.GetSelection() |
|
477 |
window = self.FileOpened.GetPage(selected) |
|
478 |
window.RefreshIndexList() |
|
479 |
||
480 |
def RefreshStatusBar(self): |
|
491 | 481 |
selected = self.FileOpened.GetSelection() |
482 |
if selected >= 0: |
|
483 |
window = self.FileOpened.GetPage(selected) |
|
715
5795fb789230
Adding support for integration of panels in Beremiz
smarteh-dev
parents:
614
diff
changeset
|
484 |
self.SetStatusBarText(window.GetSelection(), self.Manager) |
0 | 485 |
|
486 |
def RefreshMainMenu(self): |
|
491 | 487 |
if self.FileOpened.GetPageCount() > 0: |
488 |
if self.ModeSolo: |
|
489 |
self.MenuBar.EnableTop(1, True) |
|
490 |
self.MenuBar.EnableTop(2, True) |
|
491 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
492 |
self.FileMenu.Enable(wx.ID_SAVE, True) |
|
493 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
|
494 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUEXPORTEDS, True) |
|
495 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUEXPORTC, True) |
|
496 |
else: |
|
497 |
self.MenuBar.EnableTop(0, True) |
|
498 |
self.MenuBar.EnableTop(1, True) |
|
499 |
else: |
|
500 |
if self.ModeSolo: |
|
501 |
self.MenuBar.EnableTop(1, False) |
|
502 |
self.MenuBar.EnableTop(2, False) |
|
503 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
504 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
505 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
|
506 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUEXPORTEDS, False) |
|
507 |
self.FileMenu.Enable(ID_OBJDICTEDITFILEMENUEXPORTC, False) |
|
508 |
else: |
|
509 |
self.MenuBar.EnableTop(0, False) |
|
510 |
self.MenuBar.EnableTop(1, False) |
|
0 | 511 |
|
512 |
def RefreshEditMenu(self): |
|
491 | 513 |
if self.FileOpened.GetPageCount() > 0: |
514 |
undo, redo = self.Manager.GetCurrentBufferState() |
|
515 |
self.EditMenu.Enable(wx.ID_UNDO, undo) |
|
516 |
self.EditMenu.Enable(wx.ID_REDO, redo) |
|
517 |
else: |
|
518 |
self.EditMenu.Enable(wx.ID_UNDO, False) |
|
519 |
self.EditMenu.Enable(wx.ID_REDO, False) |
|
0 | 520 |
|
521 |
#------------------------------------------------------------------------------- |
|
522 |
# Buffer Functions |
|
523 |
#------------------------------------------------------------------------------- |
|
524 |
||
525 |
def RefreshBufferState(self): |
|
526 |
fileopened = self.Manager.GetAllFilenames() |
|
527 |
for idx, filename in enumerate(fileopened): |
|
528 |
self.FileOpened.SetPageText(idx, filename) |
|
529 |
self.RefreshEditMenu() |
|
530 |
self.RefreshTitle() |
|
531 |
||
532 |
#------------------------------------------------------------------------------- |
|
533 |
# Load and Save Funtions |
|
534 |
#------------------------------------------------------------------------------- |
|
535 |
||
536 |
def OnNewMenu(self, event): |
|
537 |
self.FilePath = "" |
|
258 | 538 |
dialog = CreateNodeDialog(self) |
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
539 |
if dialog.ShowModal() == wx.ID_OK: |
205 | 540 |
name, id, nodetype, description = dialog.GetValues() |
59 | 541 |
profile, filepath = dialog.GetProfile() |
542 |
NMT = dialog.GetNMTManagement() |
|
543 |
options = dialog.GetOptions() |
|
205 | 544 |
result = self.Manager.CreateNewNode(name, id, nodetype, description, profile, filepath, NMT, options) |
512 | 545 |
if isinstance(result, (IntType, LongType)): |
299 | 546 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 547 |
new_editingpanel.SetIndex(result) |
59 | 548 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 549 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
550 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, False) |
59 | 551 |
if "DS302" in options: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
552 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, True) |
59 | 553 |
self.RefreshBufferState() |
554 |
self.RefreshProfileMenu() |
|
555 |
self.RefreshMainMenu() |
|
0 | 556 |
else: |
580 | 557 |
message = wx.MessageDialog(self, result, _("ERROR"), wx.OK|wx.ICON_ERROR) |
0 | 558 |
message.ShowModal() |
559 |
message.Destroy() |
|
299 | 560 |
dialog.Destroy() |
608 | 561 |
|
0 | 562 |
def OnOpenMenu(self, event): |
563 |
filepath = self.Manager.GetCurrentFilePath() |
|
564 |
if filepath != "": |
|
565 |
directory = os.path.dirname(filepath) |
|
566 |
else: |
|
567 |
directory = os.getcwd() |
|
580 | 568 |
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
|
569 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 570 |
filepath = dialog.GetPath() |
571 |
if os.path.isfile(filepath): |
|
572 |
result = self.Manager.OpenFileInCurrent(filepath) |
|
512 | 573 |
if isinstance(result, (IntType, LongType)): |
299 | 574 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 575 |
new_editingpanel.SetIndex(result) |
0 | 576 |
self.FileOpened.AddPage(new_editingpanel, "") |
205 | 577 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
0 | 578 |
if self.Manager.CurrentDS302Defined(): |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
579 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, True) |
0 | 580 |
else: |
418
64a8c24b61a5
Problem with String size in C file generated fixed
lbessard
parents:
410
diff
changeset
|
581 |
self.EditMenu.Enable(ID_OBJDICTEDITEDITMENUDS302PROFILE, False) |
0 | 582 |
self.RefreshEditMenu() |
583 |
self.RefreshBufferState() |
|
584 |
self.RefreshProfileMenu() |
|
585 |
self.RefreshMainMenu() |
|
586 |
else: |
|
580 | 587 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 588 |
message.ShowModal() |
589 |
message.Destroy() |
|
590 |
dialog.Destroy() |
|
608 | 591 |
|
0 | 592 |
def OnSaveMenu(self, event): |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
593 |
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
|
594 |
self._onsave() |
488 | 595 |
self.RefreshBufferState() |
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
596 |
else: |
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
597 |
self.Save() |
608 | 598 |
|
0 | 599 |
def OnSaveAsMenu(self, event): |
600 |
self.SaveAs() |
|
601 |
||
602 |
def Save(self): |
|
603 |
result = self.Manager.SaveCurrentInFile() |
|
604 |
if not result: |
|
605 |
self.SaveAs() |
|
512 | 606 |
elif not isinstance(result, (StringType, UnicodeType)): |
0 | 607 |
self.RefreshBufferState() |
608 |
else: |
|
580 | 609 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 610 |
message.ShowModal() |
611 |
message.Destroy() |
|
612 |
||
613 |
def SaveAs(self): |
|
614 |
filepath = self.Manager.GetCurrentFilePath() |
|
615 |
if filepath != "": |
|
616 |
directory, filename = os.path.split(filepath) |
|
617 |
else: |
|
618 |
directory, filename = os.getcwd(), "%s.od"%self.Manager.GetCurrentNodeInfos()[0] |
|
580 | 619 |
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
|
620 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 621 |
filepath = dialog.GetPath() |
622 |
if os.path.isdir(os.path.dirname(filepath)): |
|
623 |
result = self.Manager.SaveCurrentInFile(filepath) |
|
512 | 624 |
if not isinstance(result, (StringType, UnicodeType)): |
0 | 625 |
self.RefreshBufferState() |
626 |
else: |
|
580 | 627 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 628 |
message.ShowModal() |
629 |
message.Destroy() |
|
630 |
else: |
|
580 | 631 |
message = wx.MessageDialog(self, _("%s is not a valid folder!")%os.path.dirname(filepath), _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 632 |
message.ShowModal() |
633 |
message.Destroy() |
|
634 |
dialog.Destroy() |
|
635 |
||
636 |
def OnCloseMenu(self, event): |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
637 |
answer = wx.ID_YES |
0 | 638 |
result = self.Manager.CloseCurrent() |
639 |
if not result: |
|
580 | 640 |
dialog = wx.MessageDialog(self, _("There are changes, do you want to save?"), _("Close File"), wx.YES_NO|wx.CANCEL|wx.ICON_QUESTION) |
0 | 641 |
answer = dialog.ShowModal() |
642 |
dialog.Destroy() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
643 |
if answer == wx.ID_YES: |
0 | 644 |
self.OnSaveMenu(event) |
645 |
if self.Manager.CurrentIsSaved(): |
|
646 |
self.Manager.CloseCurrent() |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
647 |
elif answer == wx.ID_NO: |
0 | 648 |
self.Manager.CloseCurrent(True) |
649 |
if self.FileOpened.GetPageCount() > self.Manager.GetBufferNumber(): |
|
650 |
current = self.FileOpened.GetSelection() |
|
651 |
self.FileOpened.DeletePage(current) |
|
652 |
if self.FileOpened.GetPageCount() > 0: |
|
653 |
self.FileOpened.SetSelection(min(current, self.FileOpened.GetPageCount() - 1)) |
|
654 |
self.RefreshBufferState() |
|
655 |
self.RefreshMainMenu() |
|
656 |
||
657 |
||
658 |
#------------------------------------------------------------------------------- |
|
659 |
# Import and Export Functions |
|
660 |
#------------------------------------------------------------------------------- |
|
661 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
662 |
def OnImportEDSMenu(self, event): |
580 | 663 |
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
|
664 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 665 |
filepath = dialog.GetPath() |
666 |
if os.path.isfile(filepath): |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
667 |
result = self.Manager.ImportCurrentFromEDSFile(filepath) |
512 | 668 |
if isinstance(result, (IntType, LongType)): |
299 | 669 |
new_editingpanel = EditingPanel(self.FileOpened, self, self.Manager) |
205 | 670 |
new_editingpanel.SetIndex(result) |
671 |
self.FileOpened.AddPage(new_editingpanel, "") |
|
672 |
self.FileOpened.SetSelection(self.FileOpened.GetPageCount() - 1) |
|
0 | 673 |
self.RefreshBufferState() |
674 |
self.RefreshCurrentIndexList() |
|
675 |
self.RefreshProfileMenu() |
|
676 |
self.RefreshMainMenu() |
|
580 | 677 |
message = wx.MessageDialog(self, _("Import successful"), _("Information"), wx.OK|wx.ICON_INFORMATION) |
0 | 678 |
message.ShowModal() |
679 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
680 |
else: |
580 | 681 |
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
|
682 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
683 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
684 |
else: |
580 | 685 |
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
|
686 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
687 |
message.Destroy() |
0 | 688 |
dialog.Destroy() |
689 |
||
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
690 |
def OnExportEDSMenu(self, event): |
580 | 691 |
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
|
692 |
if dialog.ShowModal() == wx.ID_OK: |
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
693 |
filepath = dialog.GetPath() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
694 |
if os.path.isdir(os.path.dirname(filepath)): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
695 |
path, extend = os.path.splitext(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
696 |
if extend in ("", "."): |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
697 |
filepath = path + ".eds" |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
698 |
result = self.Manager.ExportCurrentToEDSFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
699 |
if not result: |
580 | 700 |
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
|
701 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
702 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
703 |
else: |
580 | 704 |
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
|
705 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
706 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
707 |
else: |
580 | 708 |
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
|
709 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
710 |
message.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
711 |
dialog.Destroy() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
712 |
|
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
713 |
def OnExportCMenu(self, event): |
580 | 714 |
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
|
715 |
if dialog.ShowModal() == wx.ID_OK: |
0 | 716 |
filepath = dialog.GetPath() |
717 |
if os.path.isdir(os.path.dirname(filepath)): |
|
718 |
path, extend = os.path.splitext(filepath) |
|
719 |
if extend in ("", "."): |
|
720 |
filepath = path + ".c" |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
721 |
result = self.Manager.ExportCurrentToCFile(filepath) |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
722 |
if not result: |
580 | 723 |
message = wx.MessageDialog(self, _("Export successful"), _("Information"), wx.OK|wx.ICON_INFORMATION) |
0 | 724 |
message.ShowModal() |
725 |
message.Destroy() |
|
182
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
726 |
else: |
580 | 727 |
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
|
728 |
message.ShowModal() |
988f2b302aa6
Adding support for importing and exporting EDS files
lbessard
parents:
176
diff
changeset
|
729 |
message.Destroy() |
0 | 730 |
else: |
580 | 731 |
message = wx.MessageDialog(self, _("\"%s\" is not a valid folder!")%os.path.dirname(filepath), _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 732 |
message.ShowModal() |
733 |
message.Destroy() |
|
734 |
dialog.Destroy() |
|
735 |
||
736 |
||
737 |
#------------------------------------------------------------------------------- |
|
738 |
# Exception Handler |
|
739 |
#------------------------------------------------------------------------------- |
|
740 |
||
741 |
Max_Traceback_List_Size = 20 |
|
742 |
||
743 |
def Display_Exception_Dialog(e_type,e_value,e_tb): |
|
744 |
trcbck_lst = [] |
|
745 |
for i,line in enumerate(traceback.extract_tb(e_tb)): |
|
580 | 746 |
trcbck = " " + str(i+1) + _(". ") |
0 | 747 |
if line[0].find(os.getcwd()) == -1: |
580 | 748 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
749 |
else: |
|
750 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
|
751 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
0 | 752 |
trcbck_lst.append(trcbck) |
753 |
||
754 |
# Allow clicking.... |
|
755 |
cap = wx.Window_GetCapture() |
|
756 |
if cap: |
|
757 |
cap.ReleaseMouse() |
|
758 |
||
759 |
dlg = wx.SingleChoiceDialog(None, |
|
580 | 760 |
_(""" |
0 | 761 |
An error happens. |
762 |
||
763 |
Click on OK for saving an error report. |
|
764 |
||
614 | 765 |
Please be kind enough to send this file to: |
766 |
edouard.tisserant@gmail.com |
|
0 | 767 |
|
768 |
||
769 |
Error: |
|
580 | 770 |
""") + |
771 |
str(e_type) + _(" : ") + str(e_value), |
|
772 |
_("Error"), |
|
0 | 773 |
trcbck_lst) |
774 |
try: |
|
775 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
776 |
finally: |
|
777 |
dlg.Destroy() |
|
778 |
||
779 |
return res |
|
780 |
||
781 |
def Display_Error_Dialog(e_value): |
|
580 | 782 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK|wx.ICON_ERROR) |
0 | 783 |
message.ShowModal() |
784 |
message.Destroy() |
|
785 |
||
786 |
def get_last_traceback(tb): |
|
787 |
while tb.tb_next: |
|
788 |
tb = tb.tb_next |
|
789 |
return tb |
|
790 |
||
791 |
||
792 |
def format_namespace(d, indent=' '): |
|
793 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
794 |
||
795 |
||
796 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
|
797 |
||
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
798 |
def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
0 | 799 |
|
800 |
def handle_exception(e_type, e_value, e_traceback): |
|
801 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
|
802 |
last_tb = get_last_traceback(e_traceback) |
|
803 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
804 |
if str(e_value).startswith("!!!"): |
|
805 |
Display_Error_Dialog(e_value) |
|
806 |
elif ex not in ignored_exceptions: |
|
807 |
ignored_exceptions.append(ex) |
|
808 |
result = Display_Exception_Dialog(e_type,e_value,e_traceback) |
|
809 |
if result: |
|
810 |
info = { |
|
811 |
'app-title' : wx.GetApp().GetAppName(), # app_title |
|
812 |
'app-version' : app_version, |
|
813 |
'wx-version' : wx.VERSION_STRING, |
|
814 |
'wx-platform' : wx.Platform, |
|
815 |
'python-version' : platform.python_version(), #sys.version.split()[0], |
|
816 |
'platform' : platform.platform(), |
|
817 |
'e-type' : e_type, |
|
818 |
'e-value' : e_value, |
|
819 |
'date' : time.ctime(), |
|
820 |
'cwd' : os.getcwd(), |
|
821 |
} |
|
822 |
if e_traceback: |
|
823 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
824 |
last_tb = get_last_traceback(e_traceback) |
|
825 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
826 |
info['locals'] = format_namespace(exception_locals) |
|
827 |
if 'self' in exception_locals: |
|
828 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
829 |
||
830 |
output = open(path+os.sep+"bug_report_"+info['date'].replace(':','-').replace(' ','_')+".txt",'w') |
|
831 |
lst = info.keys() |
|
832 |
lst.sort() |
|
833 |
for a in lst: |
|
834 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
835 |
||
836 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
837 |
sys.excepthook = handle_exception |
|
838 |
||
839 |
if __name__ == '__main__': |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
840 |
wx.InitAllImageHandlers() |
0 | 841 |
|
842 |
# Install a exception handle for bug reports |
|
254
f2b0acb54e65
Cleaning code for using only wxPython 2.6 class naming
lbessard
parents:
245
diff
changeset
|
843 |
AddExceptHook(os.getcwd(),__version__) |
0 | 844 |
|
485
24b506ea314b
Added embedded mode in objdictedit, for integration in Beremiz.
etisserant
parents:
418
diff
changeset
|
845 |
frame = objdictedit(None, filesOpen = args) |
0 | 846 |
|
847 |
frame.Show() |
|
848 |
app.MainLoop() |