wxglade_hmi/wxglade_hmi.py
changeset 1734 750eeb7230a1
parent 1732 94ffe74e6895
child 1736 7e61baa047f0
equal deleted inserted replaced
1733:dea107dce0c4 1734:750eeb7230a1
    71 
    71 
    72     def launch_wxglade(self, options, wait=False):
    72     def launch_wxglade(self, options, wait=False):
    73         path = self.GetWxGladePath()
    73         path = self.GetWxGladePath()
    74         glade = os.path.join(path, 'wxglade.py')
    74         glade = os.path.join(path, 'wxglade.py')
    75         if wx.Platform == '__WXMSW__':
    75         if wx.Platform == '__WXMSW__':
    76             glade = "\"%s\""%glade
    76             glade = "\"%s\"" % glade
    77         mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
    77         mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
    78         os.spawnv(mode, sys.executable, ["\"%s\""%sys.executable] + [glade] + options)
    78         os.spawnv(mode, sys.executable, ["\"%s\"" % sys.executable] + [glade] + options)
    79 
    79 
    80     def OnCTNSave(self, from_project_path=None):
    80     def OnCTNSave(self, from_project_path=None):
    81         if from_project_path is not None:
    81         if from_project_path is not None:
    82             shutil.copyfile(self._getWXGLADEpath(from_project_path),
    82             shutil.copyfile(self._getWXGLADEpath(from_project_path),
    83                             self._getWXGLADEpath())
    83                             self._getWXGLADEpath())
   102                             hnode.firstChild.data for hnode in
   102                             hnode.firstChild.data for hnode in
   103                             node.getElementsByTagName("handler")]})
   103                             node.getElementsByTagName("handler")]})
   104 
   104 
   105             hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py")
   105             hmipyfile_path=os.path.join(self._getBuildPath(), "hmi.py")
   106             if wx.Platform == '__WXMSW__':
   106             if wx.Platform == '__WXMSW__':
   107                 wxgfile_path = "\"%s\""%wxgfile_path
   107                 wxgfile_path = "\"%s\"" % wxgfile_path
   108                 wxghmipyfile_path = "\"%s\""%hmipyfile_path
   108                 wxghmipyfile_path = "\"%s\"" % hmipyfile_path
   109             else:
   109             else:
   110                 wxghmipyfile_path = hmipyfile_path
   110                 wxghmipyfile_path = hmipyfile_path
   111             self.launch_wxglade(['-o', wxghmipyfile_path, '-g', 'python', wxgfile_path], wait=True)
   111             self.launch_wxglade(['-o', wxghmipyfile_path, '-g', 'python', wxgfile_path], wait=True)
   112 
   112 
   113             hmipyfile = open(hmipyfile_path, 'r')
   113             hmipyfile = open(hmipyfile_path, 'r')
   119 
   119 
   120         declare_hmi = "\n".join(["%(name)s = None\n" % x +
   120         declare_hmi = "\n".join(["%(name)s = None\n" % x +
   121                           "\n".join(["%(class)s.%(h)s = %(h)s"%
   121                           "\n".join(["%(class)s.%(h)s = %(h)s"%
   122                             dict(x,h=h) for h in x['handlers']])
   122                             dict(x,h=h) for h in x['handlers']])
   123                                 for x in hmi_frames])
   123                                 for x in hmi_frames])
   124         global_hmi = ("global %s\n"%",".join(
   124         global_hmi = ("global %s\n" % ",".join(
   125                          [x["name"] for x in hmi_frames])
   125                          [x["name"] for x in hmi_frames])
   126                       if len(hmi_frames) > 0 else "")
   126                       if len(hmi_frames) > 0 else "")
   127         init_hmi = "\n".join(["""\
   127         init_hmi = "\n".join(["""\
   128 def OnCloseFrame(evt):
   128 def OnCloseFrame(evt):
   129     wx.MessageBox(_("Please stop PLC to close"))
   129     wx.MessageBox(_("Please stop PLC to close"))
   172         </object>
   172         </object>
   173         </object>
   173         </object>
   174     </application>
   174     </application>
   175     """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
   175     """ % {"name": hmi_name, "class": "Class_%s" % hmi_name})
   176             if wx.Platform == '__WXMSW__':
   176             if wx.Platform == '__WXMSW__':
   177                 wxg_filename = "\"%s\""%wxg_filename
   177                 wxg_filename = "\"%s\"" % wxg_filename
   178             self.launch_wxglade([wxg_filename])
   178             self.launch_wxglade([wxg_filename])