88 self._getWXGLADEpath()) |
88 self._getWXGLADEpath()) |
89 return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
89 return PythonFileCTNMixin.OnCTNSave(self, from_project_path) |
90 |
90 |
91 def CTNGenerate_C(self, buildpath, locations): |
91 def CTNGenerate_C(self, buildpath, locations): |
92 |
92 |
93 hmi_frames = [] |
93 # list containing description of all objects declared in wxglade |
|
94 hmi_objects = [] |
|
95 # list containing only description of the main frame object |
|
96 main_frames = [] |
94 |
97 |
95 wxgfile_path = self._getWXGLADEpath() |
98 wxgfile_path = self._getWXGLADEpath() |
96 if os.path.exists(wxgfile_path): |
99 if os.path.exists(wxgfile_path): |
97 wxgfile = open(wxgfile_path, 'r') |
100 wxgfile = open(wxgfile_path, 'r') |
98 wxgtree = minidom.parse(wxgfile) |
101 wxgtree = minidom.parse(wxgfile) |
99 wxgfile.close() |
102 wxgfile.close() |
100 |
103 |
101 for node in wxgtree.childNodes[1].childNodes: |
104 for node in wxgtree.childNodes[1].childNodes: |
102 if node.nodeType == wxgtree.ELEMENT_NODE: |
105 if node.nodeType == wxgtree.ELEMENT_NODE: |
103 hmi_frames.append({ |
106 name = node.getAttribute("name") |
104 "name": node.getAttribute("name"), |
107 wxglade_object_desc = { |
|
108 "name": name, |
105 "class": node.getAttribute("class"), |
109 "class": node.getAttribute("class"), |
106 "handlers": [ |
110 "handlers": [ |
107 hnode.firstChild.data for hnode in |
111 hnode.firstChild.data for hnode in |
108 node.getElementsByTagName("handler")]}) |
112 node.getElementsByTagName("handler")]} |
|
113 |
|
114 hmi_objects.append(wxglade_object_desc) |
|
115 if name == self.CTNName() : |
|
116 main_frames.append(wxglade_object_desc) |
109 |
117 |
110 hmipyfile_path = os.path.join(self._getBuildPath(), "hmi.py") |
118 hmipyfile_path = os.path.join(self._getBuildPath(), "hmi.py") |
111 if wx.Platform == '__WXMSW__': |
119 if wx.Platform == '__WXMSW__': |
112 wxgfile_path = "\"%s\"" % wxgfile_path |
120 wxgfile_path = "\"%s\"" % wxgfile_path |
113 wxghmipyfile_path = "\"%s\"" % hmipyfile_path |
121 wxghmipyfile_path = "\"%s\"" % hmipyfile_path |
120 hmipyfile.close() |
128 hmipyfile.close() |
121 |
129 |
122 else: |
130 else: |
123 define_hmi = "" |
131 define_hmi = "" |
124 |
132 |
125 declare_hmi = "\n".join(["%(name)s = None\n" % x + |
133 declare_hmi = "\n".join(["%(name)s = None\n" % x for x in main_frames]) |
126 "\n".join(["%(class)s.%(h)s = %(h)s" % |
134 declare_hmi += "\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" % |
127 dict(x, h=h) for h in x['handlers']]) |
135 dict(x, h=h) for h in x['handlers']]) |
128 for x in hmi_frames]) |
136 for x in hmi_objects]) |
129 global_hmi = ("global %s\n" % ",".join( |
137 global_hmi = ("global %s\n" % ",".join( |
130 [x["name"] for x in hmi_frames]) if len(hmi_frames) > 0 else "") |
138 [x["name"] for x in main_frames]) if len(main_frames) > 0 else "") |
131 init_hmi = "\n".join(["""\ |
139 init_hmi = "\n".join(["""\ |
132 def OnCloseFrame(evt): |
140 def OnCloseFrame(evt): |
133 wx.MessageBox(_("Please stop PLC to close")) |
141 wx.MessageBox(_("Please stop PLC to close")) |
134 |
142 |
135 %(name)s = %(class)s(None) |
143 %(name)s = %(class)s(None) |
136 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
144 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
137 %(name)s.Show() |
145 %(name)s.Show() |
138 """ % x for x in hmi_frames]) |
146 """ % x for x in main_frames]) |
139 cleanup_hmi = "\n".join( |
147 cleanup_hmi = "\n".join( |
140 ["if %(name)s is not None: %(name)s.Destroy()" % x |
148 ["if %(name)s is not None: %(name)s.Destroy()" % x |
141 for x in hmi_frames]) |
149 for x in main_frames]) |
142 |
150 |
143 self.PreSectionsTexts = { |
151 self.PreSectionsTexts = { |
144 "globals": define_hmi, |
152 "globals": define_hmi, |
145 "start": global_hmi, |
153 "start": global_hmi, |
146 "stop": global_hmi + cleanup_hmi |
154 "stop": global_hmi + cleanup_hmi |
148 self.PostSectionsTexts = { |
156 self.PostSectionsTexts = { |
149 "globals": declare_hmi, |
157 "globals": declare_hmi, |
150 "start": init_hmi, |
158 "start": init_hmi, |
151 } |
159 } |
152 |
160 |
|
161 if len(main_frames) == 0 and \ |
|
162 len(getattr(self.CodeFile, "start").getanyText().strip()) == 0: |
|
163 self.GetCTRoot().logger.write_warning( |
|
164 _("Warning: WxGlade HMI has no object with name identical to extension name, and no python code is provided in start section to create object.\n")) |
|
165 |
153 return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations) |
166 return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations) |
154 |
167 |
155 def _editWXGLADE(self): |
168 def _editWXGLADE(self): |
156 wxg_filename = self._getWXGLADEpath() |
169 wxg_filename = self._getWXGLADEpath() |
157 open_wxglade = True |
170 open_wxglade = True |