37 self._getWXGLADEpath()) |
37 self._getWXGLADEpath()) |
38 return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
38 return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
39 |
39 |
40 def CTNGenerate_C(self, buildpath, locations): |
40 def CTNGenerate_C(self, buildpath, locations): |
41 |
41 |
42 hmi_frames = {} |
42 hmi_frames = [] |
43 |
43 |
44 wxgfile_path=self._getWXGLADEpath() |
44 wxgfile_path=self._getWXGLADEpath() |
45 if os.path.exists(wxgfile_path): |
45 if os.path.exists(wxgfile_path): |
46 wxgfile = open(wxgfile_path, 'r') |
46 wxgfile = open(wxgfile_path, 'r') |
47 wxgtree = minidom.parse(wxgfile) |
47 wxgtree = minidom.parse(wxgfile) |
48 wxgfile.close() |
48 wxgfile.close() |
49 |
49 |
50 for node in wxgtree.childNodes[1].childNodes: |
50 for node in wxgtree.childNodes[1].childNodes: |
51 if node.nodeType == wxgtree.ELEMENT_NODE: |
51 if node.nodeType == wxgtree.ELEMENT_NODE: |
52 hmi_frames[node._attrs["name"].value] = node._attrs["class"].value |
52 hmi_frames.append({ |
|
53 "name" : node.getAttribute("name"), |
|
54 "class" : node.getAttribute("class"), |
|
55 "handlers" : [ |
|
56 hnode.firstChild.data for hnode in |
|
57 node.getElementsByTagName("handler")]}) |
53 |
58 |
54 hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py") |
59 hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py") |
55 if wx.Platform == '__WXMSW__': |
60 if wx.Platform == '__WXMSW__': |
56 wxgfile_path = "\"%s\""%wxgfile_path |
61 wxgfile_path = "\"%s\""%wxgfile_path |
57 wxghmipyfile_path = "\"%s\""%hmipyfile_path |
62 wxghmipyfile_path = "\"%s\""%hmipyfile_path |
61 |
66 |
62 hmipyfile = open(hmipyfile_path, 'r') |
67 hmipyfile = open(hmipyfile_path, 'r') |
63 define_hmi = hmipyfile.read().decode('utf-8') |
68 define_hmi = hmipyfile.read().decode('utf-8') |
64 hmipyfile.close() |
69 hmipyfile.close() |
65 |
70 |
66 declare_hmi = "\n".join(map(lambda x:"%s = None" % x, |
71 declare_hmi = "\n".join(["%(name)s = None\n" % x + |
67 hmi_frames.keys())) |
72 "\n".join(["%(class)s.%(h)s = %(h)s"% |
68 global_hmi = "global "+",".join(hmi_frames.keys()) + "\n" |
73 dict(x,h=h) for h in x['handlers']]) |
69 init_hmi = "\n".join(map(lambda x: """\ |
74 for x in hmi_frames]) |
|
75 global_hmi = "global %s\n"%",".join( |
|
76 [x["name"] for x in hmi_frames]) |
|
77 init_hmi = "\n".join(["""\ |
70 def OnCloseFrame(evt): |
78 def OnCloseFrame(evt): |
71 wx.MessageBox(_("Please stop PLC to close")) |
79 wx.MessageBox(_("Please stop PLC to close")) |
72 |
80 |
73 %(name)s = %(class)s(None) |
81 %(name)s = %(class)s(None) |
74 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
82 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
75 %(name)s.Show() |
83 %(name)s.Show() |
76 """ % {"name": x[0], "class": x[1]}, hmi_frames.items())) |
84 """ % x for x in hmi_frames]) |
77 cleanup_hmi = "\n".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys())) |
85 cleanup_hmi = "\n".join( |
|
86 ["if %(name)s is not None: %(name)s.Destroy()" % x |
|
87 for x in hmi_frames]) |
78 |
88 |
79 self.PreSectionsTexts = { |
89 self.PreSectionsTexts = { |
80 "globals":define_hmi + declare_hmi, |
90 "globals":define_hmi, |
81 "start":global_hmi, |
91 "start":global_hmi, |
82 "stop":global_hmi + cleanup_hmi |
92 "stop":global_hmi + cleanup_hmi |
83 } |
93 } |
84 self.PostSectionsTexts = { |
94 self.PostSectionsTexts = { |
|
95 "globals":declare_hmi, |
85 "start":init_hmi, |
96 "start":init_hmi, |
86 } |
97 } |
87 |
98 |
88 return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations) |
99 return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations) |
89 |
100 |