Adding support for declaring PluginRoot outside of Beremiz
authorlaurent
Thu, 15 Oct 2009 10:11:07 +0200
changeset 417 a895ae50b737
parent 416 3b3f7f5a8e40
child 419 1cdae505be9e
Adding support for declaring PluginRoot outside of Beremiz
Beremiz.py
plugger.py
--- a/Beremiz.py	Fri Oct 09 17:52:00 2009 +0200
+++ b/Beremiz.py	Thu Oct 15 10:11:07 2009 +0200
@@ -377,7 +377,7 @@
         
         self._init_beremiz_sizers()
 
-    def __init__(self, parent, projectOpen, buildpath, debug=True):
+    def __init__(self, parent, projectOpen=None, buildpath=None, plugin_root=None, debug=True):
         IDEFrame.__init__(self, parent, debug)
         self.Config = wx.ConfigBase.Get()
         
@@ -403,8 +403,11 @@
                 self.ResetView()
                 self.ShowErrorMessage(result)
         else:
-            self.PluginRoot = None
-            self.Controler = None
+            self.PluginRoot = plugin_root
+            self.Controler = plugin_root
+            if plugin_root is not None:
+                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self.RefreshAll()
         
         # Add beremiz's icon in top left corner of the frame
         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
--- a/plugger.py	Fri Oct 09 17:52:00 2009 +0200
+++ b/plugger.py	Thu Oct 15 10:11:07 2009 +0200
@@ -485,7 +485,7 @@
         # Ask to his parent to remove it
         self.PlugParent._doRemoveChild(self)
 
-    def PlugAddChild(self, PlugName, PlugType):
+    def PlugAddChild(self, PlugName, PlugType, IEC_Channel=0):
         """
         Create the plugins that may be added as child to this node self
         @param PlugType: string desining the plugin class name (get name from PlugChildsTypes)
@@ -554,7 +554,7 @@
                     # If plugin do not have corresponding file/dirs - they will be created on Save
                     _self.PlugMakeDir()
                     # Find an IEC number
-                    _self.FindNewIEC_Channel(0)
+                    _self.FindNewIEC_Channel(IEC_Channel)
                     # Call the plugin real __init__
                     if getattr(PlugClass, "__init__", None):
                         PlugClass.__init__(_self)
@@ -742,8 +742,7 @@
         PLCControler.__init__(self)
 
         self.MandatoryParams = None
-        self.AppFrame = frame
-        self.logger = logger
+        self.SetAppFrame(frame, logger)
         self._builder = None
         self._connector = None
         self.Deleting = False
@@ -755,11 +754,6 @@
         self.DebugTimer=None
         self.ResetIECProgramsAndVariables()
         
-        # Timer to pull PLC status
-        ID_STATUSTIMER = wx.NewId()
-        self.StatusTimer = wx.Timer(self.AppFrame, ID_STATUSTIMER)
-        self.AppFrame.Bind(wx.EVT_TIMER, self.PullPLCStatusProc, self.StatusTimer)
-        
         #This method are not called here... but in NewProject and OpenProject
         #self._AddParamsMembers()
         #self.PluggedChilds = {}
@@ -785,6 +779,25 @@
     def __del__(self):
         self.Deleting = True
 
+    def SetAppFrame(self, frame, logger):
+        self.AppFrame = frame
+        self.logger = logger
+        self.StatusTimer = None
+        
+        if frame is not None:
+            # Timer to pull PLC status
+            ID_STATUSTIMER = wx.NewId()
+            self.StatusTimer = wx.Timer(self.AppFrame, ID_STATUSTIMER)
+            self.AppFrame.Bind(wx.EVT_TIMER, self.PullPLCStatusProc, self.StatusTimer)
+
+    def ResetAppFrame(self, logger):
+        if self.AppFrame is not None:
+            self.AppFrame.Unbind(wx.EVT_TIMER, self.StatusTimer)
+            self.StatusTimer = None
+            self.AppFrame = None
+        
+        self.logger = logger
+
     def PluginLibraryFilePath(self):
         return os.path.join(os.path.split(__file__)[0], "pous.xml")
 
@@ -910,8 +923,8 @@
     
     def CloseProject(self):
         self.ClearPluggedChilds()
-        self.AppFrame.Unbind(wx.EVT_TIMER, self.StatusTimer)
-    
+        self.ResetAppFrame(None)
+        
     def SaveProject(self):
         if not self.SaveXMLFile():
             self.SaveXMLFile(os.path.join(self.ProjectPath, 'plc.xml'))