Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
authoretisserant
Thu, 21 Feb 2008 11:42:33 +0100
changeset 105 434aed8dc58d
parent 104 d70b05f43e73
child 106 9810689febb0
Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
Beremiz.py
plugger.py
plugins/c_ext/c_ext.py
plugins/canfestival/canfestival.py
plugins/svgui/svgui.py
--- a/Beremiz.py	Mon Feb 18 18:34:24 2008 +0100
+++ b/Beremiz.py	Thu Feb 21 11:42:33 2008 +0100
@@ -788,7 +788,7 @@
     
     def GetButtonCallBackFunction(self, plugin, method):
         def OnButtonClick(event):
-            method(plugin, self.Log)
+            getattr(plugin,method)(self.Log)
             self.RefreshVariableLists()
             event.Skip()
         return OnButtonClick
--- a/plugger.py	Mon Feb 18 18:34:24 2008 +0100
+++ b/plugger.py	Thu Feb 21 11:42:33 2008 +0100
@@ -487,6 +487,10 @@
             
 
     def LoadXMLParams(self, PlugName = None):
+        methode_name = os.path.join(self.PlugPath(PlugName), "methods.py")
+        if os.path.isfile(methode_name):
+            execfile(methode_name)
+
         # Get the base xml tree
         if self.MandatoryParams:
             basexmlfile = open(self.PluginBaseXmlFilePath(PlugName), 'r')
@@ -938,8 +942,6 @@
         
         return True
         
-        
-    # Link object files into something that can be executed on target
 
     def _showIECcode(self, logger):
         plc_file = self._getIECcodepath()
@@ -993,29 +995,36 @@
     def _Run(self, logger):
         logger.write_error("Not impl\n")
 
+    def _Stop(self, logger):
+        logger.write_error("Not impl\n")
+
     PluginMethods = [
         {"bitmap" : os.path.join("images", "editPLC"),
          "name" : "Edit PLC",
          "tooltip" : "Edit PLC program with PLCOpenEditor",
-         "method" : _EditPLC},
+         "method" : "_EditPLC"},
         {"bitmap" : os.path.join("images", "Build"),
          "name" : "Build",
          "tooltip" : "Build project into build folder",
-         "method" : _build},
+         "method" : "_build"},
         {"bitmap" : os.path.join("images", "Clean"),
          "name" : "Clean",
          "tooltip" : "Clean project build folder",
-         "method" : _Clean},
+         "method" : "_Clean"},
         {"bitmap" : os.path.join("images", "Run"),
          "name" : "Run",
          "tooltip" : "Run PLC from build folder",
-         "method" : _Run},
+         "method" : "_Run"},
+        {"bitmap" : os.path.join("images", "Stop"),
+         "name" : "Stop",
+         "tooltip" : "Stop Running PLC",
+         "method" : "_Stop"},
         {"bitmap" : os.path.join("images", "ShowIECcode"),
          "name" : "Show IEC code",
          "tooltip" : "Show IEC code generated by PLCGenerator",
-         "method" : _showIECcode},
+         "method" : "_showIECcode"},
         {"name" : "Edit raw IEC code",
          "tooltip" : "Edit raw IEC code added to code generated by PLCGenerator",
-         "method" : _editIECrawcode}
+         "method" : "_editIECrawcode"}
     ]
 
--- a/plugins/c_ext/c_ext.py	Mon Feb 18 18:34:24 2008 +0100
+++ b/plugins/c_ext/c_ext.py	Thu Feb 21 11:42:33 2008 +0100
@@ -103,10 +103,10 @@
     PluginMethods = [
         {"name" : "Edit C File", 
          "tooltip" : "Edit C File",
-         "method" : _OpenView},
+         "method" : "_OpenView"},
         {"name" : "Import C File", 
          "tooltip" : "Import C File",
-         "method" : _OpenView}
+         "method" : "_OpenView"}
     ]
 
     def SaveCView(self, name):
--- a/plugins/canfestival/canfestival.py	Mon Feb 18 18:34:24 2008 +0100
+++ b/plugins/canfestival/canfestival.py	Thu Feb 21 11:42:33 2008 +0100
@@ -75,10 +75,10 @@
         {"bitmap" : os.path.join("images", "NetworkEdit"),
          "name" : "Edit network", 
          "tooltip" : "Edit CanOpen Network with NetworkEdit",
-         "method" : _OpenView},
+         "method" : "_OpenView"},
         {"name" : "Show Master", 
          "tooltip" : "Show Master generated by config_utils",
-         "method" : _ShowMasterGenerated}
+         "method" : "_ShowMasterGenerated"}
     ]
 
     def OnPlugClose(self):
--- a/plugins/svgui/svgui.py	Mon Feb 18 18:34:24 2008 +0100
+++ b/plugins/svgui/svgui.py	Thu Feb 21 11:42:33 2008 +0100
@@ -123,15 +123,15 @@
         {"bitmap" : os.path.join("images","HMIEditor"),
          "name" : "HMI Editor",
          "tooltip" : "HMI Editor",
-         "method" : _OpenView},
+         "method" : "_OpenView"},
         {"bitmap" : os.path.join("images","ImportSVG"),
          "name" : "Import SVG",
          "tooltip" : "Import SVG",
-         "method" : _OpenView},
+         "method" : "_OpenView"},
         {"bitmap" : os.path.join("images","ImportDEF"),
          "name" : "Import DEF",
          "tooltip" : "Import DEF",
-         "method" : _OpenView},
+         "method" : "_OpenView"},
     ]
     
     def OnPlugSave(self):