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