74 |
74 |
75 hmipyfile = open(hmipyfile_path, 'r') |
75 hmipyfile = open(hmipyfile_path, 'r') |
76 runtimefile.write(hmipyfile.read()) |
76 runtimefile.write(hmipyfile.read()) |
77 hmipyfile.close() |
77 hmipyfile.close() |
78 |
78 |
79 runtimefile.write(self.GetPythonCode()) |
79 sections_code = self.GetSectionsCode() |
80 runtimefile.write(""" |
80 |
81 %(declare)s |
81 # Adding variables |
82 |
82 runtimefile.write("## User variables reference\n" + |
83 def _runtime_%(location)s_start(): |
83 sections_code["variables"] + "\n") |
84 global %(global)s |
84 |
85 |
85 # Adding user global variables and routines |
86 def OnCloseFrame(evt): |
86 runtimefile.write("## User internal user variables and routines\n" + |
87 wx.MessageBox(_("Please stop PLC to close")) |
87 sections_code["globals"] + "\n") |
88 |
88 |
89 %(init)s |
89 for section in ["init", "cleanup"]: |
90 |
90 if not sections_code[section]: |
91 def _runtime_%(location)s_stop(): |
91 sections_code = " pass" |
92 global %(global)s |
92 |
93 |
93 sections_code.update({ |
94 %(cleanup)s |
94 "location": location_str, |
95 |
95 "declare_hmi": "\n".join(map(lambda x:"%s = None" % x, hmi_frames.keys())), |
96 """ % {"location": location_str, |
96 "global_hmi": ",".join(hmi_frames.keys()), |
97 "declare": "\n".join(map(lambda x:"%s = None" % x, hmi_frames.keys())), |
97 "init_hmi": "\n".join(map(lambda x: """ |
98 "global": ",".join(hmi_frames.keys()), |
|
99 "init": "\n".join(map(lambda x: """ |
|
100 %(name)s = %(class)s(None) |
98 %(name)s = %(class)s(None) |
101 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
99 %(name)s.Bind(wx.EVT_CLOSE, OnCloseFrame) |
102 %(name)s.Show() |
100 %(name)s.Show() |
103 """ % {"name": x[0], "class": x[1]}, |
101 """ % {"name": x[0], "class": x[1]}, |
104 hmi_frames.items())), |
102 hmi_frames.items())), |
105 "cleanup": "\n ".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys()))}) |
103 "cleanup_hmi": "\n ".join(map(lambda x:"if %s is not None: %s.Destroy()" % (x,x), hmi_frames.keys()))}) |
|
104 |
|
105 runtimefile.write(""" |
|
106 %(declare_hmi)s |
|
107 |
|
108 def _runtime_%(location)s_init(): |
|
109 %(init)s |
|
110 |
|
111 def _runtime_%(location)s_cleanup(): |
|
112 %(cleanup)s |
|
113 |
|
114 def _runtime_%(location)s_start(): |
|
115 global %(global_hmi)s |
|
116 |
|
117 %(start)s |
|
118 |
|
119 def OnCloseFrame(evt): |
|
120 wx.MessageBox(_("Please stop PLC to close")) |
|
121 |
|
122 %(init_hmi)s |
|
123 |
|
124 def _runtime_%(location)s_stop(): |
|
125 global %(global_hmi)s |
|
126 |
|
127 %(cleanup_hmi)s |
|
128 |
|
129 %(stop)s |
|
130 |
|
131 """ % sections_code) |
106 runtimefile.close() |
132 runtimefile.close() |
107 |
133 |
108 return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
134 return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
109 |
135 |
110 def _editWXGLADE(self): |
136 def _editWXGLADE(self): |