Adding search field for finding function or function block in library tree
authorlaurent
Thu, 03 May 2012 19:02:34 +0200
changeset 716 180e4a7d945c
parent 715 135566ab0807
child 717 1c23952dbde1
Adding search field for finding function or function block in library tree
Beremiz.py
plugger.py
--- a/Beremiz.py	Fri Apr 27 02:07:47 2012 +0200
+++ b/Beremiz.py	Thu May 03 19:02:34 2012 +0200
@@ -146,7 +146,7 @@
 import TextCtrlAutoComplete, cPickle
 from BrowseValuesLibraryDialog import BrowseValuesLibraryDialog
 import types, time, re, platform, time, traceback, commands
-from plugger import PluginsRoot, MATIEC_ERROR_MODEL
+from plugger import PluginsRoot, MiniTextControler, MATIEC_ERROR_MODEL
 from wxPopen import ProcessLogger
 
 from docutils import *
@@ -559,6 +559,7 @@
             self.Controler = self.PluginRoot
             result = self.PluginRoot.LoadProject(projectOpen, buildpath)
             if not result:
+                self.LibraryPanel.SetControler(self.Controler)
                 self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
                 self.RefreshAll()
@@ -569,6 +570,7 @@
             self.PluginRoot = plugin_root
             self.Controler = plugin_root
             if plugin_root is not None:
+                self.LibraryPanel.SetControler(self.Controler)
                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
                 self.RefreshAll()
         if self.EnableDebug:
@@ -673,13 +675,19 @@
                                  ConfigurationEditor, 
                                  DataTypeEditor))):
             return ("plugin", tab.Controler.PlugFullName())
+        elif (isinstance(tab, TextViewer) and 
+              (tab.Controler is None or isinstance(tab.Controler, MiniTextControler))):
+            return ("plugin", None, tab.GetInstancePath())
         else:
             return IDEFrame.GetTabInfos(self, tab)
     
     def LoadTab(self, notebook, page_infos):
         if page_infos[0] == "plugin":
-            plugin = self.PluginRoot.GetChildByName(page_infos[1])
-            return notebook.GetPageIndex(plugin._OpenView())
+            if page_infos[1] is None:
+                plugin = self.PluginRoot
+            else:
+                plugin = self.PluginRoot.GetChildByName(page_infos[1])
+            return notebook.GetPageIndex(plugin._OpenView(*page_infos[2:]))
         else:
             return IDEFrame.LoadTab(self, notebook, page_infos)
     
@@ -1673,6 +1681,7 @@
             if not result:
                 self.PluginRoot = plugin_root
                 self.Controler = self.PluginRoot
+                self.LibraryPanel.SetControler(self.Controler)
                 self.RefreshConfigRecentProjects(projectpath)
                 if self.EnableDebug:
                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
@@ -1707,6 +1716,7 @@
             self.Controler = self.PluginRoot
             result = self.PluginRoot.LoadProject(projectpath)
             if not result:
+                self.LibraryPanel.SetControler(self.Controler)
                 self.RefreshConfigRecentProjects(projectpath)
                 if self.EnableDebug:
                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
--- a/plugger.py	Fri Apr 27 02:07:47 2012 +0200
+++ b/plugger.py	Thu May 03 19:02:34 2012 +0200
@@ -35,7 +35,10 @@
     
     def __init__(self, filepath):
         self.FilePath = filepath
-        
+    
+    def PlugFullName(self):
+        return ""
+    
     def SetEditedElementText(self, tagname, text):
         file = open(self.FilePath, "w")
         file.write(text)
@@ -493,7 +496,7 @@
         self.BaseParams.setIEC_Channel(res)
         return res
 
-    def _OpenView(self):
+    def _OpenView(self, name=None):
         if self.EditorType is not None and self._View is None:
             app_frame = self.GetPlugRoot().AppFrame
             
@@ -1018,7 +1021,7 @@
             self.ClearPluginTypes()
             self.AddPluginTypesList(self.PluginsTypesFactory())
         if self.AppFrame is not None:
-            self.AppFrame.RefreshLibraryTree()
+            self.AppFrame.RefreshLibraryPanel()
             self.AppFrame.RefreshEditor()
     
     # Update a PLCOpenEditor Pou variable location
@@ -1555,31 +1558,44 @@
                 self.AppFrame.ShowError(infos, start, end)
 
     def _showIECcode(self):
-        plc_file = self._getIECcodepath()
-        
-        IEC_code_viewer = TextViewer(self.AppFrame.TabsOpened, "", None, None, instancepath="IEC code")
-        #IEC_code_viewer.Enable(False)
-        IEC_code_viewer.SetTextSyntax("ALL")
-        IEC_code_viewer.SetKeywords(IEC_KEYWORDS)
-        try:
-            text = file(plc_file).read()
-        except:
-            text = '(* No IEC code have been generated at that time ! *)'
-        IEC_code_viewer.SetText(text = text)
-        IEC_code_viewer.SetIcon(self.AppFrame.GenerateBitmap("ST"))
+        self._OpenView("IEC code")
+
+    def _editIECrawcode(self):
+        self._OpenView("IEC raw code")
+
+    def _OpenView(self, name=None):
+        if name == "IEC code":
+            plc_file = self._getIECcodepath()
+        
+            IEC_code_viewer = TextViewer(self.AppFrame.TabsOpened, "", None, None, instancepath=name)
+            #IEC_code_viewer.Enable(False)
+            IEC_code_viewer.SetTextSyntax("ALL")
+            IEC_code_viewer.SetKeywords(IEC_KEYWORDS)
+            try:
+                text = file(plc_file).read()
+            except:
+                text = '(* No IEC code have been generated at that time ! *)'
+            IEC_code_viewer.SetText(text = text)
+            IEC_code_viewer.SetIcon(self.AppFrame.GenerateBitmap("ST"))
+                
+            self.AppFrame.EditProjectElement(IEC_code_viewer, name)
             
-        self.AppFrame.EditProjectElement(IEC_code_viewer, "IEC code")
-        
-    def _editIECrawcode(self):
-        controler = MiniTextControler(self._getIECrawcodepath())
-        IEC_raw_code_viewer = TextViewer(self.AppFrame.TabsOpened, "", None, controler, instancepath="IEC raw code")
-        #IEC_raw_code_viewer.Enable(False)
-        IEC_raw_code_viewer.SetTextSyntax("ALL")
-        IEC_raw_code_viewer.SetKeywords(IEC_KEYWORDS)
-        IEC_raw_code_viewer.RefreshView()
-        IEC_raw_code_viewer.SetIcon(self.AppFrame.GenerateBitmap("ST"))
-            
-        self.AppFrame.EditProjectElement(IEC_raw_code_viewer, "IEC raw code")
+            return IEC_code_viewer
+        
+        elif name == "IEC raw code":
+            controler = MiniTextControler(self._getIECrawcodepath())
+            IEC_raw_code_viewer = TextViewer(self.AppFrame.TabsOpened, "", None, controler, instancepath=name)
+            #IEC_raw_code_viewer.Enable(False)
+            IEC_raw_code_viewer.SetTextSyntax("ALL")
+            IEC_raw_code_viewer.SetKeywords(IEC_KEYWORDS)
+            IEC_raw_code_viewer.RefreshView()
+            IEC_raw_code_viewer.SetIcon(self.AppFrame.GenerateBitmap("ST"))
+                
+            self.AppFrame.EditProjectElement(IEC_raw_code_viewer, name)
+
+            return IEC_raw_code_viewer
+        
+        return None
 
     def _Clean(self):
         if os.path.isdir(os.path.join(self._getBuildPath())):