author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 25 Aug 2017 12:23:45 +0300 | |
changeset 1791 | 3216ed1ba1f7 |
parent 1783 | 3311eea28d56 |
child 1792 | 4d1de8b0183f |
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 |
|
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
36 |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1581
diff
changeset
|
37 |
beremiz_dir = paths.AbsDir(__file__) |
814 | 38 |
|
39 |
__version__ = "$Revision: 1.130 $" |
|
40 |
||
41 |
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
|
42 |
# Usage message displayed when help request or when error detected in |
814 | 43 |
# command line |
44 |
def usage(): |
|
45 |
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
|
46 |
print "\n %s [Filepath]\n" % sys.argv[0] |
814 | 47 |
|
48 |
# Parse options given to PLCOpenEditor in command line |
|
49 |
try: |
|
50 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
51 |
except getopt.GetoptError: |
|
52 |
# print help information and exit: |
|
53 |
usage() |
|
54 |
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
|
55 |
|
814 | 56 |
# Extract if help has been requested |
57 |
for o, a in opts: |
|
58 |
if o in ("-h", "--help"): |
|
59 |
usage() |
|
60 |
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
|
61 |
|
814 | 62 |
# Extract the optional filename to open |
63 |
fileOpen = None |
|
64 |
if len(args) > 1: |
|
65 |
usage() |
|
66 |
sys.exit() |
|
67 |
elif len(args) == 1: |
|
68 |
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
|
69 |
|
814 | 70 |
# 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
|
71 |
# 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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
|
1388
67c9a9482d24
Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents:
1330
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
|
1791
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
80 |
# these imports require wx.GetApp to return |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
81 |
# a valid application instance |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
82 |
from docutil import * |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
83 |
from IDEFrame import IDEFrame, AppendMenu |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
84 |
from IDEFrame import \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
85 |
TITLE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
86 |
EDITORTOOLBAR, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
87 |
FILEMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
88 |
EDITMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
89 |
DISPLAYMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
90 |
PROJECTTREE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
91 |
POUINSTANCEVARIABLESPANEL, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
92 |
LIBRARYTREE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
93 |
PAGETITLES |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
94 |
|
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
95 |
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
96 |
from editors.Viewer import Viewer |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
97 |
from PLCControler import PLCControler |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
98 |
from dialogs import ProjectDialog |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
99 |
from dialogs.AboutDialog import ShowAboutDialog |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
100 |
|
814 | 101 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
102 |
# ------------------------------------------------------------------------------- |
814 | 103 |
# PLCOpenEditor Main Class |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
104 |
# ------------------------------------------------------------------------------- |
814 | 105 |
|
106 |
# Define PLCOpenEditor FileMenu extra items id |
|
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
107 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
108 |
ID_PLCOPENEDITORFILEMENUGENERATE, |
814 | 109 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)] |
110 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
111 |
|
814 | 112 |
class PLCOpenEditor(IDEFrame): |
113 |
||
114 |
# Compatibility function for wx versions < 2.6 |
|
115 |
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
|
116 |
def Bind(self, event, function, id=None): |
814 | 117 |
if id is not None: |
118 |
event(self, id, function) |
|
119 |
else: |
|
120 |
event(self, function) |
|
121 |
||
122 |
def _init_coll_FileMenu_Items(self, parent): |
|
123 |
AppendMenu(parent, help='', id=wx.ID_NEW, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
124 |
kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N') |
814 | 125 |
AppendMenu(parent, help='', id=wx.ID_OPEN, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
126 |
kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O') |
814 | 127 |
AppendMenu(parent, help='', id=wx.ID_CLOSE, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
128 |
kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W') |
814 | 129 |
AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
130 |
kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W') |
814 | 131 |
parent.AppendSeparator() |
132 |
AppendMenu(parent, help='', id=wx.ID_SAVE, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
133 |
kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S') |
814 | 134 |
AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
135 |
kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S') |
814 | 136 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
137 |
kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G') |
814 | 138 |
parent.AppendSeparator() |
139 |
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
140 |
kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P') |
814 | 141 |
AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
142 |
kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P') |
814 | 143 |
AppendMenu(parent, help='', id=wx.ID_PRINT, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
144 |
kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P') |
814 | 145 |
parent.AppendSeparator() |
146 |
AppendMenu(parent, help='', id=wx.ID_PROPERTIES, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
147 |
kind=wx.ITEM_NORMAL, text=_(u'&Properties')) |
814 | 148 |
parent.AppendSeparator() |
149 |
AppendMenu(parent, help='', id=wx.ID_EXIT, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
150 |
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
|
151 |
|
814 | 152 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
153 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
|
154 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
|
155 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
|
156 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
157 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
|
158 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramMenu, |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
159 |
id=ID_PLCOPENEDITORFILEMENUGENERATE) |
814 | 160 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
161 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
162 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
|
163 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
|
164 |
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
|
165 |
|
814 | 166 |
self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None), |
167 |
(wx.ID_OPEN, "open", _(u'Open'), None), |
|
168 |
(wx.ID_SAVE, "save", _(u'Save'), None), |
|
169 |
(wx.ID_SAVEAS, "saveas", _(u'Save As...'), None), |
|
170 |
(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
|
171 |
|
814 | 172 |
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
|
173 |
AppendMenu(parent, help='', id=wx.ID_HELP, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
174 |
kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor') + '\tF1') |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
175 |
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS, |
814 | 176 |
# kind=wx.ITEM_NORMAL, text=u'PLCOpen\tF2') |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
177 |
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT, |
814 | 178 |
# 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
|
179 |
|
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
180 |
def handler(event): |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
181 |
return wx.MessageBox( |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
182 |
version.GetCommunityHelpMsg(), |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
183 |
_(u'Community support'), |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
184 |
wx.OK | wx.ICON_INFORMATION) |
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1760
diff
changeset
|
185 |
|
1692
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
186 |
id = wx.NewId() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
|
814 | 190 |
AppendMenu(parent, help='', id=wx.ID_ABOUT, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
191 |
kind=wx.ITEM_NORMAL, text=_(u'About')) |
814 | 192 |
self.Bind(wx.EVT_MENU, self.OnPLCOpenEditorMenu, id=wx.ID_HELP) |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
193 |
# self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS) |
814 | 194 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
195 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
196 |
def __init__(self, parent, fileOpen=None): |
1781
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
197 |
""" Constructor of the PLCOpenEditor class. |
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
198 |
|
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
199 |
:param parent: The parent window. |
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
200 |
:param fileOpen: The filepath to open if no controler defined (default: None). |
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
201 |
""" |
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
|
202 |
self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO) |
814 | 203 |
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
|
204 |
|
814 | 205 |
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
|
206 |
|
814 | 207 |
# Open the filepath if defined |
208 |
if fileOpen is not None: |
|
209 |
fileOpen = DecodeFileSystemPath(fileOpen, False) |
|
210 |
if os.path.isfile(fileOpen): |
|
211 |
# Create a new controller |
|
212 |
controler = PLCControler() |
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
|
814 | 220 |
# 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
|
221 |
self.SetIcon(self.icon) |
814 | 222 |
|
223 |
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
|
224 |
|
814 | 225 |
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
|
226 |
|
814 | 227 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
228 |
(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
|
229 |
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line)) |
814 | 230 |
|
231 |
def OnCloseFrame(self, event): |
|
232 |
if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
|
233 |
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
|
234 |
|
814 | 235 |
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
|
236 |
|
814 | 237 |
event.Skip() |
238 |
else: |
|
239 |
event.Veto() |
|
240 |
||
241 |
def RefreshTitle(self): |
|
242 |
name = _("PLCOpenEditor") |
|
243 |
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
|
244 |
self.SetTitle("%s - %s" % (name, self.Controler.GetFilename())) |
814 | 245 |
else: |
246 |
self.SetTitle(name) |
|
247 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
248 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
249 |
# File Menu Functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
250 |
# ------------------------------------------------------------------------------- |
814 | 251 |
|
252 |
def RefreshFileMenu(self): |
|
253 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
254 |
if self.Controler is not None: |
|
255 |
selected = self.TabsOpened.GetSelection() |
|
256 |
if selected >= 0: |
|
257 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
258 |
else: |
|
259 |
graphic_viewer = False |
|
260 |
if self.TabsOpened.GetPageCount() > 0: |
|
261 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
262 |
if graphic_viewer: |
|
263 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
264 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
|
265 |
MenuToolBar.EnableTool(wx.ID_PRINT, True) |
|
266 |
else: |
|
267 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
268 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
269 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
270 |
else: |
|
271 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
272 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
273 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
274 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
275 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
|
276 |
project_modified = not self.Controler.ProjectIsSaved() |
|
277 |
self.FileMenu.Enable(wx.ID_SAVE, project_modified) |
|
278 |
MenuToolBar.EnableTool(wx.ID_SAVE, project_modified) |
|
279 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
|
280 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
|
281 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
|
282 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
|
283 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
|
284 |
else: |
|
285 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
286 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
287 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
288 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
289 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
290 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
291 |
MenuToolBar.EnableTool(wx.ID_SAVE, False) |
|
292 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
|
293 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
|
294 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
|
295 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
|
296 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
|
297 |
||
298 |
def OnNewProjectMenu(self, event): |
|
299 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
300 |
return |
|
301 |
dialog = ProjectDialog(self) |
|
302 |
if dialog.ShowModal() == wx.ID_OK: |
|
303 |
properties = dialog.GetValues() |
|
304 |
self.ResetView() |
|
305 |
self.Controler = PLCControler() |
|
306 |
self.Controler.CreateNewProject(properties) |
|
307 |
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
|
308 |
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
|
309 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
814 | 310 |
LIBRARYTREE) |
311 |
||
312 |
def OnOpenProjectMenu(self, event): |
|
313 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
314 |
return |
|
315 |
filepath = "" |
|
316 |
if self.Controler is not None: |
|
317 |
filepath = self.Controler.GetFilePath() |
|
318 |
if filepath != "": |
|
319 |
directory = os.path.dirname(filepath) |
|
320 |
else: |
|
321 |
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
|
322 |
|
814 | 323 |
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
|
324 |
|
814 | 325 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, "", _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN) |
326 |
if dialog.ShowModal() == wx.ID_OK: |
|
327 |
filepath = dialog.GetPath() |
|
328 |
if os.path.isfile(filepath): |
|
329 |
self.ResetView() |
|
330 |
controler = PLCControler() |
|
331 |
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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
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
|
336 |
self._Refresh(PROJECTTREE, LIBRARYTREE) |
814 | 337 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
338 |
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
|
339 |
|
814 | 340 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
341 |
(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
|
342 |
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
|
343 |
|
814 | 344 |
def OnCloseProjectMenu(self, event): |
345 |
if not self.CheckSaveBeforeClosing(): |
|
346 |
return |
|
347 |
self.ResetView() |
|
348 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
|
349 |
||
350 |
def OnSaveProjectMenu(self, event): |
|
351 |
self.SaveProject() |
|
352 |
||
353 |
def OnSaveProjectAsMenu(self, event): |
|
354 |
self.SaveProjectAs() |
|
355 |
||
356 |
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
|
357 |
dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), self.Controler.GetProgramFilePath(), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
814 | 358 |
if dialog.ShowModal() == wx.ID_OK: |
359 |
filepath = dialog.GetPath() |
|
360 |
message_text = "" |
|
361 |
header, icon = _("Done"), wx.ICON_INFORMATION |
|
362 |
if os.path.isdir(os.path.dirname(filepath)): |
|
363 |
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
|
364 |
message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
814 | 365 |
if len(errors) > 0: |
1312
250c3ae0787c
Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents:
1295
diff
changeset
|
366 |
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
|
367 |
message_text += _("Can't generate program to file %s!") % filepath |
814 | 368 |
header, icon = _("Error"), wx.ICON_ERROR |
369 |
else: |
|
370 |
message_text += _("Program was successfully generated!") |
|
371 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
372 |
message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
814 | 373 |
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
|
374 |
message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
814 | 375 |
message.ShowModal() |
376 |
message.Destroy() |
|
377 |
dialog.Destroy() |
|
378 |
||
379 |
def OnPLCOpenEditorMenu(self, event): |
|
380 |
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
|
381 |
|
814 | 382 |
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
|
383 |
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
|
384 |
|
814 | 385 |
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
|
386 |
info = version.GetAboutDialogInfo() |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
387 |
info.Name = "PLCOpenEditor" |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
388 |
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
|
389 |
"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
|
390 |
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
|
391 |
ShowAboutDialog(self, info) |
814 | 392 |
|
393 |
def SaveProject(self): |
|
394 |
result = self.Controler.SaveXMLFile() |
|
395 |
if not result: |
|
396 |
self.SaveProjectAs() |
|
397 |
else: |
|
398 |
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
|
399 |
|
814 | 400 |
def SaveProjectAs(self): |
401 |
filepath = self.Controler.GetFilePath() |
|
402 |
if filepath != "": |
|
403 |
directory, filename = os.path.split(filepath) |
|
404 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
405 |
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
|
406 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, filename, _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT) |
814 | 407 |
if dialog.ShowModal() == wx.ID_OK: |
408 |
filepath = dialog.GetPath() |
|
409 |
if os.path.isdir(os.path.dirname(filepath)): |
|
410 |
result = self.Controler.SaveXMLFile(filepath) |
|
411 |
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
|
412 |
self.ShowErrorMessage(_("Can't save project to file %s!") % filepath) |
814 | 413 |
else: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
414 |
self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
814 | 415 |
self._Refresh(TITLE, FILEMENU, PAGETITLES) |
416 |
dialog.Destroy() |
|
417 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
418 |
# ------------------------------------------------------------------------------- |
814 | 419 |
# Exception Handler |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
420 |
# ------------------------------------------------------------------------------- |
814 | 421 |
|
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
|
422 |
|
814 | 423 |
Max_Traceback_List_Size = 20 |
424 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
425 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
426 |
def Display_Exception_Dialog(e_type, e_value, e_tb): |
814 | 427 |
trcbck_lst = [] |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
428 |
for i, line in enumerate(traceback.extract_tb(e_tb)): |
814 | 429 |
trcbck = " " + str(i+1) + _(". ") |
430 |
if line[0].find(os.getcwd()) == -1: |
|
431 |
trcbck += _("file : ") + str(line[0]) + _(", ") |
|
432 |
else: |
|
433 |
trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ") |
|
434 |
trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2]) |
|
435 |
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
|
436 |
|
814 | 437 |
# Allow clicking.... |
438 |
cap = wx.Window_GetCapture() |
|
439 |
if cap: |
|
440 |
cap.ReleaseMouse() |
|
441 |
||
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
442 |
dlg = wx.SingleChoiceDialog( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
443 |
None, |
814 | 444 |
_(""" |
1580
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
445 |
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
|
446 |
(%s) |
814 | 447 |
|
448 |
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
|
449 |
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
|
450 |
|
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
451 |
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
|
452 |
|
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
453 |
Traceback: |
f37b88d3edc6
change bug report address for PLCOpenEditor to beremiz-devel@lists.sourceforge.net
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
454 |
""") % 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
|
455 |
repr(e_type) + " : " + repr(e_value), |
814 | 456 |
_("Error"), |
457 |
trcbck_lst) |
|
458 |
try: |
|
459 |
res = (dlg.ShowModal() == wx.ID_OK) |
|
460 |
finally: |
|
461 |
dlg.Destroy() |
|
462 |
||
463 |
return res |
|
464 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
465 |
|
814 | 466 |
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
|
467 |
message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 468 |
message.ShowModal() |
469 |
message.Destroy() |
|
470 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
471 |
|
814 | 472 |
def get_last_traceback(tb): |
473 |
while tb.tb_next: |
|
474 |
tb = tb.tb_next |
|
475 |
return tb |
|
476 |
||
477 |
||
478 |
def format_namespace(d, indent=' '): |
|
479 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
|
480 |
||
481 |
||
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
482 |
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
|
483 |
|
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
484 |
|
1760
ed2e2afb9573
clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
485 |
def AddExceptHook(path, app_version='[No 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
|
486 |
|
814 | 487 |
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
|
488 |
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 | 489 |
last_tb = get_last_traceback(e_traceback) |
490 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
|
491 |
if str(e_value).startswith("!!!"): |
|
492 |
Display_Error_Dialog(e_value) |
|
493 |
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
|
494 |
result = Display_Exception_Dialog(e_type, e_value, e_traceback) |
814 | 495 |
if result: |
496 |
ignored_exceptions.append(ex) |
|
497 |
info = { |
|
1760
ed2e2afb9573
clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
498 |
'app-title': wx.GetApp().GetAppName(), |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
499 |
'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
|
500 |
'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
|
501 |
'wx-platform': wx.Platform, |
1760
ed2e2afb9573
clean-up: fix PEP8 E262 inline comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
502 |
'python-version': platform.python_version(), |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
503 |
'platform': platform.platform(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
504 |
'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
|
505 |
'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
|
506 |
'date': time.ctime(), |
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
507 |
'cwd': os.getcwd(), |
814 | 508 |
} |
509 |
if e_traceback: |
|
510 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
511 |
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
|
512 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
814 | 513 |
info['locals'] = format_namespace(exception_locals) |
514 |
if 'self' in exception_locals: |
|
515 |
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
|
516 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
517 |
output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt", 'w') |
814 | 518 |
lst = info.keys() |
519 |
lst.sort() |
|
520 |
for a in lst: |
|
521 |
output.write(a+":\n"+str(info[a])+"\n\n") |
|
522 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
523 |
# sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
814 | 524 |
sys.excepthook = handle_exception |
525 |
||
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
|
526 |
|
814 | 527 |
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
|
528 |
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
|
529 |
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
|
530 |
|
814 | 531 |
# 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
|
532 |
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
|
533 |
|
814 | 534 |
frame = PLCOpenEditor(None, fileOpen=fileOpen) |
535 |
||
536 |
frame.Show() |
|
537 |
app.MainLoop() |