author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 05 Dec 2024 16:45:37 +0100 | |
changeset 4061 | e0dfe8b8db4a |
parent 4057 | cf42c3dbdd5c |
child 4064 | f273ee835411 |
permissions | -rw-r--r-- |
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 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1815
diff
changeset
|
26 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
27 |
|
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
28 |
|
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
30 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
31 |
import getopt |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
32 |
|
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
33 |
import wx |
3570
eb915a9fdcb0
IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
34 |
import wx.adv |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
35 |
|
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
|
36 |
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
|
37 |
import util.paths as paths |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1791
diff
changeset
|
38 |
import util.ExceptionHandler |
1834
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1832
diff
changeset
|
39 |
from util.misc import InstallLocalRessources |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
40 |
from IDEFrame import IDEFrame, AppendMenu |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
41 |
from IDEFrame import \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
42 |
TITLE, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
43 |
EDITORTOOLBAR, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
44 |
FILEMENU, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
45 |
EDITMENU, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
46 |
DISPLAYMENU, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
47 |
PROJECTTREE, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
48 |
POUINSTANCEVARIABLESPANEL, \ |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
49 |
LIBRARYTREE, \ |
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
50 |
PAGETITLES, \ |
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
51 |
DecodeFileSystemPath |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
52 |
from editors.Viewer import Viewer |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
53 |
from PLCControler import PLCControler |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
54 |
from dialogs import ProjectDialog |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
55 |
from dialogs.AboutDialog import ShowAboutDialog |
1791
3216ed1ba1f7
fix problem running PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1783
diff
changeset
|
56 |
|
814 | 57 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
58 |
# ------------------------------------------------------------------------------- |
814 | 59 |
# 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
|
60 |
# ------------------------------------------------------------------------------- |
814 | 61 |
|
62 |
# 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
|
63 |
[ |
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
64 |
ID_PLCOPENEDITORFILEMENUGENERATE, |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
65 |
ID_PLCOPENEDITORFILEMENUGENERATEAS, |
3766 | 66 |
] = [wx.NewIdRef() for _init_coll_FileMenu_Items in range(2)] |
814 | 67 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
68 |
|
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
69 |
beremiz_dir = paths.AbsDir(__file__) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
70 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
71 |
|
814 | 72 |
class PLCOpenEditor(IDEFrame): |
73 |
||
74 |
def _init_coll_FileMenu_Items(self, parent): |
|
75 |
AppendMenu(parent, help='', id=wx.ID_NEW, |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
76 |
kind=wx.ITEM_NORMAL, text=_('New') + '\tCTRL+N') |
814 | 77 |
AppendMenu(parent, help='', id=wx.ID_OPEN, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
78 |
kind=wx.ITEM_NORMAL, text=_('Open') + '\tCTRL+O') |
814 | 79 |
AppendMenu(parent, help='', id=wx.ID_CLOSE, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
80 |
kind=wx.ITEM_NORMAL, text=_('Close Tab') + '\tCTRL+W') |
814 | 81 |
AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
82 |
kind=wx.ITEM_NORMAL, text=_('Close Project') + '\tCTRL+SHIFT+W') |
814 | 83 |
parent.AppendSeparator() |
84 |
AppendMenu(parent, help='', id=wx.ID_SAVE, |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
85 |
kind=wx.ITEM_NORMAL, text=_('Save') + '\tCTRL+S') |
814 | 86 |
AppendMenu(parent, help='', id=wx.ID_SAVEAS, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
87 |
kind=wx.ITEM_NORMAL, text=_('Save As...') + '\tCTRL+SHIFT+S') |
814 | 88 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATE, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
89 |
kind=wx.ITEM_NORMAL, text=_('Generate Program') + '\tCTRL+G') |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
90 |
AppendMenu(parent, help='', id=ID_PLCOPENEDITORFILEMENUGENERATEAS, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
91 |
kind=wx.ITEM_NORMAL, text=_('Generate Program As...') + '\tCTRL+SHIFT+G') |
814 | 92 |
parent.AppendSeparator() |
93 |
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
94 |
kind=wx.ITEM_NORMAL, text=_('Page Setup') + '\tCTRL+ALT+P') |
814 | 95 |
AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
96 |
kind=wx.ITEM_NORMAL, text=_('Preview') + '\tCTRL+SHIFT+P') |
814 | 97 |
AppendMenu(parent, help='', id=wx.ID_PRINT, |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
98 |
kind=wx.ITEM_NORMAL, text=_('Print') + '\tCTRL+P') |
814 | 99 |
parent.AppendSeparator() |
100 |
AppendMenu(parent, help='', id=wx.ID_PROPERTIES, |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
101 |
kind=wx.ITEM_NORMAL, text=_('&Properties')) |
814 | 102 |
parent.AppendSeparator() |
103 |
AppendMenu(parent, help='', id=wx.ID_EXIT, |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
104 |
kind=wx.ITEM_NORMAL, text=_('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
|
105 |
|
814 | 106 |
self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW) |
107 |
self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN) |
|
108 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
|
109 |
self.Bind(wx.EVT_MENU, self.OnCloseProjectMenu, id=wx.ID_CLOSE_ALL) |
|
110 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
111 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS) |
|
112 |
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
|
113 |
id=ID_PLCOPENEDITORFILEMENUGENERATE) |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
114 |
self.Bind(wx.EVT_MENU, self.OnGenerateProgramAsMenu, |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
115 |
id=ID_PLCOPENEDITORFILEMENUGENERATEAS) |
814 | 116 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
117 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
118 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
|
119 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
|
120 |
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
|
121 |
|
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
122 |
self.AddToMenuToolBar([(wx.ID_NEW, "new", _('New'), None), |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
123 |
(wx.ID_OPEN, "open", _('Open'), None), |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
124 |
(wx.ID_SAVE, "save", _('Save'), None), |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
125 |
(wx.ID_SAVEAS, "saveas", _('Save As...'), None), |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
126 |
(wx.ID_PRINT, "print", _('Print'), None), |
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
127 |
(ID_PLCOPENEDITORFILEMENUGENERATE, "Build", _('Generate Program'), 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
|
128 |
|
814 | 129 |
def _init_coll_HelpMenu_Items(self, parent): |
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
|
130 |
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
|
131 |
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
|
132 |
version.GetCommunityHelpMsg(), |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3570
diff
changeset
|
133 |
_('Community support'), |
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
|
134 |
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
|
135 |
|
4057
cf42c3dbdd5c
IDE: Fix PLCOpenEditor (wxPython4 menus) and drop broken PDF doc support.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3906
diff
changeset
|
136 |
menu_entry = parent.Append(wx.ID_ANY, _('Community support'), '') |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2532
diff
changeset
|
137 |
self.Bind(wx.EVT_MENU, handler, menu_entry) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1718
diff
changeset
|
138 |
|
4057
cf42c3dbdd5c
IDE: Fix PLCOpenEditor (wxPython4 menus) and drop broken PDF doc support.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3906
diff
changeset
|
139 |
parent.Append(wx.MenuItem(helpString='', id=wx.ID_ABOUT, |
cf42c3dbdd5c
IDE: Fix PLCOpenEditor (wxPython4 menus) and drop broken PDF doc support.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3906
diff
changeset
|
140 |
kind=wx.ITEM_NORMAL, text=_('About'))) |
814 | 141 |
self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT) |
142 |
||
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
143 |
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
|
144 |
""" 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
|
145 |
|
b112bfdde5cc
clean-up: fix PEP8 E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
146 |
: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
|
147 |
: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
|
148 |
""" |
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
|
149 |
self.icon = wx.Icon(os.path.join(beremiz_dir, "images", "poe.ico"), wx.BITMAP_TYPE_ICO) |
814 | 150 |
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
|
151 |
|
814 | 152 |
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
|
153 |
|
814 | 154 |
# Open the filepath if defined |
155 |
if fileOpen is not None: |
|
156 |
fileOpen = DecodeFileSystemPath(fileOpen, False) |
|
157 |
if os.path.isfile(fileOpen): |
|
158 |
# Create a new controller |
|
159 |
controler = PLCControler() |
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
|
814 | 167 |
# 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
|
168 |
self.SetIcon(self.icon) |
814 | 169 |
|
170 |
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
|
171 |
|
814 | 172 |
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
|
173 |
|
814 | 174 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
175 |
(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
|
176 |
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line)) |
814 | 177 |
|
178 |
def OnCloseFrame(self, event): |
|
179 |
if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")): |
|
180 |
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
|
181 |
|
814 | 182 |
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
|
183 |
|
814 | 184 |
event.Skip() |
185 |
else: |
|
186 |
event.Veto() |
|
187 |
||
188 |
def RefreshTitle(self): |
|
189 |
name = _("PLCOpenEditor") |
|
190 |
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
|
191 |
self.SetTitle("%s - %s" % (name, self.Controler.GetFilename())) |
814 | 192 |
else: |
193 |
self.SetTitle(name) |
|
194 |
||
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
195 |
# ------------------------------------------------------------------------------- |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
196 |
# File Menu Functions |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1781
diff
changeset
|
197 |
# ------------------------------------------------------------------------------- |
814 | 198 |
|
199 |
def RefreshFileMenu(self): |
|
200 |
MenuToolBar = self.Panes["MenuToolBar"] |
|
201 |
if self.Controler is not None: |
|
202 |
selected = self.TabsOpened.GetSelection() |
|
203 |
if selected >= 0: |
|
204 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
205 |
else: |
|
206 |
graphic_viewer = False |
|
207 |
if self.TabsOpened.GetPageCount() > 0: |
|
208 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
209 |
if graphic_viewer: |
|
210 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
211 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
|
212 |
MenuToolBar.EnableTool(wx.ID_PRINT, True) |
|
213 |
else: |
|
214 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
215 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
216 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
217 |
else: |
|
218 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
219 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
220 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
221 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
222 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
|
223 |
project_modified = not self.Controler.ProjectIsSaved() |
|
224 |
self.FileMenu.Enable(wx.ID_SAVE, project_modified) |
|
225 |
MenuToolBar.EnableTool(wx.ID_SAVE, project_modified) |
|
226 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
|
227 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, True) |
|
228 |
self.FileMenu.Enable(wx.ID_SAVEAS, True) |
|
229 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, True) |
|
230 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
|
2531
f5891ce3228e
Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents:
2497
diff
changeset
|
231 |
MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, True) |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
232 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATEAS, True) |
814 | 233 |
else: |
234 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
235 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
236 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
237 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
238 |
MenuToolBar.EnableTool(wx.ID_PRINT, False) |
|
239 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
240 |
MenuToolBar.EnableTool(wx.ID_SAVE, False) |
|
241 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
|
242 |
self.FileMenu.Enable(wx.ID_CLOSE_ALL, False) |
|
243 |
self.FileMenu.Enable(wx.ID_SAVEAS, False) |
|
244 |
MenuToolBar.EnableTool(wx.ID_SAVEAS, False) |
|
245 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
|
2531
f5891ce3228e
Add "Generate Program" to toolbar in PLCOpenEditor standalone mode.
Schlumpf <schlumpf@kr-ll.de>
parents:
2497
diff
changeset
|
246 |
MenuToolBar.EnableTool(ID_PLCOPENEDITORFILEMENUGENERATE, False) |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
247 |
self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATEAS, False) |
814 | 248 |
|
249 |
def OnNewProjectMenu(self, event): |
|
250 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
251 |
return |
|
252 |
dialog = ProjectDialog(self) |
|
253 |
if dialog.ShowModal() == wx.ID_OK: |
|
254 |
properties = dialog.GetValues() |
|
255 |
self.ResetView() |
|
256 |
self.Controler = PLCControler() |
|
257 |
self.Controler.CreateNewProject(properties) |
|
258 |
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
|
259 |
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
|
260 |
self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, |
814 | 261 |
LIBRARYTREE) |
262 |
||
263 |
def OnOpenProjectMenu(self, event): |
|
264 |
if self.Controler is not None and not self.CheckSaveBeforeClosing(): |
|
265 |
return |
|
266 |
filepath = "" |
|
267 |
if self.Controler is not None: |
|
268 |
filepath = self.Controler.GetFilePath() |
|
269 |
if filepath != "": |
|
270 |
directory = os.path.dirname(filepath) |
|
271 |
else: |
|
272 |
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
|
273 |
|
814 | 274 |
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
|
275 |
|
814 | 276 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, "", _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN) |
277 |
if dialog.ShowModal() == wx.ID_OK: |
|
278 |
filepath = dialog.GetPath() |
|
279 |
if os.path.isfile(filepath): |
|
280 |
self.ResetView() |
|
281 |
controler = PLCControler() |
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
self._Refresh(PROJECTTREE, LIBRARYTREE) |
814 | 288 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
289 |
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
|
290 |
|
814 | 291 |
if result is not None: |
1581
2295fdc5c271
fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1580
diff
changeset
|
292 |
(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
|
293 |
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
|
294 |
|
814 | 295 |
def OnCloseProjectMenu(self, event): |
296 |
if not self.CheckSaveBeforeClosing(): |
|
297 |
return |
|
298 |
self.ResetView() |
|
299 |
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU) |
|
300 |
||
301 |
def OnSaveProjectMenu(self, event): |
|
302 |
self.SaveProject() |
|
303 |
||
304 |
def OnSaveProjectAsMenu(self, event): |
|
305 |
self.SaveProjectAs() |
|
306 |
||
307 |
def OnGenerateProgramMenu(self, event): |
|
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
308 |
result = self.Controler.GetProgramFilePath() |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
309 |
if not result: |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
310 |
self.GenerateProgramAs() |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
311 |
else: |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
312 |
self.GenerateProgram(result) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
313 |
|
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
314 |
def OnGenerateProgramAsMenu(self, event): |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
315 |
self.GenerateProgramAs() |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
316 |
|
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
317 |
def GenerateProgramAs(self): |
2497
e04824ad26e4
Fix an exception on wx-3.0-gtk3 in PLCOpenEditor when generating ST files.
Schlumpf <schlumpf@kr-ll.de>
parents:
2177
diff
changeset
|
318 |
dialog = wx.FileDialog(self, _("Choose a file"), os.getcwd(), os.path.basename(self.Controler.GetProgramFilePath()), _("ST files (*.st)|*.st|All files|*.*"), wx.SAVE | wx.CHANGE_DIR) |
814 | 319 |
if dialog.ShowModal() == wx.ID_OK: |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
320 |
self.GenerateProgram(dialog.GetPath()) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
321 |
dialog.Destroy() |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
322 |
|
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
323 |
def GenerateProgram(self, filepath=None): |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
324 |
message_text = "" |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
325 |
header, icon = _("Done"), wx.ICON_INFORMATION |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
326 |
if os.path.isdir(os.path.dirname(filepath)): |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
327 |
_program, errors, warnings = self.Controler.GenerateProgram(filepath) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
328 |
message_text += "".join([_("warning: %s\n") % warning for warning in warnings]) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
329 |
if len(errors) > 0: |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
330 |
message_text += "".join([_("error: %s\n") % error for error in errors]) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
331 |
message_text += _("Can't generate program to file %s!") % filepath |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
332 |
header, icon = _("Error"), wx.ICON_ERROR |
814 | 333 |
else: |
2532
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
334 |
message_text += _("Program was successfully generated!") |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
335 |
else: |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
336 |
message_text += _("\"%s\" is not a valid folder!") % os.path.dirname(filepath) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
337 |
header, icon = _("Error"), wx.ICON_ERROR |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
338 |
message = wx.MessageDialog(self, message_text, header, wx.OK | icon) |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
339 |
message.ShowModal() |
b9d6f5d7e0f1
Create a "Generate Program As..." menu to make the "Generate Program" toolbutton even more useful.
Schlumpf <schlumpf@kr-ll.de>
parents:
2531
diff
changeset
|
340 |
message.Destroy() |
814 | 341 |
|
342 |
def OnAboutMenu(self, event): |
|
3570
eb915a9fdcb0
IDE: fix About dialog not showing (wxPython4 sequel), update copyright section.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
343 |
info = wx.adv.AboutDialogInfo() |
3906
f831ff63ca6e
IDE: display contents of revisions.txt (put there by installer builder script) in About Dialog.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3793
diff
changeset
|
344 |
info = version.GetAboutDialogInfo(info) |
1565
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
345 |
info.Name = "PLCOpenEditor" |
894f31f8ca64
make about dialog boxes use standard wx about dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1560
diff
changeset
|
346 |
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
|
347 |
"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
|
348 |
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
|
349 |
ShowAboutDialog(self, info) |
814 | 350 |
|
351 |
def SaveProject(self): |
|
352 |
result = self.Controler.SaveXMLFile() |
|
353 |
if not result: |
|
354 |
self.SaveProjectAs() |
|
355 |
else: |
|
356 |
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
|
357 |
|
814 | 358 |
def SaveProjectAs(self): |
359 |
filepath = self.Controler.GetFilePath() |
|
360 |
if filepath != "": |
|
361 |
directory, filename = os.path.split(filepath) |
|
362 |
else: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1732
diff
changeset
|
363 |
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
|
364 |
dialog = wx.FileDialog(self, _("Choose a file"), directory, filename, _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT) |
814 | 365 |
if dialog.ShowModal() == wx.ID_OK: |
366 |
filepath = dialog.GetPath() |
|
367 |
if os.path.isdir(os.path.dirname(filepath)): |
|
368 |
result = self.Controler.SaveXMLFile(filepath) |
|
369 |
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
|
370 |
self.ShowErrorMessage(_("Can't save project to file %s!") % filepath) |
814 | 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 |
self.ShowErrorMessage(_("\"%s\" is not a valid folder!") % os.path.dirname(filepath)) |
814 | 373 |
self._Refresh(TITLE, FILEMENU, PAGETITLES) |
374 |
dialog.Destroy() |
|
375 |
||
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
|
376 |
|
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
377 |
class PLCOpenEditorApp(wx.App): |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
378 |
# def SetOpenFile( |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
379 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
380 |
def PrintUsage(self): |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1815
diff
changeset
|
381 |
print("\nUsage of PLCOpenEditor.py :") |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1815
diff
changeset
|
382 |
print("\n %s [Filepath]\n" % sys.argv[0]) |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
383 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
384 |
def ParseCommandLine(self): |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
385 |
# Parse options given to PLCOpenEditor in command line |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
386 |
try: |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
387 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
388 |
except getopt.GetoptError: |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
389 |
# print help information and exit: |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
390 |
self.PrintUsage() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
391 |
sys.exit(2) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
392 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
393 |
# Extract if help has been requested |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1834
diff
changeset
|
394 |
for o, _a in opts: |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
395 |
if o in ("-h", "--help"): |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
396 |
self.PrintUsage() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
397 |
sys.exit() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
398 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
399 |
# Extract the optional filename to open |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
400 |
self.fileOpen = None |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
401 |
if len(args) > 1: |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
402 |
self.PrintUsage() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
403 |
sys.exit() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
404 |
elif len(args) == 1: |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
405 |
self.fileOpen = args[0] |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
406 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
407 |
def OnInit(self): |
1815
f0600fe03a89
add application name for PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1814
diff
changeset
|
408 |
self.SetAppName('plcopeneditor') |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
409 |
self.ParseCommandLine() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
410 |
InstallLocalRessources(beremiz_dir) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
411 |
util.ExceptionHandler.AddExceptHook(version.app_version) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
412 |
self.frame = PLCOpenEditor(None, fileOpen=self.fileOpen) |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
413 |
return True |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
414 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
415 |
def Show(self): |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
416 |
self.frame.Show() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
417 |
|
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
418 |
|
814 | 419 |
if __name__ == '__main__': |
1814
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
420 |
app = PLCOpenEditorApp() |
fc387c4fc1d4
rewrite PLCOpenEditor. Add PLCOpenEditorApp class for easier customizations.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
421 |
app.Show() |
814 | 422 |
app.MainLoop() |