130 hmipyfile.close() |
130 hmipyfile.close() |
131 |
131 |
132 else: |
132 else: |
133 define_hmi = "" |
133 define_hmi = "" |
134 |
134 |
135 declare_hmi = "\n".join(["%(name)s = None\n" % x for x in main_frames]) |
135 declare_hmi = \ |
136 declare_hmi += "\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" % |
136 "\n".join(["%(name)s = None\n" % x for x in main_frames]) + \ |
137 dict(x, h=h) for h in x['handlers']]) |
137 "\n".join(["\n".join(["%(class)s.%(h)s = %(h)s" % |
138 for x in hmi_objects]) |
138 dict(x, h=h) for h in x['handlers']]) |
|
139 for x in hmi_objects]) + """\ |
|
140 |
|
141 def OnCloseFrame(evt): |
|
142 wx.MessageBox(_("Please stop PLC to close")) |
|
143 |
|
144 def InitHMI(): |
|
145 """+"\n".join(["""\ |
|
146 %(name)s = %(class)s(None) |
|
147 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
|
148 %(name)s.Show() |
|
149 |
|
150 """ % x for x in main_frames]) + """\ |
|
151 def CleanupHMI(): |
|
152 """ + "\n".join(["""\ |
|
153 if %(name)s is not None: |
|
154 %(name)s.Destroy() |
|
155 """ % x for x in main_frames]) |
|
156 |
139 global_hmi = ("global %s\n" % ",".join( |
157 global_hmi = ("global %s\n" % ",".join( |
140 [x["name"] for x in main_frames]) if len(main_frames) > 0 else "") |
158 [x["name"] for x in main_frames]) if len(main_frames) > 0 else "") |
141 init_hmi = "\n".join(["""\ |
|
142 def OnCloseFrame(evt): |
|
143 wx.MessageBox(_("Please stop PLC to close")) |
|
144 |
|
145 %(name)s = %(class)s(None) |
|
146 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
|
147 %(name)s.Show() |
|
148 """ % x for x in main_frames]) |
|
149 cleanup_hmi = "\n".join( |
|
150 ["if %(name)s is not None: %(name)s.Destroy()" % x |
|
151 for x in main_frames]) |
|
152 |
159 |
153 self.PreSectionsTexts = { |
160 self.PreSectionsTexts = { |
154 "globals": define_hmi, |
161 "globals": define_hmi, |
155 "start": global_hmi, |
162 "start": global_hmi, |
156 "stop": global_hmi + cleanup_hmi |
163 "stop": global_hmi + "wx.CallAfter(CleanupHMI)\n" |
157 } |
164 } |
158 self.PostSectionsTexts = { |
165 self.PostSectionsTexts = { |
159 "globals": declare_hmi, |
166 "globals": declare_hmi, |
160 "start": init_hmi, |
167 "start": "wx.CallAfter(InitHMI)\n", |
161 } |
168 } |
162 |
169 |
163 if len(main_frames) == 0 and \ |
170 if len(main_frames) == 0 and \ |
164 len(getattr(self.CodeFile, "start").getanyText().strip()) == 0: |
171 len(getattr(self.CodeFile, "start").getanyText().strip()) == 0: |
165 self.GetCTRoot().logger.write_warning( |
172 self.GetCTRoot().logger.write_warning( |