Added support for left panel add menu with multiple levels
authorlaurent
Fri, 02 Aug 2013 08:58:09 +0900
changeset 1282 f427352f9727
parent 1281 47131e3388f4
child 1283 f3cfe1ff917e
Added support for left panel add menu with multiple levels
Beremiz.py
ProjectController.py
editors/ConfTreeNodeEditor.py
--- a/Beremiz.py	Fri Aug 02 08:55:45 2013 +0900
+++ b/Beremiz.py	Fri Aug 02 08:58:09 2013 +0900
@@ -150,7 +150,7 @@
 from controls.CustomStyledTextCtrl import CustomStyledTextCtrl
 
 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
-from ProjectController import ProjectController, MATIEC_ERROR_MODEL, ITEM_CONFNODE
+from ProjectController import ProjectController, GetAddMenuItems, MATIEC_ERROR_MODEL, ITEM_CONFNODE
 
 
 MAX_RECENT_PROJECTS = 10
@@ -330,6 +330,19 @@
                                (wx.ID_SAVEAS, "saveas", _(u'Save As...'), None),
                                (wx.ID_PRINT, "print", _(u'Print'), None)])
     
+    def _RecursiveAddMenuItems(self, menu, items):
+        for name, text, help, children in items:
+            new_id = wx.NewId()
+            if len(children) > 0:
+                new_menu = wx.Menu(title='')
+                menu.AppendMenu(new_id, text, new_menu)
+                self._RecursiveAddMenuItems(new_menu, children)
+            else:
+                AppendMenu(menu, help=help, id=new_id, 
+                       kind=wx.ITEM_NORMAL, text=text)
+                self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name), 
+                          id=new_id)    
+    
     def _init_coll_AddMenu_Items(self, parent):
         IDEFrame._init_coll_AddMenu_Items(self, parent, False)
         
@@ -339,11 +352,7 @@
         #          kind=wx.ITEM_NORMAL, text=_(u'&Resource'))
         #self.Bind(wx.EVT_MENU, self.AddResourceMenu, id=new_id)
         
-        for name, XSDClass, help in ProjectController.CTNChildrenTypes:
-            new_id = wx.NewId()
-            AppendMenu(parent, help='', id=new_id, 
-                       kind=wx.ITEM_NORMAL, text=help)
-            self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name), id=new_id)
+        self._RecursiveAddMenuItems(parent, GetAddMenuItems())
     
     def _init_coll_HelpMenu_Items(self, parent):
         parent.Append(help='', id=wx.ID_ABOUT,
--- a/ProjectController.py	Fri Aug 02 08:55:45 2013 +0900
+++ b/ProjectController.py	Fri Aug 02 08:58:09 2013 +0900
@@ -7,6 +7,7 @@
 import shutil
 import wx
 import re, tempfile
+from types import ListType
 from threading import Timer, Lock, Thread
 from time import localtime
 from datetime import datetime
@@ -37,6 +38,28 @@
 
 ITEM_CONFNODE = 25
 
+def ExtractChildrenTypesFromCatalog(catalog):
+    children_types = []
+    for n,d,h,c in catalog:
+        if isinstance(c, ListType):
+            children_types.extend(ExtractChildrenTypesFromCatalog(c))
+        else:
+            children_types.append((n, GetClassImporter(c), d))
+    return children_types
+
+def ExtractMenuItemsFromCatalog(catalog):
+    menu_items = []
+    for n,d,h,c in catalog:
+        if isinstance(c, ListType):
+            children = ExtractMenuItemsFromCatalog(c)
+        else:
+            children = []
+        menu_items.append((n, d, h, children))
+    return menu_items
+
+def GetAddMenuItems():
+    return ExtractMenuItemsFromCatalog(features.catalog)
+
 class ProjectController(ConfigTreeNode, PLCControler):
     """
     This class define Root object of the confnode tree. 
@@ -50,7 +73,7 @@
     """
 
     # For root object, available Children Types are modules of the confnode packages.
-    CTNChildrenTypes =  [(n, GetClassImporter(c), d) for n,d,h,c in features.catalog]
+    CTNChildrenTypes = ExtractChildrenTypesFromCatalog(features.catalog)
 
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
@@ -116,6 +139,11 @@
         # copy ConfNodeMethods so that it can be later customized
         self.StatusMethods = [dic.copy() for dic in self.StatusMethods]
 
+    def __del__(self):
+        if self.DebugTimer:
+            self.DebugTimer.cancel()
+        self.KillDebugThread()
+    
     def LoadLibraries(self):
         self.Libraries = []
         TypeStack=[]
@@ -124,11 +152,6 @@
                 Lib = GetClassImporter(clsname)()(self, libname, TypeStack)
                 TypeStack.append(Lib.GetTypes())
                 self.Libraries.append(Lib)
-
-    def __del__(self):
-        if self.DebugTimer:
-            self.DebugTimer.cancel()
-        self.KillDebugThread()
     
     def SetAppFrame(self, frame, logger):
         self.AppFrame = frame
--- a/editors/ConfTreeNodeEditor.py	Fri Aug 02 08:55:45 2013 +0900
+++ b/editors/ConfTreeNodeEditor.py	Fri Aug 02 08:58:09 2013 +0900
@@ -316,7 +316,11 @@
             else:
                 element_path = element_infos["name"]
             if element_infos["type"] == "element":
-                label = element_infos["name"]
+                name = element_infos["name"]
+                value = element_infos["value"]
+                label = _(name)
+                if value is not None:
+                    label += " - %s" % _(value)
                 staticbox = wx.StaticBox(self.ParamsEditor, 
                       label=_(label), size=wx.Size(10, 0))
                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)