3 |
3 |
4 # This file is part of Beremiz, a Integrated Development Environment for |
4 # This file is part of Beremiz, a Integrated Development Environment for |
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6 # |
6 # |
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 # Copyright (C) 2017: Andrey Skvortsov |
8 # |
9 # |
9 # See COPYING file for copyrights details. |
10 # See COPYING file for copyrights details. |
10 # |
11 # |
11 # This program is free software; you can redistribute it and/or |
12 # This program is free software; you can redistribute it and/or |
12 # modify it under the terms of the GNU General Public License |
13 # modify it under the terms of the GNU General Public License |
25 import wx |
26 import wx |
26 import os, sys, shutil |
27 import os, sys, shutil |
27 |
28 |
28 from pyjs import translate |
29 from pyjs import translate |
29 |
30 |
|
31 import util.paths as paths |
30 from POULibrary import POULibrary |
32 from POULibrary import POULibrary |
31 from docutil import open_svg |
33 from docutil import open_svg |
32 from py_ext import PythonFileCTNMixin |
34 from py_ext import PythonFileCTNMixin |
33 |
35 |
34 class SVGUILibrary(POULibrary): |
36 class SVGUILibrary(POULibrary): |
35 def GetLibraryPath(self): |
37 def GetLibraryPath(self): |
36 return os.path.join(os.path.split(__file__)[0], "pous.xml") |
38 return paths.AbsNeighbourFile(__file__, "pous.xml") |
37 |
39 |
38 class SVGUI(PythonFileCTNMixin): |
40 class SVGUI(PythonFileCTNMixin): |
39 |
41 |
40 ConfNodeMethods = [ |
42 ConfNodeMethods = [ |
41 {"bitmap" : "ImportSVG", |
43 {"bitmap" : "ImportSVG", |
47 "tooltip" : _("Create HMI"), |
49 "tooltip" : _("Create HMI"), |
48 "method" : "_StartInkscape"}, |
50 "method" : "_StartInkscape"}, |
49 ] |
51 ] |
50 |
52 |
51 def ConfNodePath(self): |
53 def ConfNodePath(self): |
52 return os.path.join(os.path.dirname(__file__)) |
54 return paths.AbsDir(__file__) |
53 |
55 |
54 def _getSVGpath(self, project_path=None): |
56 def _getSVGpath(self, project_path=None): |
55 if project_path is None: |
57 if project_path is None: |
56 project_path = self.CTNPath() |
58 project_path = self.CTNPath() |
57 # define name for SVG file containing gui layout |
59 # define name for SVG file containing gui layout |
58 return os.path.join(project_path, "gui.svg") |
60 return os.path.join(project_path, "gui.svg") |
59 |
61 |
60 def _getSVGUIserverpath(self): |
62 def _getSVGUIserverpath(self): |
61 return os.path.join(os.path.dirname(__file__), "svgui_server.py") |
63 return paths.AbsNeighbourFile(__file__, "svgui_server.py") |
62 |
64 |
63 def OnCTNSave(self, from_project_path=None): |
65 def OnCTNSave(self, from_project_path=None): |
64 if from_project_path is not None: |
66 if from_project_path is not None: |
65 shutil.copyfile(self._getSVGpath(from_project_path), |
67 shutil.copyfile(self._getSVGpath(from_project_path), |
66 self._getSVGpath()) |
68 self._getSVGpath()) |
88 svguiservercode = svguiserverfile.read() |
90 svguiservercode = svguiserverfile.read() |
89 svguiserverfile.close() |
91 svguiserverfile.close() |
90 |
92 |
91 svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") |
93 svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") |
92 svguilibfile = open(svguilibpath, 'w') |
94 svguilibfile = open(svguilibpath, 'w') |
93 svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "sys.py"), "sys")) |
95 fpath=paths.AbsDir(__file__) |
94 svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "_pyjs.js"), 'r').read()) |
96 svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "sys.py"), "sys")) |
95 svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "pyjslib.py"), "pyjslib")) |
97 svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "_pyjs.js"), 'r').read()) |
96 svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "svguilib.py"), "svguilib")) |
98 svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "pyjslib.py"), "pyjslib")) |
|
99 svguilibfile.write(translate(os.path.join(fpath, "svguilib.py"), "svguilib")) |
97 svguilibfile.write("pyjslib();\nsvguilib();\n") |
100 svguilibfile.write("pyjslib();\nsvguilib();\n") |
98 svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "json.js"), 'r').read()) |
101 svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "json.js"), 'r').read()) |
99 svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "livesvg.js"), 'r').read()) |
102 svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read()) |
100 svguilibfile.close() |
103 svguilibfile.close() |
101 jsmodules = {"LiveSVGPage": "svguilib.js"} |
104 jsmodules = {"LiveSVGPage": "svguilib.js"} |
102 res += (("svguilib.js", file(svguilibpath,"rb")),) |
105 res += (("svguilib.js", file(svguilibpath,"rb")),) |
103 |
106 |
104 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
107 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |