# HG changeset patch # User Laurent Bessard # Date 1362594238 -3600 # Node ID 8a339cd61cb4b7a5a614d895967f0306d55cd48a # Parent dc1318160073827e6ce7bc23d1de2e5f47056e8b Added support for extension custom contextual add menu diff -r dc1318160073 -r 8a339cd61cb4 Beremiz.py --- a/Beremiz.py Wed Mar 06 10:58:15 2013 +0100 +++ b/Beremiz.py Wed Mar 06 19:23:58 2013 +0100 @@ -110,7 +110,7 @@ splash.SetText(text=updateinfo) wx.Yield() -from util.TranslationCatalogs import AddCatalog, locale +from util.TranslationCatalogs import AddCatalog from util.BitmapLibrary import AddBitmapFolder, GetBitmap AddCatalog(os.path.join(CWD, "locale")) @@ -120,7 +120,6 @@ # Import module for internationalization import gettext - __builtin__.__dict__['loc'] = locale __builtin__.__dict__['_'] = wx.GetTranslation # Load extensions @@ -942,11 +941,18 @@ confnode_menu = wx.Menu(title='') confnode = item_infos["confnode"] - if confnode is not None and len(confnode.CTNChildrenTypes) > 0: - for name, XSDClass, help in confnode.CTNChildrenTypes: - new_id = wx.NewId() - confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Add") + " " + name) - self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), id=new_id) + if confnode is not None: + menu_items = confnode.GetContextualMenuItems() + if menu_items is not None: + for text, help, callback in menu_items: + new_id = wx.NewId() + confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=text) + self.Bind(wx.EVT_MENU, callback, id=new_id) + else: + for name, XSDClass, help in confnode.CTNChildrenTypes: + new_id = wx.NewId() + confnode_menu.Append(help=help, id=new_id, kind=wx.ITEM_NORMAL, text=_("Add") + " " + name) + self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), id=new_id) new_id = wx.NewId() AppendMenu(confnode_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Delete")) diff -r dc1318160073 -r 8a339cd61cb4 ConfigTreeNode.py --- a/ConfigTreeNode.py Wed Mar 06 10:58:15 2013 +0100 +++ b/ConfigTreeNode.py Wed Mar 06 19:23:58 2013 +0100 @@ -422,6 +422,9 @@ self.BaseParams.setIEC_Channel(res) return res + def GetContextualMenuItems(self): + return None + def _OpenView(self, name=None, onlyopened=False): if self.EditorType is not None: app_frame = self.GetCTRoot().AppFrame diff -r dc1318160073 -r 8a339cd61cb4 PLCOpenEditor.py --- a/PLCOpenEditor.py Wed Mar 06 10:58:15 2013 +0100 +++ b/PLCOpenEditor.py Wed Mar 06 19:23:58 2013 +0100 @@ -64,7 +64,7 @@ from docutil import * -from util.TranslationCatalogs import AddCatalog, locale +from util.TranslationCatalogs import AddCatalog from util.BitmapLibrary import AddBitmapFolder, GetBitmap AddCatalog(os.path.join(CWD, "locale")) @@ -75,7 +75,6 @@ import gettext import __builtin__ - __builtin__.__dict__['loc'] = locale __builtin__.__dict__['_'] = wx.GetTranslation from IDEFrame import IDEFrame, AppendMenu