author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 05 Jul 2017 12:59:43 +0300 | |
changeset 1714 | 64ea7c86a74c |
parent 1680 | 6db967480b7d |
child 1730 | 64d8f52bc8c8 |
permissions | -rw-r--r-- |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
3 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
6 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
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:
1511
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
9 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
11 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
16 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
20 |
# GNU General Public License for more details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
21 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
25 |
|
371 | 26 |
import wx |
407 | 27 |
import os, sys, shutil |
371 | 28 |
|
29 |
from pyjs import translate |
|
30 |
||
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
31 |
import util.paths as paths |
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
32 |
from POULibrary import POULibrary |
737 | 33 |
from docutil import open_svg |
1061 | 34 |
from py_ext import PythonFileCTNMixin |
371 | 35 |
|
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
36 |
class SVGUILibrary(POULibrary): |
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
37 |
def GetLibraryPath(self): |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
38 |
return paths.AbsNeighbourFile(__file__, "pous.xml") |
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
39 |
|
1061 | 40 |
class SVGUI(PythonFileCTNMixin): |
371 | 41 |
|
717 | 42 |
ConfNodeMethods = [ |
734 | 43 |
{"bitmap" : "ImportSVG", |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
44 |
"name" : _("Import SVG"), |
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
45 |
"tooltip" : _("Import SVG"), |
371 | 46 |
"method" : "_ImportSVG"}, |
734 | 47 |
{"bitmap" : "ImportSVG", # should be something different |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
48 |
"name" : _("Inkscape"), |
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
49 |
"tooltip" : _("Create HMI"), |
371 | 50 |
"method" : "_StartInkscape"}, |
51 |
] |
|
52 |
||
717 | 53 |
def ConfNodePath(self): |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
54 |
return paths.AbsDir(__file__) |
371 | 55 |
|
1061 | 56 |
def _getSVGpath(self, project_path=None): |
57 |
if project_path is None: |
|
58 |
project_path = self.CTNPath() |
|
59 |
# define name for SVG file containing gui layout |
|
60 |
return os.path.join(project_path, "gui.svg") |
|
371 | 61 |
|
62 |
def _getSVGUIserverpath(self): |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
63 |
return paths.AbsNeighbourFile(__file__, "svgui_server.py") |
371 | 64 |
|
1061 | 65 |
def OnCTNSave(self, from_project_path=None): |
66 |
if from_project_path is not None: |
|
67 |
shutil.copyfile(self._getSVGpath(from_project_path), |
|
68 |
self._getSVGpath()) |
|
69 |
return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
|
70 |
||
718 | 71 |
def CTNGenerate_C(self, buildpath, locations): |
371 | 72 |
""" |
73 |
Return C code generated by iec2c compiler |
|
74 |
when _generate_softPLC have been called |
|
75 |
@param locations: ignored |
|
76 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
77 |
""" |
|
78 |
||
79 |
current_location = self.GetCurrentLocation() |
|
80 |
# define a unique name for the generated C file |
|
81 |
location_str = "_".join(map(lambda x:str(x), current_location)) |
|
82 |
||
83 |
res = ([], "", False) |
|
84 |
||
85 |
svgfile=self._getSVGpath() |
|
86 |
if os.path.exists(svgfile): |
|
87 |
res += (("gui.svg", file(svgfile,"rb")),) |
|
88 |
||
89 |
svguiserverfile = open(self._getSVGUIserverpath(), 'r') |
|
90 |
svguiservercode = svguiserverfile.read() |
|
91 |
svguiserverfile.close() |
|
92 |
||
93 |
svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") |
|
94 |
svguilibfile = open(svguilibpath, 'w') |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
95 |
fpath=paths.AbsDir(__file__) |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
96 |
svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "sys.py"), "sys")) |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
97 |
svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "_pyjs.js"), 'r').read()) |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
98 |
svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "pyjslib.py"), "pyjslib")) |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
99 |
svguilibfile.write(translate(os.path.join(fpath, "svguilib.py"), "svguilib")) |
371 | 100 |
svguilibfile.write("pyjslib();\nsvguilib();\n") |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
101 |
svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "json.js"), 'r').read()) |
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
102 |
svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read()) |
371 | 103 |
svguilibfile.close() |
104 |
jsmodules = {"LiveSVGPage": "svguilib.js"} |
|
105 |
res += (("svguilib.js", file(svguilibpath,"rb")),) |
|
106 |
||
107 |
runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
|
108 |
runtimefile = open(runtimefile_path, 'w') |
|
109 |
runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) |
|
110 |
runtimefile.write(""" |
|
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
737
diff
changeset
|
111 |
def _runtime_%(location)s_start(): |
371 | 112 |
website.LoadHMI(%(svgui_class)s, %(jsmodules)s) |
113 |
||
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
737
diff
changeset
|
114 |
def _runtime_%(location)s_stop(): |
371 | 115 |
website.UnLoadHMI() |
116 |
||
117 |
""" % {"location": location_str, |
|
118 |
"svgui_class": "SVGUI_HMI", |
|
119 |
"jsmodules" : str(jsmodules), |
|
120 |
}) |
|
121 |
runtimefile.close() |
|
122 |
||
123 |
res += (("runtime_%s.py"%location_str, file(runtimefile_path,"rb")),) |
|
124 |
||
125 |
return res |
|
126 |
||
127 |
def _ImportSVG(self): |
|
718 | 128 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) |
371 | 129 |
if dialog.ShowModal() == wx.ID_OK: |
130 |
svgpath = dialog.GetPath() |
|
131 |
if os.path.isfile(svgpath): |
|
132 |
shutil.copy(svgpath, self._getSVGpath()) |
|
133 |
else: |
|
718 | 134 |
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n")%svgpath) |
371 | 135 |
dialog.Destroy() |
136 |
||
137 |
def _StartInkscape(self): |
|
138 |
svgfile = self._getSVGpath() |
|
427 | 139 |
open_inkscape = True |
718 | 140 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
141 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
|
427 | 142 |
_("You don't have write permissions.\nOpen Inkscape anyway ?"), |
143 |
_("Open Inkscape"), |
|
144 |
wx.YES_NO|wx.ICON_QUESTION) |
|
145 |
open_inkscape = dialog.ShowModal() == wx.ID_YES |
|
146 |
dialog.Destroy() |
|
147 |
if open_inkscape: |
|
148 |
if not os.path.isfile(svgfile): |
|
149 |
svgfile = None |
|
150 |
open_svg(svgfile) |