diff -r f794fbff8f02 -r 28f96aa9c070 wxglade_hmi/wxglade_hmi.py --- a/wxglade_hmi/wxglade_hmi.py Tue May 14 00:30:35 2013 +0200 +++ b/wxglade_hmi/wxglade_hmi.py Tue May 14 18:41:33 2013 +0900 @@ -38,19 +38,6 @@ return PythonFileCTNMixin.OnCTNSave(self, from_project_path) def CTNGenerate_C(self, buildpath, locations): - """ - Return C code generated by iec2c compiler - when _generate_softPLC have been called - @param locations: ignored - @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND - """ - - current_location = self.GetCurrentLocation() - # define a unique name for the generated C file - location_str = "_".join(map(lambda x:str(x), current_location)) - - runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) - runtimefile = open(runtimefile_path, 'w') hmi_frames = {} @@ -73,65 +60,32 @@ self.launch_wxglade(['-o', wxghmipyfile_path, '-g', 'python', wxgfile_path], wait=True) hmipyfile = open(hmipyfile_path, 'r') - runtimefile.write(hmipyfile.read()) + define_hmi = hmipyfile.read().decode('utf-8') hmipyfile.close() - sections_code = self.GetSectionsCode() + declare_hmi = "\n".join(map(lambda x:"%s = None" % x, + hmi_frames.keys())) + global_hmi = "global "+",".join(hmi_frames.keys()) + init_hmi = "\n".join(map(lambda x: """\ +def OnCloseFrame(evt): + wx.MessageBox(_("Please stop PLC to close")) + +%(name)s = %(class)s(None) +%(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) +%(name)s.Show() +""" % {"name": x[0], "class": x[1]}, hmi_frames.items())) + cleanup_hmi = "\n".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys())) - # Adding variables - runtimefile.write("## User variables reference\n" + - sections_code["variables"] + "\n") - - # Adding user global variables and routines - runtimefile.write("## User internal user variables and routines\n" + - sections_code["globals"] + "\n") - - for section in ["init", "cleanup"]: - if not sections_code[section]: - sections_code[section] = " pass" - - sections_code.update({ - "location": location_str, - "declare_hmi": "\n".join(map(lambda x:"%s = None" % x, hmi_frames.keys())), - "global_hmi": ",".join(hmi_frames.keys()), - "init_hmi": "\n".join(map(lambda x: """ - %(name)s = %(class)s(None) - %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) - %(name)s.Show() -""" % {"name": x[0], "class": x[1]}, - hmi_frames.items())), - "cleanup_hmi": "\n ".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys()))}) - - runtimefile.write(""" -%(declare_hmi)s + self.PreSectionsTexts = { + "globals":define_hmi + declare_hmi, + "start":global_hmi, + "stop":global_hmi + } + self.PostSectionsTexts = { + "start":init_hmi, + } -def _runtime_%(location)s_init(): -%(init)s - -def _runtime_%(location)s_cleanup(): -%(cleanup)s - -def _runtime_%(location)s_start(): - global %(global_hmi)s - -%(start)s - - def OnCloseFrame(evt): - wx.MessageBox(_("Please stop PLC to close")) - - %(init_hmi)s - -def _runtime_%(location)s_stop(): - global %(global_hmi)s - - %(cleanup_hmi)s - -%(stop)s - -""" % sections_code) - runtimefile.close() - - return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) + return PythonFileCTNMixin.CTNGenerate_C(self, buildpath, locations) def _editWXGLADE(self): wxg_filename = self._getWXGLADEpath()