refactoring
authorlaurent
Fri, 18 May 2012 18:50:49 +0200
changeset 730 4480b7da6bea
parent 729 25054c592dc4
child 731 4fc681ed0c61
refactoring
Beremiz.py
LPCBeremiz.py
ProjectController.py
util/__init__.py
--- a/Beremiz.py	Sat May 12 12:11:42 2012 +0200
+++ b/Beremiz.py	Fri May 18 18:50:49 2012 +0200
@@ -147,11 +147,11 @@
 from util.BrowseValuesLibraryDialog import BrowseValuesLibraryDialog
 import types, time, re, platform, time, traceback, commands
 from ProjectController import ProjectController, MATIEC_ERROR_MODEL
-from util import MiniTextControler
+from util.MiniTextControler import MiniTextControler
 from util.ProcessLogger import ProcessLogger
 
 from docutil import OpenHtmlFrame
-from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING, PAGETITLES, USE_AUI
+from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES, USE_AUI
 from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor
 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
 
@@ -558,8 +558,9 @@
             result = self.CTR.LoadProject(projectOpen, buildpath)
             if not result:
                 self.LibraryPanel.SetControler(self.Controler)
+                self.PouInstanceVariablesPanel.SetController(self.Controler)
                 self.RefreshConfigRecentProjects(os.path.abspath(projectOpen))
-                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
                 self.RefreshAll()
             else:
                 self.ResetView()
@@ -569,7 +570,8 @@
             self.Controler = ctr
             if ctr is not None:
                 self.LibraryPanel.SetControler(self.Controler)
-                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self.PouInstanceVariablesPanel.SetController(self.Controler)
+                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
                 self.RefreshAll()
         if self.EnableDebug:
             self.DebugVariablePanel.SetDataProducer(self.CTR)
@@ -773,18 +775,22 @@
             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
     
     def RefreshRecentProjectsMenu(self):
-        for i in xrange(self.RecentProjectsMenu.GetMenuItemCount()):
-            item = self.RecentProjectsMenu.FindItemByPosition(0)
-            self.RecentProjectsMenu.Delete(item.GetId())
-        
         recent_projects = cPickle.loads(str(self.Config.Read("RecentProjects", cPickle.dumps([]))))
         self.FileMenu.Enable(ID_FILEMENURECENTPROJECTS, len(recent_projects) > 0)
         for idx, projectpath in enumerate(recent_projects):
-            id = wx.NewId()
-            AppendMenu(self.RecentProjectsMenu, help='', id=id, 
-                       kind=wx.ITEM_NORMAL, text="%d: %s" % (idx + 1, projectpath))
+            text = u'%d: %s' % (idx + 1, projectpath)
+            
+            if idx < self.RecentProjectsMenu.GetMenuItemCount():
+                item = self.RecentProjectsMenu.FindItemByPosition(idx)
+                id = item.GetId()
+                item.SetItemLabel(text)
+                self.Disconnect(id, id, wx.EVT_BUTTON._getEvtType())
+            else:
+                id = wx.NewId()
+                AppendMenu(self.RecentProjectsMenu, help='', id=id, 
+                           kind=wx.ITEM_NORMAL, text=text)
             self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), id=id)
-    
+        
     def GenerateOpenRecentProjectFunction(self, projectpath):
         def OpenRecentProject(event):
             if self.CTR is not None and not self.CheckSaveBeforeClosing():
@@ -1680,10 +1686,11 @@
                 self.CTR = ctr
                 self.Controler = self.CTR
                 self.LibraryPanel.SetControler(self.Controler)
+                self.PouInstanceVariablesPanel.SetController(self.Controler)
                 self.RefreshConfigRecentProjects(projectpath)
                 if self.EnableDebug:
                     self.DebugVariablePanel.SetDataProducer(self.CTR)
-                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
                 self.RefreshAll()
             else:
                 self.ResetView()
@@ -1715,11 +1722,12 @@
             result = self.CTR.LoadProject(projectpath)
             if not result:
                 self.LibraryPanel.SetControler(self.Controler)
+                self.PouInstanceVariablesPanel.SetController(self.Controler)
                 self.RefreshConfigRecentProjects(projectpath)
                 if self.EnableDebug:
                     self.DebugVariablePanel.SetDataProducer(self.CTR)
                 self.LoadProjectOrganization()
-                self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self._Refresh(PROJECTTREE, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
                 self.RefreshAll()
             else:
                 self.ResetView()
--- a/LPCBeremiz.py	Sat May 12 12:11:42 2012 +0200
+++ b/LPCBeremiz.py	Fri May 18 18:50:49 2012 +0200
@@ -954,7 +954,6 @@
                 self.UnsubscribeAllDebugIECVariable()
                 self.ProgramTransferred()
                 if self.AppFrame is not None:
-                    self.AppFrame.RefreshInstancesTree()
                     self.AppFrame.CloseObsoleteDebugTabs()
                 self.logger.write(_("Transfer completed successfully.\n"))
             else:
@@ -1139,7 +1138,7 @@
             if new_values != old_values:
                 self.Controler.SetProjectProperties(None, new_values)
                 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
-                              TYPESTREE, INSTANCESTREE, SCALING)
+                              PROJECTTREE, POUINSTANCEVARIABLESPANEL, SCALING)
         dialog.Destroy()
 
     def RefreshFileMenu(self):
@@ -1450,7 +1449,7 @@
         def Refresh(self):
             global frame
             if frame is not None:
-                frame._Refresh(TITLE, INSTANCESTREE, FILEMENU, EDITMENU)
+                frame._Refresh(TITLE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
                 frame.RefreshEditor()
                 frame.RefreshAll()
         
--- a/ProjectController.py	Sat May 12 12:11:42 2012 +0200
+++ b/ProjectController.py	Fri May 18 18:50:49 2012 +0200
@@ -59,10 +59,17 @@
                 </xsd:choice>
               </xsd:complexType>
             </xsd:element>
+            <xsd:element name="Libraries" minOccurs="0">
+              <xsd:complexType>
+              """+"\n".join(['<xsd:attribute name="Enable_'+
+                             lib.rsplit('.',1)[-1]+
+                             '" type="xsd:boolean" use="optional" default="true"/>' 
+                             for lib in features.libraries])+"""
+              </xsd:complexType>
+            </xsd:element>
           </xsd:sequence>
           <xsd:attribute name="URI_location" type="xsd:string" use="optional" default=""/>
           <xsd:attribute name="Disable_Extensions" type="xsd:boolean" use="optional" default="false"/>
-          """+"\n".join(['<xsd:attribute name="Enable_'+lib.rsplit('.',1)[-1]+'" type="xsd:boolean" use="optional" default="true"/>' for lib in features.libraries])+"""
         </xsd:complexType>
       </xsd:element>
     </xsd:schema>
@@ -106,7 +113,7 @@
         self.Libraries = []
         TypeStack=[]
         for clsname in features.libraries:
-            if getattr(self.BeremizRoot, "Enable_"+clsname.rsplit('.',1)[-1]):
+            if self.BeremizRoot.Libraries is None or getattr(self.BeremizRoot.Libraries, "Enable_"+clsname.rsplit('.',1)[-1]):
                 Lib = GetClassImporter(clsname)()(TypeStack)
                 TypeStack.append(Lib.GetTypes())
                 self.Libraries.append(Lib)
@@ -348,7 +355,7 @@
         self.BufferProject()
         if self.AppFrame is not None:
             self.AppFrame.RefreshTitle()
-            self.AppFrame.RefreshInstancesTree()
+            self.AppFrame.RefreshPouInstanceVariablesPanel()
             self.AppFrame.RefreshFileMenu()
             self.AppFrame.RefreshEditMenu()
             self.AppFrame.RefreshEditor()
@@ -1337,7 +1344,6 @@
                     self.UnsubscribeAllDebugIECVariable()
                     self.ProgramTransferred()
                     if self.AppFrame is not None:
-                        self.AppFrame.RefreshInstancesTree()
                         self.AppFrame.CloseObsoleteDebugTabs()
                     self.logger.write(_("Transfer completed successfully.\n"))
                 else:
--- a/util/__init__.py	Sat May 12 12:11:42 2012 +0200
+++ b/util/__init__.py	Fri May 18 18:50:49 2012 +0200
@@ -3,5 +3,6 @@
 import ProcessLogger
 import Zeroconf
 import discovery
+import MiniTextControler
 from misc import *