author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 16 Aug 2017 12:48:08 +0300 | |
changeset 1749 | d73b64672238 |
parent 1745 | f9d32913bad4 |
child 1760 | ed2e2afb9573 |
permissions | -rwxr-xr-x |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
814 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
814 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
20 |
# GNU General Public License for more details. |
814 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1565
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
26 |
import wx |
|
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
27 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
28 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import platform |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
30 |
import time |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
31 |
import traceback |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
32 |
import getopt |
1560
4ce8492159ab
add version with commit hash to 'About' dialogs for Beremiz IDE and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1533
diff
changeset
|
33 |
import version |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
34 |
import util.paths as paths |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
35 |
|
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
36 |
beremiz_dir = paths.AbsDir(__file__) |
814 | 37 |
|
38 |
__version__ = "$Revision: 1.130 $" |
|
39 |
||
40 |
if __name__ == '__main__': |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
41 |
# Usage message displayed when help request or when error detected in |
814 | 42 |
# command line |
43 |
def usage(): |
|
44 |
print "\nUsage of PLCOpenEditor.py :" |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
45 |
print "\n %s [Filepath]\n" % sys.argv[0] |
814 | 46 |
|
47 |
# Parse options given to PLCOpenEditor in command line |
|
48 |
try: |
|
49 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
50 |
except getopt.GetoptError: |
|
51 |
# print help information and exit: |
|
52 |
usage() |
|
53 |
sys.exit(2) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
54 |
|
814 | 55 |
# Extract if help has been requested |
56 |
for o, a in opts: |
|
57 |
if o in ("-h", "--help"): |
|
58 |
usage() |
|
59 |
sys.exit() |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
60 |
|
814 | 61 |
# Extract the optional filename to open |
62 |
fileOpen = None |
|
63 |
if len(args) > 1: |
|
64 |
usage() |
|
65 |
sys.exit() |
|
66 |
elif len(args) == 1: |
|
67 |
fileOpen = args[0] |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
68 |
|
814 | 69 |
# Create wxApp (Need to create App before internationalization because of |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
70 |
# Windows) |
1533
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
71 |
if wx.VERSION >= (3, 0, 0): |
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
72 |
app = wx.App() |
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
73 |
else: |
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
74 |
app = wx.PySimpleApp() |
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
75 |
|
1388
67c9a9482d24
Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents:
1330
diff
changeset
|
76 |
from util.misc import InstallLocalRessources |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
77 |
InstallLocalRessources(beremiz_dir) |
1388
67c9a9482d24
Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents:
1330
diff
changeset
|
78 |
|
815
e4f24593a758
Adding support for extending internationalization to extensions
laurent
parents:
814
diff
changeset
|
79 |
from docutil import * |
814 | 80 |
from IDEFrame import IDEFrame, AppendMenu |
81 |
from IDEFrame import TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, PAGETITLES |
|
82 |
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
|
83 |
from editors.Viewer import Viewer |
|
84 |
from PLCControler import PLCControler |
|
1030
d9e75a5b5f08
Fix bug when creating New project in PLCOpenEditor
Laurent Bessard
parents:
980
diff
changeset
|
85 |
from dialogs import ProjectDialog |
1565
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
86 |
from dialogs.AboutDialog import ShowAboutDialog |
814 | 87 |
|
88 |
#------------------------------------------------------------------------------- |
|
89 |
# PLCOpenEditor Main Class |
|
90 |
#------------------------------------------------------------------------------- |
|
91 |
||
92 |
# Define PLCOpenEditor FileMenu extra items id |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
93 |
[ID_PLCOPENEDITORFILEMENUGENERATE, |
814 | 94 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)] |
95 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
96 |
|
814 | 97 |
class PLCOpenEditor(IDEFrame): |
98 |
||
99 |
# Compatibility function for wx versions < 2.6 |
|
100 |
if wx.VERSION < (2, 6, 0): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
101 |
def Bind(self, event, function, id=None): |
814 | 102 |
if id is not None: |
103 |
event(self, id, function) |
|
104 |
else: |
|
105 |
event(self, function) |
|
106 |
||
107 |
def _init_coll_FileMenu_Items(self, parent): |
|
108 |
AppendMenu(parent, help='', id=wx.ID_NEW, |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
109 |
kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N') |
814 | 110 |
AppendMenu(parent, help='', id=wx.ID_OPEN, |
111 |
kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O') |
|
112 |
AppendMenu(parent, help='', id=wx.ID_CLOSE, |
|
113 |
kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W') |
|
114 |
AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL, |
|
115 |
kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W') |
|
116 |
parent.AppendSeparator() |
|
117 |
AppendMenu(parent, help='', id=wx.ID_SAVE, |
|
118 |
kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S') |
|
119 |
AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
|
120 |
kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S') |
|
121 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE, |
|
122 |
kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G') |
|
123 |
parent.AppendSeparator() |
|
124 |
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
|
125 |
kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P') |
|
126 |
AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
|
127 |
kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P') |
|
128 |
AppendMenu(parent, help='', id=wx.ID_PRINT, |
|
129 |
kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P') |
|
130 |
parent.AppendSeparator() |
|
131 |
AppendMenu(parent, help='', id=wx.ID_PROPERTIES, |
|
132 |
kind=wx.ITEM_NORMAL, text=_(u'&Properties')) |
|
133 |
parent.AppendSeparator() |
|
134 |
AppendMenu(parent, help='', id=wx.ID_EXIT, |
|
135 |
kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q') |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
136 |
|
814 | 137 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
138 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
|
139 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
|
140 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
|
141 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
142 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
|
143 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
|
144 |
id=ID_PLCOPENEDITORFILEMENUGENERATE) |
|
145 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
|
146 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
147 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
|
148 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
|
149 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
150 |
|
814 | 151 |
self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None), |
152 |
(wx.ID_OPEN, "open", _(u'Open'), None), |
|
153 |
(wx.ID_SAVE, "save", _(u'Save'), None), |
|
154 |
(wx.ID_SAVEAS, "saveas", _(u'Save As...'), None), |
|
155 |
(wx.ID_PRINT, "print", _(u'Print'), None)]) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
156 |
|
814 | 157 |
def _init_coll_HelpMenu_Items(self, parent): |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
158 |
AppendMenu(parent, help='', id=wx.ID_HELP, |
814 | 159 |
kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor') + '\tF1') |
160 |
#AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS, |
|
161 |
# kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
|
162 |
#AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT, |
|
163 |
# kind=wx.ITEM_NORMAL, text=u'IEC 61131-3\tF3') |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
164 |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
165 |
handler = lambda event: { |
1692
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
166 |
wx.MessageBox(version.GetCommunityHelpMsg(), _(u'Community support'), wx.OK | wx.ICON_INFORMATION) |
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
167 |
} |
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
168 |
id = wx.NewId() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
169 |
parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support')) |
1692
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
170 |
self.Bind(wx.EVT_MENU, handler, id=id) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
171 |
|
814 | 172 |
AppendMenu(parent, help='', id=wx.ID_ABOUT, |
173 |
kind=wx.ITEM_NORMAL, text=_(u'About')) |
|
174 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP) |
|
175 |
#self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS) |
|
176 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
|
177 |
||
178 |
## Constructor of the PLCOpenEditor class. |
|
179 |
# @param parent The parent window. |
|
180 |
# @param controler The controler been used by PLCOpenEditor (default: None). |
|
181 |
# @param fileOpen The filepath to open if no controler defined (default: None). |
|
182 |
# @param debug The filepath to open if no controler defined (default: False). |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
183 |
def __init__(self, parent, fileOpen=None): |
1533
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
184 |
self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO) |
814 | 185 |
IDEFrame.__init__(self, parent) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
186 |
|
814 | 187 |
result = None |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
188 |
|
814 | 189 |
# Open the filepath if defined |
190 |
if fileOpen is not None: |
|
191 |
fileOpen = DecodeFileSystemPath(fileOpen, False) |
|
192 |
if os.path.isfile(fileOpen): |
|
193 |
# Create a new controller |
|
194 |
controler = PLCControler() |
|
195 |
result = controler.OpenXMLFile(fileOpen) |
|
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
196 |
self.Controler = controler |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
197 |
self.LibraryPanel.SetController(controler) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
198 |
self.ProjectTree.Enable(True) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
199 |
self.PouInstanceVariablesPanel.SetController(controler) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
200 |
self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
201 |
|
814 | 202 |
# Define PLCOpenEditor icon |
1533
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
203 |
self.SetIcon(self.icon) |
814 | 204 |
|
205 |
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
206 |
|
814 | 207 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
208 |
|
814 | 209 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
210 |
(num, line) = result |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
211 |
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line)) |
814 | 212 |
|
213 |
def OnCloseFrame(self, event): |
|
214 |
if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
|
215 |
self.AUIManager.UnInit() |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
216 |
|
814 | 217 |
self.SaveLastState() |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
218 |
|
814 | 219 |
event.Skip() |
220 |
else: |
|
221 |
event.Veto() |
|
222 |
||
223 |
def RefreshTitle(self): |
|
224 |
name = _("PLCOpenEditor") |
|
225 |
if self.Controler is not None: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
226 |
self.SetTitle("%s - %s" % (name, self.Controler.GetFilename())) |
814 | 227 |
else: |
228 |
self.SetTitle(name) |
|
229 |
||
230 |
#------------------------------------------------------------------------------- |
|
231 |
# File Menu Functions |
|
232 |
#------------------------------------------------------------------------------- |
|
233 |
||
234 |
def RefreshFileMenu(self): |
|
235 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
236 |
if self.Controler is not None: |
|
237 |
selected = self.TabsOpened.GetSelection() |
|
238 |
if selected >= 0: |
|
239 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
240 |
else: |
|
241 |
graphic_viewer = False |
|
242 |
if self.TabsOpened.GetPageCount() > 0: |
|
243 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
244 |
if graphic_viewer: |
|
245 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
246 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
|
247 |
MenuToolBar.EnableTool(wx.ID_PRINT, True) |
|
248 |
else: |
|
249 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
250 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
251 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
252 |
else: |
|
253 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
254 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
255 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
256 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
257 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
|
258 |
project_modified = not self.Controler.ProjectIsSaved() |
|
259 |
self.FileMenu.Enable(wx.ID_SAVE, project_modified) |
|
260 |
MenuToolBar.EnableTool(wx.ID_SAVE, project_modified) |
|
261 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
|
262 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
|
263 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
|
264 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
|
265 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
|
266 |
else: |
|
267 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
268 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
269 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
270 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
271 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
272 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
273 |
MenuToolBar.EnableTool(wx.ID_SAVE, False) |
|
274 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
|
275 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
|
276 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
|
277 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
|
278 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
|
279 |
||
280 |
def OnNewProjectMenu(self, event): |
|
281 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
282 |
return |
|
283 |
dialog = ProjectDialog(self) |
|
284 |
if dialog.ShowModal() == wx.ID_OK: |
|
285 |
properties = dialog.GetValues() |
|
286 |
self.ResetView() |
|
287 |
self.Controler = PLCControler() |
|
288 |
self.Controler.CreateNewProject(properties) |
|
289 |
self.LibraryPanel.SetController(self.Controler) |
|
1295
2ad168756c5e
Fixed bug no contextual menu displayed in left panel tree when creating new project
Laurent Bessard
parents:
1030
diff
changeset
|
290 |
self.ProjectTree.Enable(True) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
291 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
814 | 292 |
LIBRARYTREE) |
293 |
||
294 |
def OnOpenProjectMenu(self, event): |
|
295 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
296 |
return |
|
297 |
filepath = "" |
|
298 |
if self.Controler is not None: |
|
299 |
filepath = self.Controler.GetFilePath() |
|
300 |
if filepath != "": |
|
301 |
directory = os.path.dirname(filepath) |
|
302 |
else: |
|
303 |
directory = os.getcwd() |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
304 |
|
814 | 305 |
result = None |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
306 |
|
814 | 307 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, "", _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN) |
308 |
if dialog.ShowModal() == wx.ID_OK: |
|
309 |
filepath = dialog.GetPath() |
|
310 |
if os.path.isfile(filepath): |
|
311 |
self.ResetView() |
|
312 |
controler = PLCControler() |
|
313 |
result = controler.OpenXMLFile(filepath) |
|
1330
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
314 |
self.Controler = controler |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
315 |
self.LibraryPanel.SetController(controler) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
316 |
self.ProjectTree.Enable(True) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
317 |
self.PouInstanceVariablesPanel.SetController(controler) |
96b242e4c59d
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
1312
diff
changeset
|
318 |
self._Refresh(PROJECTTREE, LIBRARYTREE) |
814 | 319 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
320 |
dialog.Destroy() |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
321 |
|
814 | 322 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
323 |
(num, line) = result |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
324 |
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line)) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
325 |
|
814 | 326 |
def OnCloseProjectMenu(self, event): |
327 |
if not self.CheckSaveBeforeClosing(): |
|
328 |
return |
|
329 |
self.ResetView() |
|
330 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
|
331 |
||
332 |
def OnSaveProjectMenu(self, event): |
|
333 |
self.SaveProject() |
|
334 |
||
335 |
def OnSaveProjectAsMenu(self, event): |
|
336 |
self.SaveProjectAs() |
|
337 |
||
338 |
def OnGenerateProgramMenu(self, event): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
339 |
dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), self.Controler.GetProgramFilePath(), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
814 | 340 |
if dialog.ShowModal() == wx.ID_OK: |
341 |
filepath = dialog.GetPath() |
|
342 |
message_text = "" |
|
343 |
header, icon = _("Done"), wx.ICON_INFORMATION |
|
344 |
if os.path.isdir(os.path.dirname(filepath)): |
|
345 |
program, errors, warnings = self.Controler.GenerateProgram(filepath) |
|
1312
250c3ae0787c
Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents:
1295
diff
changeset
|
346 |
message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
814 | 347 |
if len(errors) > 0: |
1312
250c3ae0787c
Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents:
1295
diff
changeset
|
348 |
message_text += "".join([_("error: %s\n") % error for error in errors]) |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
349 |
message_text += _("Can't generate program to file %s!") % filepath |
814 | 350 |
header, icon = _("Error"), wx.ICON_ERROR |
351 |
else: |
|
352 |
message_text += _("Program was successfully generated!") |
|
353 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
354 |
message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
814 | 355 |
header, icon = _("Error"), wx.ICON_ERROR |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
356 |
message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
814 | 357 |
message.ShowModal() |
358 |
message.Destroy() |
|
359 |
dialog.Destroy() |
|
360 |
||
361 |
def OnPLCOpenEditorMenu(self, event): |
|
362 |
wx.MessageBox(_("No documentation available.\nComing soon.")) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
363 |
|
814 | 364 |
def OnPLCOpenMenu(self, event): |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
365 |
open_pdf(os.path.join(beremiz_dir, "plcopen", "TC6_XML_V101.pdf")) |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
366 |
|
814 | 367 |
def OnAboutMenu(self, event): |
1565
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
368 |
info = version.GetAboutDialogInfo() |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
369 |
info.Name = "PLCOpenEditor" |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
370 |
info.Description = _("PLCOpenEditor is part of Beremiz project.\n\n" |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
371 |
"Beremiz is an ") + info.Description |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
372 |
info.Icon = wx.Icon(os.path.join(beremiz_dir, "images", "aboutlogo.png"), wx.BITMAP_TYPE_PNG) |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
373 |
ShowAboutDialog(self, info) |
814 | 374 |
|
375 |
def SaveProject(self): |
|
376 |
result = self.Controler.SaveXMLFile() |
|
377 |
if not result: |
|
378 |
self.SaveProjectAs() |
|
379 |
else: |
|
380 |
self._Refresh(TITLE, FILEMENU, PAGETITLES) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
381 |
|
814 | 382 |
def SaveProjectAs(self): |
383 |
filepath = self.Controler.GetFilePath() |
|
384 |
if filepath != "": |
|
385 |
directory, filename = os.path.split(filepath) |
|
386 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
387 |
directory, filename = os.getcwd(), "%(projectName)s.xml" % self.Controler.GetProjectProperties() |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
388 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, filename, _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT) |
814 | 389 |
if dialog.ShowModal() == wx.ID_OK: |
390 |
filepath = dialog.GetPath() |
|
391 |
if os.path.isdir(os.path.dirname(filepath)): |
|
392 |
result = self.Controler.SaveXMLFile(filepath) |
|
393 |
if not result: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
394 |
self.ShowErrorMessage(_("Can't save project to file %s!") % filepath) |
814 | 395 |
else: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
396 |
self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
814 | 397 |
self._Refresh(TITLE, FILEMENU, PAGETITLES) |
398 |
dialog.Destroy() |
|
399 |
||
400 |
#------------------------------------------------------------------------------- |
|
401 |
# Exception Handler |
|
402 |
#------------------------------------------------------------------------------- |
|
403 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
404 |
|
814 | 405 |
Max_Traceback_List_Size = 20 |
406 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
407 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
408 |
def Display_Exception_Dialog(e_type, e_value, e_tb): |
814 | 409 |
trcbck_lst = [] |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
410 |
for i, line in enumerate(traceback.extract_tb(e_tb)): |
814 | 411 |
trcbck = " " + str(i+1) + _(". ") |
412 |
if line[0].find(os.getcwd()) == -1: |
|
413 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
|
414 |
else: |
|
415 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
|
416 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
417 |
trcbck_lst.append(trcbck) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
418 |
|
814 | 419 |
# Allow clicking.... |
420 |
cap = wx.Window_GetCapture() |
|
421 |
if cap: |
|
422 |
cap.ReleaseMouse() |
|
423 |
||
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
424 |
dlg = wx.SingleChoiceDialog(None, |
814 | 425 |
_(""" |
1580
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
426 |
An unhandled exception (bug) occured. Bug report saved at : |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
427 |
(%s) |
814 | 428 |
|
429 |
Please be kind enough to send this file to: |
|
1580
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
430 |
beremiz-devel@lists.sourceforge.net |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
431 |
|
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
432 |
You should now restart program. |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
433 |
|
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
434 |
Traceback: |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
435 |
""") % bug_report_path + |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
436 |
repr(e_type) + " : " + repr(e_value), |
814 | 437 |
_("Error"), |
438 |
trcbck_lst) |
|
439 |
try: |
|
440 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
441 |
finally: |
|
442 |
dlg.Destroy() |
|
443 |
||
444 |
return res |
|
445 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
446 |
|
814 | 447 |
def Display_Error_Dialog(e_value): |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
448 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 449 |
message.ShowModal() |
450 |
message.Destroy() |
|
451 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
452 |
|
814 | 453 |
def get_last_traceback(tb): |
454 |
while tb.tb_next: |
|
455 |
tb = tb.tb_next |
|
456 |
return tb |
|
457 |
||
458 |
||
459 |
def format_namespace(d, indent=' '): |
|
460 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
461 |
||
462 |
||
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
463 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
464 |
|
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
465 |
|
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
466 |
def AddExceptHook(path, app_version='[No version]'): #, ignored_exceptions=[]): |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
467 |
|
814 | 468 |
def handle_exception(e_type, e_value, e_traceback): |
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
469 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
814 | 470 |
last_tb = get_last_traceback(e_traceback) |
471 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
472 |
if str(e_value).startswith("!!!"): |
|
473 |
Display_Error_Dialog(e_value) |
|
474 |
elif ex not in ignored_exceptions: |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
475 |
result = Display_Exception_Dialog(e_type, e_value, e_traceback) |
814 | 476 |
if result: |
477 |
ignored_exceptions.append(ex) |
|
478 |
info = { |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
479 |
'app-title': wx.GetApp().GetAppName(), # app_title |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
480 |
'app-version': app_version, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
481 |
'wx-version': wx.VERSION_STRING, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
482 |
'wx-platform': wx.Platform, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
483 |
'python-version': platform.python_version(), #sys.version.split()[0], |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
484 |
'platform': platform.platform(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
485 |
'e-type': e_type, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
486 |
'e-value': e_value, |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
487 |
'date': time.ctime(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
488 |
'cwd': os.getcwd(), |
814 | 489 |
} |
490 |
if e_traceback: |
|
491 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
492 |
last_tb = get_last_traceback(e_traceback) |
|
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
493 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
814 | 494 |
info['locals'] = format_namespace(exception_locals) |
495 |
if 'self' in exception_locals: |
|
496 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
497 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
498 |
output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt", 'w') |
814 | 499 |
lst = info.keys() |
500 |
lst.sort() |
|
501 |
for a in lst: |
|
502 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
503 |
||
504 |
#sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
|
505 |
sys.excepthook = handle_exception |
|
506 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
507 |
|
814 | 508 |
if __name__ == '__main__': |
1533
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
509 |
if wx.VERSION < (3, 0, 0): |
aca8f43483e9
fix issues in PLCOpenEditor with moving from wxWidgets 2.8 to 3.0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1492
diff
changeset
|
510 |
wx.InitAllImageHandlers() |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
511 |
|
814 | 512 |
# Install a exception handle for bug reports |
1560
4ce8492159ab
add version with commit hash to 'About' dialogs for Beremiz IDE and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1533
diff
changeset
|
513 |
AddExceptHook(os.getcwd(), version.app_version) |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1388
diff
changeset
|
514 |
|
814 | 515 |
frame = PLCOpenEditor(None, fileOpen=fileOpen) |
516 |
||
517 |
frame.Show() |
|
518 |
app.MainLoop() |