author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 12 Sep 2017 18:32:13 +0300 | |
changeset 1801 | 58ff55053518 |
parent 1792 | 4d1de8b0183f |
child 1814 | fc387c4fc1d4 |
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 getopt |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
30 |
|
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
|
31 |
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
|
32 |
import util.paths as paths |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
33 |
import util.ExceptionHandler |
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 |
|
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
|
35 |
|
1680
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 |
||
39 |
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
|
40 |
# Usage message displayed when help request or when error detected in |
814 | 41 |
# command line |
42 |
def usage(): |
|
43 |
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
|
44 |
print "\n %s [Filepath]\n" % sys.argv[0] |
814 | 45 |
|
46 |
# Parse options given to PLCOpenEditor in command line |
|
47 |
try: |
|
48 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
49 |
except getopt.GetoptError: |
|
50 |
# print help information and exit: |
|
51 |
usage() |
|
52 |
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
|
53 |
|
814 | 54 |
# Extract if help has been requested |
55 |
for o, a in opts: |
|
56 |
if o in ("-h", "--help"): |
|
57 |
usage() |
|
58 |
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
|
59 |
|
814 | 60 |
# Extract the optional filename to open |
61 |
fileOpen = None |
|
62 |
if len(args) > 1: |
|
63 |
usage() |
|
64 |
sys.exit() |
|
65 |
elif len(args) == 1: |
|
66 |
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
|
67 |
|
814 | 68 |
# 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
|
69 |
# 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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
|
1388
67c9a9482d24
Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents:
1330
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
|
1791
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
78 |
# these imports require wx.GetApp to return |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
79 |
# a valid application instance |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
80 |
|
1791
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
81 |
from IDEFrame import IDEFrame, AppendMenu |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
82 |
from IDEFrame import \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
83 |
TITLE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
84 |
EDITORTOOLBAR, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
85 |
FILEMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
86 |
EDITMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
87 |
DISPLAYMENU, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
88 |
PROJECTTREE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
89 |
POUINSTANCEVARIABLESPANEL, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
90 |
LIBRARYTREE, \ |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
91 |
PAGETITLES |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
92 |
|
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
93 |
from IDEFrame import EncodeFileSystemPath, DecodeFileSystemPath |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
94 |
from editors.Viewer import Viewer |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
95 |
from PLCControler import PLCControler |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
96 |
from dialogs import ProjectDialog |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
97 |
from dialogs.AboutDialog import ShowAboutDialog |
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
98 |
|
814 | 99 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
100 |
# ------------------------------------------------------------------------------- |
814 | 101 |
# 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
|
102 |
# ------------------------------------------------------------------------------- |
814 | 103 |
|
104 |
# 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
|
105 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
106 |
ID_PLCOPENEDITORFILEMENUGENERATE, |
814 | 107 |
] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)] |
108 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
109 |
|
814 | 110 |
class PLCOpenEditor(IDEFrame): |
111 |
||
112 |
# Compatibility function for wx versions < 2.6 |
|
113 |
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
|
114 |
def Bind(self, event, function, id=None): |
814 | 115 |
if id is not None: |
116 |
event(self, id, function) |
|
117 |
else: |
|
118 |
event(self, function) |
|
119 |
||
120 |
def _init_coll_FileMenu_Items(self, parent): |
|
121 |
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
|
122 |
kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N') |
814 | 123 |
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
|
124 |
kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O') |
814 | 125 |
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
|
126 |
kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W') |
814 | 127 |
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
|
128 |
kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W') |
814 | 129 |
parent.AppendSeparator() |
130 |
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
|
131 |
kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S') |
814 | 132 |
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
|
133 |
kind=wx.ITEM_NORMAL, text=_(u'Save As...') + '\tCTRL+SHIFT+S') |
814 | 134 |
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
|
135 |
kind=wx.ITEM_NORMAL, text=_(u'Generate Program') + '\tCTRL+G') |
814 | 136 |
parent.AppendSeparator() |
137 |
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
|
138 |
kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P') |
814 | 139 |
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
|
140 |
kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P') |
814 | 141 |
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
|
142 |
kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P') |
814 | 143 |
parent.AppendSeparator() |
144 |
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
|
145 |
kind=wx.ITEM_NORMAL, text=_(u'&Properties')) |
814 | 146 |
parent.AppendSeparator() |
147 |
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
|
148 |
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
|
149 |
|
814 | 150 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
151 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
|
152 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
|
153 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
|
154 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
155 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
|
156 |
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
|
157 |
id=ID_PLCOPENEDITORFILEMENUGENERATE) |
814 | 158 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
159 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
160 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
|
161 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
|
162 |
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
|
163 |
|
814 | 164 |
self.AddToMenuToolBar([(wx.ID_NEW, "new", _(u'New'), None), |
165 |
(wx.ID_OPEN, "open", _(u'Open'), None), |
|
166 |
(wx.ID_SAVE, "save", _(u'Save'), None), |
|
167 |
(wx.ID_SAVEAS, "saveas", _(u'Save As...'), None), |
|
168 |
(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
|
169 |
|
814 | 170 |
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
|
171 |
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
|
172 |
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
|
173 |
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTENTS, |
814 | 174 |
# 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
|
175 |
# AppendMenu(parent, help='', id=wx.ID_HELP_CONTEXT, |
814 | 176 |
# 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
|
177 |
|
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
_(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
|
182 |
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
|
183 |
|
1692
9cb4d1392baf
add information about community support channel to Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
184 |
id = wx.NewId() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
|
814 | 188 |
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
|
189 |
kind=wx.ITEM_NORMAL, text=_(u'About')) |
814 | 190 |
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
|
191 |
# self.Bind(wx.EVT_MENU, self.OnPLCOpenMenu, id=wx.ID_HELP_CONTENTS) |
814 | 192 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
193 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
194 |
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
|
195 |
""" 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
|
196 |
|
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
197 |
: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
|
198 |
: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
|
199 |
""" |
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
|
200 |
self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO) |
814 | 201 |
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
|
202 |
|
814 | 203 |
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
|
204 |
|
814 | 205 |
# Open the filepath if defined |
206 |
if fileOpen is not None: |
|
207 |
fileOpen = DecodeFileSystemPath(fileOpen, False) |
|
208 |
if os.path.isfile(fileOpen): |
|
209 |
# Create a new controller |
|
210 |
controler = PLCControler() |
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
|
814 | 218 |
# 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
|
219 |
self.SetIcon(self.icon) |
814 | 220 |
|
221 |
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
|
222 |
|
814 | 223 |
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
|
224 |
|
814 | 225 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
226 |
(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
|
227 |
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line)) |
814 | 228 |
|
229 |
def OnCloseFrame(self, event): |
|
230 |
if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
|
231 |
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
|
232 |
|
814 | 233 |
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
|
234 |
|
814 | 235 |
event.Skip() |
236 |
else: |
|
237 |
event.Veto() |
|
238 |
||
239 |
def RefreshTitle(self): |
|
240 |
name = _("PLCOpenEditor") |
|
241 |
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
|
242 |
self.SetTitle("%s - %s" % (name, self.Controler.GetFilename())) |
814 | 243 |
else: |
244 |
self.SetTitle(name) |
|
245 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
246 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
247 |
# File Menu Functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
248 |
# ------------------------------------------------------------------------------- |
814 | 249 |
|
250 |
def RefreshFileMenu(self): |
|
251 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
252 |
if self.Controler is not None: |
|
253 |
selected = self.TabsOpened.GetSelection() |
|
254 |
if selected >= 0: |
|
255 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
256 |
else: |
|
257 |
graphic_viewer = False |
|
258 |
if self.TabsOpened.GetPageCount() > 0: |
|
259 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
260 |
if graphic_viewer: |
|
261 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
262 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
|
263 |
MenuToolBar.EnableTool(wx.ID_PRINT, True) |
|
264 |
else: |
|
265 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
266 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
267 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
268 |
else: |
|
269 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
270 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
271 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
272 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
273 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
|
274 |
project_modified = not self.Controler.ProjectIsSaved() |
|
275 |
self.FileMenu.Enable(wx.ID_SAVE, project_modified) |
|
276 |
MenuToolBar.EnableTool(wx.ID_SAVE, project_modified) |
|
277 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
|
278 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
|
279 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
|
280 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
|
281 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
|
282 |
else: |
|
283 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
284 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
285 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
286 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
287 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
288 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
289 |
MenuToolBar.EnableTool(wx.ID_SAVE, False) |
|
290 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
|
291 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
|
292 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
|
293 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
|
294 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
|
295 |
||
296 |
def OnNewProjectMenu(self, event): |
|
297 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
298 |
return |
|
299 |
dialog = ProjectDialog(self) |
|
300 |
if dialog.ShowModal() == wx.ID_OK: |
|
301 |
properties = dialog.GetValues() |
|
302 |
self.ResetView() |
|
303 |
self.Controler = PLCControler() |
|
304 |
self.Controler.CreateNewProject(properties) |
|
305 |
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
|
306 |
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
|
307 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
814 | 308 |
LIBRARYTREE) |
309 |
||
310 |
def OnOpenProjectMenu(self, event): |
|
311 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
312 |
return |
|
313 |
filepath = "" |
|
314 |
if self.Controler is not None: |
|
315 |
filepath = self.Controler.GetFilePath() |
|
316 |
if filepath != "": |
|
317 |
directory = os.path.dirname(filepath) |
|
318 |
else: |
|
319 |
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
|
320 |
|
814 | 321 |
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
|
322 |
|
814 | 323 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, "", _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN) |
324 |
if dialog.ShowModal() == wx.ID_OK: |
|
325 |
filepath = dialog.GetPath() |
|
326 |
if os.path.isfile(filepath): |
|
327 |
self.ResetView() |
|
328 |
controler = PLCControler() |
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
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
|
333 |
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
|
334 |
self._Refresh(PROJECTTREE, LIBRARYTREE) |
814 | 335 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
336 |
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
|
337 |
|
814 | 338 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
339 |
(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
|
340 |
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
|
341 |
|
814 | 342 |
def OnCloseProjectMenu(self, event): |
343 |
if not self.CheckSaveBeforeClosing(): |
|
344 |
return |
|
345 |
self.ResetView() |
|
346 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
|
347 |
||
348 |
def OnSaveProjectMenu(self, event): |
|
349 |
self.SaveProject() |
|
350 |
||
351 |
def OnSaveProjectAsMenu(self, event): |
|
352 |
self.SaveProjectAs() |
|
353 |
||
354 |
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
|
355 |
dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), self.Controler.GetProgramFilePath(), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
814 | 356 |
if dialog.ShowModal() == wx.ID_OK: |
357 |
filepath = dialog.GetPath() |
|
358 |
message_text = "" |
|
359 |
header, icon = _("Done"), wx.ICON_INFORMATION |
|
360 |
if os.path.isdir(os.path.dirname(filepath)): |
|
361 |
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
|
362 |
message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
814 | 363 |
if len(errors) > 0: |
1312
250c3ae0787c
Fixed bug when printing program generating errors and warnings in PLCOpenEditor
Laurent Bessard
parents:
1295
diff
changeset
|
364 |
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
|
365 |
message_text += _("Can't generate program to file %s!") % filepath |
814 | 366 |
header, icon = _("Error"), wx.ICON_ERROR |
367 |
else: |
|
368 |
message_text += _("Program was successfully generated!") |
|
369 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
370 |
message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
814 | 371 |
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
|
372 |
message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
814 | 373 |
message.ShowModal() |
374 |
message.Destroy() |
|
375 |
dialog.Destroy() |
|
376 |
||
377 |
def OnPLCOpenEditorMenu(self, event): |
|
378 |
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
|
379 |
|
814 | 380 |
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
|
381 |
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
|
382 |
|
814 | 383 |
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
|
384 |
info = version.GetAboutDialogInfo() |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
385 |
info.Name = "PLCOpenEditor" |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
386 |
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
|
387 |
"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
|
388 |
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
|
389 |
ShowAboutDialog(self, info) |
814 | 390 |
|
391 |
def SaveProject(self): |
|
392 |
result = self.Controler.SaveXMLFile() |
|
393 |
if not result: |
|
394 |
self.SaveProjectAs() |
|
395 |
else: |
|
396 |
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
|
397 |
|
814 | 398 |
def SaveProjectAs(self): |
399 |
filepath = self.Controler.GetFilePath() |
|
400 |
if filepath != "": |
|
401 |
directory, filename = os.path.split(filepath) |
|
402 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
403 |
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
|
404 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, filename, _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT) |
814 | 405 |
if dialog.ShowModal() == wx.ID_OK: |
406 |
filepath = dialog.GetPath() |
|
407 |
if os.path.isdir(os.path.dirname(filepath)): |
|
408 |
result = self.Controler.SaveXMLFile(filepath) |
|
409 |
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
|
410 |
self.ShowErrorMessage(_("Can't save project to file %s!") % filepath) |
814 | 411 |
else: |
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(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
814 | 413 |
self._Refresh(TITLE, FILEMENU, PAGETITLES) |
414 |
dialog.Destroy() |
|
415 |
||
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
|
416 |
|
814 | 417 |
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
|
418 |
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
|
419 |
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
|
420 |
|
814 | 421 |
# Install a exception handle for bug reports |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
422 |
util.ExceptionHandler.AddExceptHook(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
|
423 |
|
814 | 424 |
frame = PLCOpenEditor(None, fileOpen=fileOpen) |
425 |
||
426 |
frame.Show() |
|
427 |
app.MainLoop() |