wxglade_hmi/wxglade_hmi.py
changeset 1740 b789b695b5c6
parent 1739 ec153828ded2
child 1741 dd94b9a68c61
equal deleted inserted replaced
1739:ec153828ded2 1740:b789b695b5c6
    75     def launch_wxglade(self, options, wait=False):
    75     def launch_wxglade(self, options, wait=False):
    76         path = self.GetWxGladePath()
    76         path = self.GetWxGladePath()
    77         glade = os.path.join(path, 'wxglade.py')
    77         glade = os.path.join(path, 'wxglade.py')
    78         if wx.Platform == '__WXMSW__':
    78         if wx.Platform == '__WXMSW__':
    79             glade = "\"%s\"" % glade
    79             glade = "\"%s\"" % glade
    80         mode = {False:os.P_NOWAIT, True:os.P_WAIT}[wait]
    80         mode = {False: os.P_NOWAIT, True: os.P_WAIT}[wait]
    81         os.spawnv(mode, sys.executable, ["\"%s\"" % sys.executable] + [glade] + options)
    81         os.spawnv(mode, sys.executable, ["\"%s\"" % sys.executable] + [glade] + options)
    82 
    82 
    83     def OnCTNSave(self, from_project_path=None):
    83     def OnCTNSave(self, from_project_path=None):
    84         if from_project_path is not None:
    84         if from_project_path is not None:
    85             shutil.copyfile(self._getWXGLADEpath(from_project_path),
    85             shutil.copyfile(self._getWXGLADEpath(from_project_path),
   120         else:
   120         else:
   121             define_hmi = ""
   121             define_hmi = ""
   122 
   122 
   123         declare_hmi = "\n".join(["%(name)s = None\n" % x +
   123         declare_hmi = "\n".join(["%(name)s = None\n" % x +
   124                           "\n".join(["%(class)s.%(h)s = %(h)s"%
   124                           "\n".join(["%(class)s.%(h)s = %(h)s"%
   125                             dict(x,h=h) for h in x['handlers']])
   125                             dict(x, h=h) for h in x['handlers']])
   126                                 for x in hmi_frames])
   126                                 for x in hmi_frames])
   127         global_hmi = ("global %s\n" % ",".join(
   127         global_hmi = ("global %s\n" % ",".join(
   128                          [x["name"] for x in hmi_frames])
   128                          [x["name"] for x in hmi_frames])
   129                       if len(hmi_frames) > 0 else "")
   129                       if len(hmi_frames) > 0 else "")
   130         init_hmi = "\n".join(["""\
   130         init_hmi = "\n".join(["""\
   138         cleanup_hmi = "\n".join(
   138         cleanup_hmi = "\n".join(
   139             ["if %(name)s is not None: %(name)s.Destroy()" % x
   139             ["if %(name)s is not None: %(name)s.Destroy()" % x
   140                 for x in hmi_frames])
   140                 for x in hmi_frames])
   141 
   141 
   142         self.PreSectionsTexts = {
   142         self.PreSectionsTexts = {
   143             "globals":define_hmi,
   143             "globals": define_hmi,
   144             "start":global_hmi,
   144             "start":   global_hmi,
   145             "stop":global_hmi + cleanup_hmi
   145             "stop":    global_hmi + cleanup_hmi
   146         }
   146         }
   147         self.PostSectionsTexts = {
   147         self.PostSectionsTexts = {
   148             "globals":declare_hmi,
   148             "globals": declare_hmi,
   149             "start":init_hmi,
   149             "start":   init_hmi,
   150         }
   150         }
   151 
   151 
   152         return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations)
   152         return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations)
   153 
   153 
   154     def _editWXGLADE(self):
   154     def _editWXGLADE(self):
   162             open_wxglade = dialog.ShowModal() == wx.ID_YES
   162             open_wxglade = dialog.ShowModal() == wx.ID_YES
   163             dialog.Destroy()
   163             dialog.Destroy()
   164         if open_wxglade:
   164         if open_wxglade:
   165             if not os.path.exists(wxg_filename):
   165             if not os.path.exists(wxg_filename):
   166                 hmi_name = self.BaseParams.getName()
   166                 hmi_name = self.BaseParams.getName()
   167                 open(wxg_filename,"w").write("""<?xml version="1.0"?>
   167                 open(wxg_filename, "w").write("""<?xml version="1.0"?>
   168     <application path="" name="" class="" option="0" language="python" top_window="%(name)s" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0">
   168     <application path="" name="" class="" option="0" language="python" top_window="%(name)s" encoding="UTF-8" use_gettext="0" overwrite="0" use_new_namespace="1" for_version="2.8" is_template="0">
   169         <object class="%(class)s" name="%(name)s" base="EditFrame">
   169         <object class="%(class)s" name="%(name)s" base="EditFrame">
   170             <style>wxDEFAULT_FRAME_STYLE</style>
   170             <style>wxDEFAULT_FRAME_STYLE</style>
   171             <title>frame_1</title>
   171             <title>frame_1</title>
   172             <object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
   172             <object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">