VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId) wx.NewID_abuse_fix
authorEdouard Tisserant
Mon, 25 Mar 2019 14:59:54 +0100
branchwx.NewID_abuse_fix
changeset 2554 45d4f9a84c60
parent 2553 4b967831374f
child 2555 5dce99e69027
VariablePanel's menu do not waste Wx IDs anymore (directly binds wx objects rather than crating new ID wit wx.NewId)
controls/VariablePanel.py
--- a/controls/VariablePanel.py	Tue Mar 26 09:48:45 2019 +0100
+++ b/controls/VariablePanel.py	Mon Mar 25 14:59:54 2019 +0100
@@ -837,22 +837,20 @@
         # build a submenu containing standard IEC types
         base_menu = wx.Menu(title='')
         for base_type in self.Controler.GetBaseTypes():
-            new_id = wx.NewId()
-            base_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type)
-            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
-
-        type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu)
+            item = base_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=base_type)
+            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), item)
+
+        type_menu.AppendMenu(wx.ID_ANY, _("Base Types"), base_menu)
 
     def BuildUserTypesMenu(self, type_menu):
         # build a submenu containing user-defined types
         datatype_menu = wx.Menu(title='')
         datatypes = self.Controler.GetDataTypes(basetypes=False, confnodetypes=False)
         for datatype in datatypes:
-            new_id = wx.NewId()
-            datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
-            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
-
-        type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu)
+            item = datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype)
+            self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item)
+
+        type_menu.AppendMenu(wx.ID_ANY, _("User Data Types"), datatype_menu)
 
     def BuildLibsTypesMenu(self, type_menu):
         for category in self.Controler.GetConfNodeDataTypes():
@@ -860,11 +858,10 @@
                 # build a submenu containing confnode types
                 confnode_datatype_menu = wx.Menu(title='')
                 for datatype in category["list"]:
-                    new_id = wx.NewId()
-                    confnode_datatype_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
-                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
-
-                type_menu.AppendMenu(wx.NewId(), category["name"], confnode_datatype_menu)
+                    item = confnode_datatype_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=datatype)
+                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), item)
+
+                type_menu.AppendMenu(wx.ID_ANY, category["name"], confnode_datatype_menu)
 
     def BuildProjectTypesMenu(self, type_menu, classtype):
         # build a submenu containing function block types
@@ -875,16 +872,14 @@
             functionblock_menu = wx.Menu(title='')
             fbtypes = self.Controler.GetFunctionBlockTypes(self.TagName)
             for functionblock_type in fbtypes:
-                new_id = wx.NewId()
-                functionblock_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
-                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
-
-            type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu)
+                item = functionblock_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=functionblock_type)
+                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), item)
+
+            type_menu.AppendMenu(wx.ID_ANY, _("Function Block Types"), functionblock_menu)
 
     def BuildArrayTypesMenu(self, type_menu):
-        new_id = wx.NewId()
-        type_menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array"))
-        self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, id=new_id)
+        item = type_menu.Append(wx.ID_ANY, help='', kind=wx.ITEM_NORMAL, text=_("Array"))
+        self.Bind(wx.EVT_MENU, self.VariableArrayTypeFunction, item)
 
     def OnVariablesGridEditorShown(self, event):
         row, col = event.GetRow(), event.GetCol()