3 |
3 |
4 from pyjs import translate |
4 from pyjs import translate |
5 |
5 |
6 from POULibrary import POULibrary |
6 from POULibrary import POULibrary |
7 from docutil import open_svg |
7 from docutil import open_svg |
|
8 from py_ext import PythonFileCTNMixin |
8 |
9 |
9 class SVGUILibrary(POULibrary): |
10 class SVGUILibrary(POULibrary): |
10 def GetLibraryPath(self): |
11 def GetLibraryPath(self): |
11 return os.path.join(os.path.split(__file__)[0], "pous.xml") |
12 return os.path.join(os.path.split(__file__)[0], "pous.xml") |
12 |
13 |
13 class SVGUI: |
14 class SVGUI(PythonFileCTNMixin): |
14 |
15 |
15 ConfNodeMethods = [ |
16 ConfNodeMethods = [ |
16 {"bitmap" : "ImportSVG", |
17 {"bitmap" : "ImportSVG", |
17 "name" : _("Import SVG"), |
18 "name" : _("Import SVG"), |
18 "tooltip" : _("Import SVG"), |
19 "tooltip" : _("Import SVG"), |
24 ] |
25 ] |
25 |
26 |
26 def ConfNodePath(self): |
27 def ConfNodePath(self): |
27 return os.path.join(os.path.dirname(__file__)) |
28 return os.path.join(os.path.dirname(__file__)) |
28 |
29 |
29 def _getSVGpath(self): |
30 def _getSVGpath(self, project_path=None): |
30 # define name for IEC raw code file |
31 if project_path is None: |
31 return os.path.join(self.CTNPath(), "gui.svg") |
32 project_path = self.CTNPath() |
|
33 # define name for SVG file containing gui layout |
|
34 return os.path.join(project_path, "gui.svg") |
32 |
35 |
33 def _getSVGUIserverpath(self): |
36 def _getSVGUIserverpath(self): |
34 return os.path.join(os.path.dirname(__file__), "svgui_server.py") |
37 return os.path.join(os.path.dirname(__file__), "svgui_server.py") |
|
38 |
|
39 def OnCTNSave(self, from_project_path=None): |
|
40 if from_project_path is not None: |
|
41 shutil.copyfile(self._getSVGpath(from_project_path), |
|
42 self._getSVGpath()) |
|
43 return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
35 |
44 |
36 def CTNGenerate_C(self, buildpath, locations): |
45 def CTNGenerate_C(self, buildpath, locations): |
37 """ |
46 """ |
38 Return C code generated by iec2c compiler |
47 Return C code generated by iec2c compiler |
39 when _generate_softPLC have been called |
48 when _generate_softPLC have been called |
70 |
79 |
71 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
80 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
72 runtimefile = open(runtimefile_path, 'w') |
81 runtimefile = open(runtimefile_path, 'w') |
73 runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) |
82 runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) |
74 runtimefile.write(""" |
83 runtimefile.write(""" |
75 def _runtime_%(location)s_begin(): |
84 def _runtime_%(location)s_start(): |
76 website.LoadHMI(%(svgui_class)s, %(jsmodules)s) |
85 website.LoadHMI(%(svgui_class)s, %(jsmodules)s) |
77 |
86 |
78 def _runtime_%(location)s_cleanup(): |
87 def _runtime_%(location)s_stop(): |
79 website.UnLoadHMI() |
88 website.UnLoadHMI() |
80 |
89 |
81 """ % {"location": location_str, |
90 """ % {"location": location_str, |
82 "svgui_class": "SVGUI_HMI", |
91 "svgui_class": "SVGUI_HMI", |
83 "jsmodules" : str(jsmodules), |
92 "jsmodules" : str(jsmodules), |