author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Mon, 23 Jan 2017 16:22:04 +0300 | |
changeset 1642 | ce9fc57e1828 |
parent 1511 | 91538d0c242c |
child 1680 | 6db967480b7d |
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 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
8 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
9 |
# 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
|
10 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
11 |
# 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
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
16 |
# 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
|
17 |
# 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
|
18 |
# 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
|
19 |
# 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
|
20 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1061
diff
changeset
|
21 |
# 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
|
22 |
# 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
|
23 |
# 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
|
24 |
|
371 | 25 |
import wx |
407 | 26 |
import os, sys, shutil |
371 | 27 |
|
28 |
from pyjs import translate |
|
29 |
||
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
30 |
from POULibrary import POULibrary |
737 | 31 |
from docutil import open_svg |
1061 | 32 |
from py_ext import PythonFileCTNMixin |
371 | 33 |
|
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
34 |
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
|
35 |
def GetLibraryPath(self): |
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
36 |
return os.path.join(os.path.split(__file__)[0], "pous.xml") |
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
37 |
|
1061 | 38 |
class SVGUI(PythonFileCTNMixin): |
371 | 39 |
|
717 | 40 |
ConfNodeMethods = [ |
734 | 41 |
{"bitmap" : "ImportSVG", |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
42 |
"name" : _("Import SVG"), |
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
43 |
"tooltip" : _("Import SVG"), |
371 | 44 |
"method" : "_ImportSVG"}, |
734 | 45 |
{"bitmap" : "ImportSVG", # should be something different |
415
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
46 |
"name" : _("Inkscape"), |
339fa2542481
improved english spelling and grammar and internationalization updated
laurent
parents:
410
diff
changeset
|
47 |
"tooltip" : _("Create HMI"), |
371 | 48 |
"method" : "_StartInkscape"}, |
49 |
] |
|
50 |
||
717 | 51 |
def ConfNodePath(self): |
728
e0424e96e3fd
refactoring - library support is not anymore attached to configtree nodes, but handles by project controller
Edouard Tisserant
parents:
725
diff
changeset
|
52 |
return os.path.join(os.path.dirname(__file__)) |
371 | 53 |
|
1061 | 54 |
def _getSVGpath(self, project_path=None): |
55 |
if project_path is None: |
|
56 |
project_path = self.CTNPath() |
|
57 |
# define name for SVG file containing gui layout |
|
58 |
return os.path.join(project_path, "gui.svg") |
|
371 | 59 |
|
60 |
def _getSVGUIserverpath(self): |
|
61 |
return os.path.join(os.path.dirname(__file__), "svgui_server.py") |
|
62 |
||
1061 | 63 |
def OnCTNSave(self, from_project_path=None): |
64 |
if from_project_path is not None: |
|
65 |
shutil.copyfile(self._getSVGpath(from_project_path), |
|
66 |
self._getSVGpath()) |
|
67 |
return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
|
68 |
||
718 | 69 |
def CTNGenerate_C(self, buildpath, locations): |
371 | 70 |
""" |
71 |
Return C code generated by iec2c compiler |
|
72 |
when _generate_softPLC have been called |
|
73 |
@param locations: ignored |
|
74 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
75 |
""" |
|
76 |
||
77 |
current_location = self.GetCurrentLocation() |
|
78 |
# define a unique name for the generated C file |
|
79 |
location_str = "_".join(map(lambda x:str(x), current_location)) |
|
80 |
||
81 |
res = ([], "", False) |
|
82 |
||
83 |
svgfile=self._getSVGpath() |
|
84 |
if os.path.exists(svgfile): |
|
85 |
res += (("gui.svg", file(svgfile,"rb")),) |
|
86 |
||
87 |
svguiserverfile = open(self._getSVGUIserverpath(), 'r') |
|
88 |
svguiservercode = svguiserverfile.read() |
|
89 |
svguiserverfile.close() |
|
90 |
||
91 |
svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") |
|
92 |
svguilibfile = open(svguilibpath, 'w') |
|
93 |
svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "sys.py"), "sys")) |
|
94 |
svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "_pyjs.js"), 'r').read()) |
|
95 |
svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "pyjslib.py"), "pyjslib")) |
|
96 |
svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "svguilib.py"), "svguilib")) |
|
97 |
svguilibfile.write("pyjslib();\nsvguilib();\n") |
|
98 |
svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "json.js"), 'r').read()) |
|
99 |
svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "livesvg.js"), 'r').read()) |
|
100 |
svguilibfile.close() |
|
101 |
jsmodules = {"LiveSVGPage": "svguilib.js"} |
|
102 |
res += (("svguilib.js", file(svguilibpath,"rb")),) |
|
103 |
||
104 |
runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
|
105 |
runtimefile = open(runtimefile_path, 'w') |
|
106 |
runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) |
|
107 |
runtimefile.write(""" |
|
1014
e2f7d6c95db0
Now python files provided by extentions have init, start, stop and cleanup hooks
Edouard Tisserant
parents:
737
diff
changeset
|
108 |
def _runtime_%(location)s_start(): |
371 | 109 |
website.LoadHMI(%(svgui_class)s, %(jsmodules)s) |
110 |
||
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_stop(): |
371 | 112 |
website.UnLoadHMI() |
113 |
||
114 |
""" % {"location": location_str, |
|
115 |
"svgui_class": "SVGUI_HMI", |
|
116 |
"jsmodules" : str(jsmodules), |
|
117 |
}) |
|
118 |
runtimefile.close() |
|
119 |
||
120 |
res += (("runtime_%s.py"%location_str, file(runtimefile_path,"rb")),) |
|
121 |
||
122 |
return res |
|
123 |
||
124 |
def _ImportSVG(self): |
|
718 | 125 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN) |
371 | 126 |
if dialog.ShowModal() == wx.ID_OK: |
127 |
svgpath = dialog.GetPath() |
|
128 |
if os.path.isfile(svgpath): |
|
129 |
shutil.copy(svgpath, self._getSVGpath()) |
|
130 |
else: |
|
718 | 131 |
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n")%svgpath) |
371 | 132 |
dialog.Destroy() |
133 |
||
134 |
def _StartInkscape(self): |
|
135 |
svgfile = self._getSVGpath() |
|
427 | 136 |
open_inkscape = True |
718 | 137 |
if not self.GetCTRoot().CheckProjectPathPerm(): |
138 |
dialog = wx.MessageDialog(self.GetCTRoot().AppFrame, |
|
427 | 139 |
_("You don't have write permissions.\nOpen Inkscape anyway ?"), |
140 |
_("Open Inkscape"), |
|
141 |
wx.YES_NO|wx.ICON_QUESTION) |
|
142 |
open_inkscape = dialog.ShowModal() == wx.ID_YES |
|
143 |
dialog.Destroy() |
|
144 |
if open_inkscape: |
|
145 |
if not os.path.isfile(svgfile): |
|
146 |
svgfile = None |
|
147 |
open_svg(svgfile) |