Make 'runtime.py' and 'hmi.py' executed independantly
authorlbessard
Mon, 23 Mar 2009 16:20:05 +0100
changeset 322 b8ae0580565c
parent 321 5a4e6278a18b
child 323 9f07f0d429df
Make 'runtime.py' and 'hmi.py' executed independantly
runtime/PLCObject.py
--- a/runtime/PLCObject.py	Mon Mar 16 17:31:08 2009 +0100
+++ b/runtime/PLCObject.py	Mon Mar 23 16:20:05 2009 +0100
@@ -189,38 +189,38 @@
                 # TODO handle exceptions in runtime.py
                 # pyfile may redefine _runtime_cleanup
                 # or even call _PythonThreadProc itself.
-                if os.path.exists(hmifile):
-                   execfile(hmifile, self.python_threads_vars)
                 execfile(pyfile, self.python_threads_vars)
-                try:
-                   if self.python_threads_vars.has_key('wx'):
-	                   wx = self.python_threads_vars['wx']
-	                   # try to instanciate the first frame found.
-	                   for name, obj in self.python_threads_vars.iteritems():
-	                       # obj is a class
-	                       if type(obj)==type(type) and issubclass(obj,wx.Frame):
-	                           def create_frame():
-	                               self.hmi_frame = obj(None)
-	                               self.python_threads_vars[name] = self.hmi_frame
-	                               # keep track of class... never know
-	                               self.python_threads_vars['Class_'+name] = obj
-	                               self.hmi_frame.Bind(wx.EVT_CLOSE, OnCloseFrame)
-	                               self.hmi_frame.Show()
-	                           
-	                           def OnCloseFrame(evt):
-	                               self.hmi_frame.Destroy()
-	                               self.hmi_frame = None
-	                               wx.MessageBox("Please stop PLC to close")
-	                               #wx.CallAfter(self.StopPLC)
-	                               create_frame()
-	                               #evt.Skip()
-	                           create_frame()
-	                           break
-                except:
-                    PLCprint(traceback.format_exc())
             except:
                 PLCprint(traceback.format_exc())
-
+        if os.path.exists(hmifile):
+            try:
+                execfile(hmifile, self.python_threads_vars)
+                if self.python_threads_vars.has_key('wx'):
+                    wx = self.python_threads_vars['wx']
+                    # try to instanciate the first frame found.
+                    for name, obj in self.python_threads_vars.iteritems():
+                        # obj is a class
+                        if type(obj)==type(type) and issubclass(obj,wx.Frame):
+                            def create_frame():
+                                self.hmi_frame = obj(None)
+                                self.python_threads_vars[name] = self.hmi_frame
+                                # keep track of class... never know
+                                self.python_threads_vars['Class_'+name] = obj
+                                self.hmi_frame.Bind(wx.EVT_CLOSE, OnCloseFrame)
+                                self.hmi_frame.Show()
+                            
+                            def OnCloseFrame(evt):
+                                self.hmi_frame.Destroy()
+                                self.hmi_frame = None
+                                wx.MessageBox("Please stop PLC to close")
+                                #wx.CallAfter(self.StopPLC)
+                                create_frame()
+                                #evt.Skip()
+                            create_frame()
+                            break
+            except:
+                PLCprint(traceback.format_exc())
+            
     def BeginRuntimePy(self):
         runtime_begin = self.python_threads_vars.get("_runtime_begin",None)
         if runtime_begin is not None: