Merged
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 07 Apr 2019 16:23:49 +0200
changeset 2578 eed31489c909
parent 2577 f88eef34a523 (current diff)
parent 2576 c08bbfe7bbd4 (diff)
child 2579 8fb5c6eddc72
Merged
--- a/BeremizIDE.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/BeremizIDE.py	Sun Apr 07 16:23:49 2019 +0200
@@ -276,17 +276,14 @@
                                (wx.ID_PRINT, "print", _(u'Print'), None)])
 
     def _RecursiveAddMenuItems(self, menu, items):
-        for name, text, help, children in items:
-            new_id = wx.NewId()
+        for name, text, helpstr, children in items:
             if len(children) > 0:
                 new_menu = wx.Menu(title='')
-                menu.AppendMenu(new_id, text, new_menu)
+                menu.AppendMenu(wx.ID_ANY, 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)
+                item = menu.Append(wx.ID_ANY, text, helpstr)
+                self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name), item)
 
     def _init_coll_AddMenu_Items(self, parent):
         IDEFrame._init_coll_AddMenu_Items(self, parent, False)
@@ -299,9 +296,8 @@
                 _(u'Community support'),
                 wx.OK | wx.ICON_INFORMATION)
 
-        id = wx.NewId()
-        parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
-        self.Bind(wx.EVT_MENU, handler, id=id)
+        item = parent.Append(wx.ID_ANY, _(u'Community support'), '')
+        self.Bind(wx.EVT_MENU, handler, item)
 
         parent.Append(help='', id=wx.ID_ABOUT,
                       kind=wx.ITEM_NORMAL, text=_(u'About'))
@@ -686,7 +682,7 @@
         except Exception:
             recent_projects = []
 
-        while self.RecentProjectsMenu.GetMenuItemCount() > len(recent_projects):
+        while self.RecentProjectsMenu.GetMenuItemCount() > 0:
             item = self.RecentProjectsMenu.FindItemByPosition(0)
             self.RecentProjectsMenu.RemoveItem(item)
 
@@ -694,16 +690,8 @@
         for idx, projectpath in enumerate(recent_projects):
             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)
+            item = self.RecentProjectsMenu.Append(wx.ID_ANY, text, '')
+            self.Bind(wx.EVT_MENU, self.GenerateOpenRecentProjectFunction(projectpath), item)
 
     def GenerateOpenRecentProjectFunction(self, projectpath):
         def OpenRecentProject(event):
@@ -743,11 +731,10 @@
 
             for confnode_method in self.CTR.StatusMethods:
                 if "method" in confnode_method and confnode_method.get("shown", True):
-                    id = wx.NewId()
-                    StatusToolBar.AddSimpleTool(
-                        id, GetBitmap(confnode_method.get("bitmap", "Unknown")),
+                    tool = StatusToolBar.AddSimpleTool(
+                        wx.ID_ANY, GetBitmap(confnode_method.get("bitmap", "Unknown")),
                         confnode_method["tooltip"])
-                    self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), id=id)
+                    self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), tool)
 
             StatusToolBar.Realize()
             self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
@@ -984,20 +971,17 @@
             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)
+                    for text, helpstr, callback in menu_items:
+                        item = confnode_menu.Append(wx.ID_ANY, text, helpstr)
+                        self.Bind(wx.EVT_MENU, callback, item)
                 else:
-                    for name, XSDClass, help in confnode.CTNChildrenTypes:
+                    for name, XSDClass, helpstr in confnode.CTNChildrenTypes:
                         if not hasattr(XSDClass, 'CTNMaxCount') or not confnode.Children.get(name) \
                                 or len(confnode.Children[name]) < XSDClass.CTNMaxCount:
-                            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"))
-            self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), id=new_id)
+                            item = confnode_menu.Append(wx.ID_ANY, _("Add") + " " + name, helpstr)
+                            self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name, confnode), item)
+            item = confnode_menu.Append(wx.ID_ANY, _("Delete"))
+            self.Bind(wx.EVT_MENU, self.GetDeleteMenuFunction(confnode), item)
 
             self.PopupMenu(confnode_menu)
             confnode_menu.Destroy()
--- a/controls/LocationCellEditor.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/controls/LocationCellEditor.py	Sun Apr 07 16:23:49 2019 +0200
@@ -60,6 +60,7 @@
         self.Controller = None
         self.VarType = None
         self.Default = False
+        self.VariableName = None
 
     def __del__(self):
         self.Controller = None
@@ -75,11 +76,16 @@
 
     def SetValue(self, value):
         self.Default = value
+        self.VariableName = None
+        self.VarType = None
         self.Location.SetValue(value)
 
     def GetValue(self):
         return self.Location.GetValue()
 
+    def GetName(self):
+        return self.VariableName
+    
     def OnSize(self, event):
         self.Layout()
 
@@ -118,8 +124,13 @@
                     location = "%M" + location
 
             self.Location.SetValue(location)
+            self.VariableName = infos["var_name"]
             self.VarType = infos["IEC_type"]
 
+            # when user selected something, end editing immediately
+            # so that changes over multiple colums appear
+            wx.CallAfter(self.Parent.Parent.CloseEditControl)
+
         self.Location.SetFocus()
 
     def OnLocationChar(self, event):
@@ -171,8 +182,22 @@
         loc = self.CellControl.GetValue()
         changed = loc != old_loc
         if changed:
+            name = self.CellControl.GetName()
+            if name is not None:
+                message = self.Table.Parent.CheckVariableName(name, row)
+                if message is not None:
+                    wx.CallAfter(self.Table.Parent.ShowErrorMessage, message)
+                    return None
+                old_name  = self.Table.GetValueByName(row, 'Name')
+                self.Table.SetValueByName(row, 'Name', name)
+                self.Table.Parent.OnVariableNameChange(old_name, name)
             self.Table.SetValueByName(row, 'Location', loc)
-            self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType())
+            var_type = self.CellControl.GetVarType()
+            if var_type is not None:
+                self.Table.SetValueByName(row, 'Type', var_type)
+        else:
+            wx.CallAfter(self.Table.Parent.ShowErrorMessage,
+                _("Selected location is identical to previous one"))
         self.CellControl.Disable()
         return changed
 
--- a/controls/VariablePanel.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/controls/VariablePanel.py	Sun Apr 07 16:23:49 2019 +0200
@@ -34,6 +34,7 @@
 from six import string_types
 from six.moves import xrange
 
+
 from plcopen.structures import LOCATIONDATATYPES, TestIdentifier, IEC_KEYWORDS, DefaultType
 from plcopen.VariableInfoCollector import _VariableInfos
 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD, ERROR_HIGHLIGHT
@@ -150,6 +151,7 @@
             return value
 
     def SetValue(self, row, col, value):
+        print("SetValue",row, col, value)
         if col < len(self.colnames):
             colname = self.GetColLabelValue(col, False)
             if colname == "Name":
@@ -788,6 +790,27 @@
         dialog.ShowModal()
         dialog.Destroy()
 
+    def OnVariableNameChange(self, old_name, new_name):
+        """ propagate renaming of variable to the rest of the project """
+        if old_name != "":
+            self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_name, new_name)
+        self.Controler.BufferProject()
+        wx.CallAfter(self.ParentWindow.RefreshView, False)
+        self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+
+    def CheckVariableName(self, value, row):
+        if not TestIdentifier(value):
+            message = _("\"%s\" is not a valid identifier!") % value
+        elif value.upper() in IEC_KEYWORDS:
+            message = _("\"%s\" is a keyword. It can't be used!") % value
+        elif value.upper() in self.PouNames:
+            message = _("A POU named \"%s\" already exists!") % value
+        elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]:
+            message = _("A variable with \"%s\" as name already exists in this pou!") % value
+        else:
+            return None
+        return message
+
     def OnVariablesGridCellChange(self, event):
         row, col = event.GetRow(), event.GetCol()
         colname = self.Table.GetColLabelValue(col, False)
@@ -795,22 +818,11 @@
         message = None
 
         if colname == "Name" and value != "":
-            if not TestIdentifier(value):
-                message = _("\"%s\" is not a valid identifier!") % value
-            elif value.upper() in IEC_KEYWORDS:
-                message = _("\"%s\" is a keyword. It can't be used!") % value
-            elif value.upper() in self.PouNames:
-                message = _("A POU named \"%s\" already exists!") % value
-            elif value.upper() in [var.Name.upper() for var in self.Values if var != self.Table.data[row]]:
-                message = _("A variable with \"%s\" as name already exists in this pou!") % value
-            else:
+            message = self.CheckVariableName(value, row)
+            if message is None:
                 self.SaveValues(False)
                 old_value = self.Table.GetOldValue()
-                if old_value != "":
-                    self.Controler.UpdateEditedElementUsedVariable(self.TagName, old_value, value)
-                self.Controler.BufferProject()
-                wx.CallAfter(self.ParentWindow.RefreshView, False)
-                self.ParentWindow._Refresh(TITLE, FILEMENU, EDITMENU, PAGETITLES, POUINSTANCEVARIABLESPANEL, LIBRARYTREE)
+                self.OnVariableNameChange(old_value, value)
         else:
             self.SaveValues()
             if colname == "Class":
--- a/dialogs/BrowseLocationsDialog.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/dialogs/BrowseLocationsDialog.py	Sun Apr 07 16:23:49 2019 +0200
@@ -71,7 +71,7 @@
 
         self.DIRFILTERCHOICE_OPTIONS = dict(
             [(_(option), filter) for option, filter in GetDirFilterChoiceOptions()])
-        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
+        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=4, vgap=10)
         main_sizer.AddGrowableCol(0)
         main_sizer.AddGrowableRow(1)
 
@@ -91,6 +91,15 @@
         main_sizer.AddWindow(self.LocationsTree, border=20,
                              flag=wx.LEFT | wx.RIGHT | wx.GROW)
 
+        self.RenameCheckBox = wx.CheckBox(self, label=_("Rename variable to signal name"))
+        self.Config = wx.ConfigBase.Get()
+        default_checked = self.Config.Read("RenameVariableOnLocationChange") == "True"
+        self.RenameCheckBox.SetValue(default_checked)
+        self.do_rename = default_checked
+
+        main_sizer.AddWindow(self.RenameCheckBox, border=20,
+                             flag=wx.LEFT | wx.RIGHT | wx.GROW)
+
         button_gridsizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
         button_gridsizer.AddGrowableCol(1)
         button_gridsizer.AddGrowableCol(3)
@@ -217,9 +226,14 @@
 
     def GetValues(self):
         selected = self.LocationsTree.GetSelection()
-        return self.LocationsTree.GetPyData(selected)
+        infos = self.LocationsTree.GetPyData(selected)
+        if not self.do_rename:
+            infos["var_name"] = None
+        return infos
 
     def OnOK(self, event):
+        self.do_rename = self.RenameCheckBox.IsChecked()
+        self.Config.Write("RenameVariableOnLocationChange", str(self.do_rename))
         selected = self.LocationsTree.GetSelection()
         var_infos = None
         if selected.IsOk():
--- a/dialogs/LDPowerRailDialog.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/dialogs/LDPowerRailDialog.py	Sun Apr 07 16:23:49 2019 +0200
@@ -155,7 +155,7 @@
         self.RefreshPreview()
         event.Skip()
 
-    def RefreshPreview(self):
+    def DrawPreview(self):
         """
         Refresh preview panel of graphic element
         Override BlockPreviewDialog function
@@ -166,5 +166,4 @@
                                     self.GetPowerRailType(),
                                     connectors=self.PinNumber.GetValue())
 
-        # Call BlockPreviewDialog function
-        BlockPreviewDialog.RefreshPreview(self)
+        return BlockPreviewDialog.DrawPreview(self)
--- a/editors/Viewer.py	Wed Apr 03 06:31:34 2019 +0000
+++ b/editors/Viewer.py	Sun Apr 07 16:23:49 2019 +0200
@@ -553,7 +553,6 @@
 
     # Add Block Pin Menu items to the given menu
     def AddBlockPinMenuItems(self, menu, connector):
-        # Create menu items
         no_modifier = self.AppendItem(menu,  _(u'No modifier'), self.OnNoModifierMenu, kind=wx.ITEM_RADIO)
         negated = self.AppendItem(menu,  _(u'Negated'), self.OnNegatedMenu, kind=wx.ITEM_RADIO)
         rising_edge = self.AppendItem(menu,  _(u'Rising Edge'), self.OnRisingEdgeMenu, kind=wx.ITEM_RADIO)
@@ -575,7 +574,6 @@
 
     # Add Alignment Menu items to the given menu
     def AddAlignmentMenuItems(self, menu):
-        # Create menu items
         self.AppendItem(menu, _(u'Left'), self.OnAlignLeftMenu)
         self.AppendItem(menu, _(u'Center'), self.OnAlignCenterMenu)
         self.AppendItem(menu, _(u'Right'), self.OnAlignRightMenu)
@@ -586,98 +584,81 @@
 
     # Add Wire Menu items to the given menu
     def AddWireMenuItems(self, menu, delete=False, replace=False):
-        [
-            ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE,
-        ] = [wx.NewId() for dummy in xrange(3)]
-
-        # Create menu items
-        self.AddMenuItems(menu, [
-            (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu),
-            (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu),
-            (ID_REPLACE_WIRE, wx.ITEM_NORMAL, _(u'Replace Wire by connections'), '', self.OnReplaceWireMenu)])
-
-        menu.Enable(ID_DELETE_SEGMENT, delete)
-        menu.Enable(ID_REPLACE_WIRE, replace)
+        self.AppendItem(menu, _(u'Add Wire Segment'), self.OnAddSegmentMenu)
+        delete_segment = self.AppendItem(menu, _(u'Delete Wire Segment'),
+                                         self.OnDeleteSegmentMenu)
+        replace_wire = self.AppendItem(menu, _(u'Replace Wire by connections'),
+                                       self.OnReplaceWireMenu)
+
+        delete_segment.Enable(delete)
+        replace_wire.Enable(replace)
 
     # Add Divergence Menu items to the given menu
     def AddDivergenceMenuItems(self, menu, delete=False):
-        [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for dummy in xrange(2)]
-
-        # Create menu items
-        self.AddMenuItems(menu, [
-            (ID_ADD_BRANCH, wx.ITEM_NORMAL, _(u'Add Divergence Branch'), '', self.OnAddBranchMenu),
-            (ID_DELETE_BRANCH, wx.ITEM_NORMAL, _(u'Delete Divergence Branch'), '', self.OnDeleteBranchMenu)])
-
-        menu.Enable(ID_DELETE_BRANCH, delete)
+        add_branch = self.AppendItem(menu, _(u'Add Divergence Branch'),
+                                     self.OnAddBranchMenu)
+        delete_branch = self.AppendItem(menu, _(u'Delete Divergence Branch'),
+                                        self.OnDeleteBranchMenu)
+
+        delete_branch.Enable(delete)
 
     # Add Add Menu items to the given menu
     def AddAddMenuItems(self, menu):
-        [ID_ADD_BLOCK, ID_ADD_VARIABLE, ID_ADD_CONNECTION,
-         ID_ADD_COMMENT] = [wx.NewId() for dummy in xrange(4)]
-
-        # Create menu items
-        self.AddMenuItems(menu, [
-            (ID_ADD_BLOCK, wx.ITEM_NORMAL, _(u'Block'), '', self.GetAddMenuCallBack(self.AddNewBlock)),
-            (ID_ADD_VARIABLE, wx.ITEM_NORMAL, _(u'Variable'), '', self.GetAddMenuCallBack(self.AddNewVariable)),
-            (ID_ADD_CONNECTION, wx.ITEM_NORMAL, _(u'Connection'), '', self.GetAddMenuCallBack(self.AddNewConnection)),
-            None])
+        self.AppendItem(menu, _(u'Block'),
+                        self.GetAddMenuCallBack(self.AddNewBlock))
+        self.AppendItem(menu, _(u'Variable'),
+                        self.GetAddMenuCallBack(self.AddNewVariable))
+        self.AppendItem(menu, _(u'Connection'),
+                        self.GetAddMenuCallBack(self.AddNewConnection))
+        menu.AppendSeparator()
 
         if self.CurrentLanguage != "FBD":
-            [
-                ID_ADD_POWER_RAIL, ID_ADD_CONTACT, ID_ADD_COIL,
-            ] = [wx.NewId() for dummy in xrange(3)]
-
-            # Create menu items
-            self.AddMenuItems(menu, [
-                (ID_ADD_POWER_RAIL, wx.ITEM_NORMAL, _(u'Power Rail'), '', self.GetAddMenuCallBack(self.AddNewPowerRail)),
-                (ID_ADD_CONTACT, wx.ITEM_NORMAL, _(u'Contact'), '', self.GetAddMenuCallBack(self.AddNewContact))])
+            self.AppendItem(menu, _(u'Power Rail'),
+                            self.GetAddMenuCallBack(self.AddNewPowerRail))
+            self.AppendItem(menu, _(u'Contact'),
+                            self.GetAddMenuCallBack(self.AddNewContact))
 
             if self.CurrentLanguage != "SFC":
-                self.AddMenuItems(menu, [
-                    (ID_ADD_COIL, wx.ITEM_NORMAL, _(u'Coil'), '', self.GetAddMenuCallBack(self.AddNewCoil))])
+                self.AppendItem(menu, _(u'Coil'),
+                                self.GetAddMenuCallBack(self.AddNewCoil))
 
             menu.AppendSeparator()
 
         if self.CurrentLanguage == "SFC":
-            [
-                ID_ADD_INITIAL_STEP, ID_ADD_STEP, ID_ADD_TRANSITION,
-                ID_ADD_ACTION_BLOCK, ID_ADD_DIVERGENCE, ID_ADD_JUMP,
-            ] = [wx.NewId() for dummy in xrange(6)]
-
-            # Create menu items
-            self.AddMenuItems(menu, [
-                (ID_ADD_INITIAL_STEP, wx.ITEM_NORMAL, _(u'Initial Step'), '', self.GetAddMenuCallBack(self.AddNewStep, True)),
-                (ID_ADD_STEP, wx.ITEM_NORMAL, _(u'Step'), '', self.GetAddMenuCallBack(self.AddNewStep)),
-                (ID_ADD_TRANSITION, wx.ITEM_NORMAL, _(u'Transition'), '', self.GetAddMenuCallBack(self.AddNewTransition)),
-                (ID_ADD_ACTION_BLOCK, wx.ITEM_NORMAL, _(u'Action Block'), '', self.GetAddMenuCallBack(self.AddNewActionBlock)),
-                (ID_ADD_DIVERGENCE, wx.ITEM_NORMAL, _(u'Divergence'), '', self.GetAddMenuCallBack(self.AddNewDivergence)),
-                (ID_ADD_JUMP, wx.ITEM_NORMAL, _(u'Jump'), '', self.GetAddMenuCallBack(self.AddNewJump)),
-                None])
-
-        self.AddMenuItems(menu, [
-            (ID_ADD_COMMENT, wx.ITEM_NORMAL, _(u'Comment'), '', self.GetAddMenuCallBack(self.AddNewComment))])
+            self.AppendItem(menu, _(u'Initial Step'),
+                            self.GetAddMenuCallBack(self.AddNewStep, True))
+            self.AppendItem(menu, (u'Step'),
+                            self.GetAddMenuCallBack(self.AddNewStep))
+            self.AppendItem(menu, (u'Transition'),
+                            self.GetAddMenuCallBack(self.AddNewTransition))
+            self.AppendItem(menu, (u'Action Block'),
+                            self.GetAddMenuCallBack(self.AddNewActionBlock))
+            self.AppendItem(menu, (u'Divergence'),
+                            self.GetAddMenuCallBack(self.AddNewDivergence))
+            self.AppendItem(menu, (u'Jump'),
+                            self.GetAddMenuCallBack(self.AddNewJump))
+            menu.AppendSeparator()
+
+        self.AppendItem(menu, _(u'Comment'),
+                       self.GetAddMenuCallBack(self.AddNewComment))
 
     # Add Default Menu items to the given menu
     def AddDefaultMenuItems(self, menu, edit=False, block=False):
         if block:
-            [ID_EDIT_BLOCK, ID_DELETE, ID_ADJUST_BLOCK_SIZE] = [wx.NewId() for dummy in xrange(3)]
-
-            # Create menu items
-            self.AddMenuItems(menu, [
-                (ID_EDIT_BLOCK, wx.ITEM_NORMAL, _(u'Edit Block'), '', self.OnEditBlockMenu),
-                (ID_ADJUST_BLOCK_SIZE, wx.ITEM_NORMAL, _(u'Adjust Block Size'), '', self.OnAdjustBlockSizeMenu),
-                (ID_DELETE, wx.ITEM_NORMAL, _(u'Delete'), '', self.OnDeleteMenu)])
-
-            menu.Enable(ID_EDIT_BLOCK, edit)
+            edit_block = self.AppendItem(menu, _(u'Edit Block'),
+                                         self.OnEditBlockMenu)
+            self.AppendItem(menu, _(u'Adjust Block Size'),
+                            self.OnAdjustBlockSizeMenu)
+            self.AppendItem(menu, _(u'Delete'), self.OnDeleteMenu)
+
+            edit_block.Enable(edit)
 
         else:
-            [ID_CLEAR_EXEC_ORDER, ID_RESET_EXEC_ORDER] = [wx.NewId() for dummy in xrange(2)]
-
-            # Create menu items
             if self.CurrentLanguage == 'FBD':
-                self.AddMenuItems(menu, [
-                    (ID_CLEAR_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Clear Execution Order'), '', self.OnClearExecutionOrderMenu),
-                    (ID_RESET_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Reset Execution Order'), '', self.OnResetExecutionOrderMenu)])
+                self.AppendItem(menu, _(u'Clear Execution Order'),
+                                self.OnClearExecutionOrderMenu)
+                self.AppendItem(menu, _(u'Reset Execution Order'),
+                                self.OnResetExecutionOrderMenu)
                 menu.AppendSeparator()
 
             add_menu = wx.Menu(title='')
@@ -686,17 +667,13 @@
 
         menu.AppendSeparator()
 
-        [ID_CUT, ID_COPY, ID_PASTE] = [wx.NewId() for dummy in xrange(3)]
-
-        # Create menu items
-        self.AddMenuItems(menu, [
-            (ID_CUT, wx.ITEM_NORMAL, _(u'Cut'), '', self.GetClipboardCallBack(self.Cut)),
-            (ID_COPY, wx.ITEM_NORMAL, _(u'Copy'), '', self.GetClipboardCallBack(self.Copy)),
-            (ID_PASTE, wx.ITEM_NORMAL, _(u'Paste'), '', self.GetAddMenuCallBack(self.Paste))])
-
-        menu.Enable(ID_CUT, block)
-        menu.Enable(ID_COPY, block)
-        menu.Enable(ID_PASTE, self.ParentWindow.GetCopyBuffer() is not None)
+        cut   = self.AppendItem(menu, _(u'Cut'), self.GetClipboardCallBack(self.Cut))
+        copy  = self.AppendItem(menu, _(u'Copy'), self.GetClipboardCallBack(self.Copy))
+        paste = self.AppendItem(menu, _(u'Paste'), self.GetAddMenuCallBack(self.Paste))
+
+        cut.Enable(block)
+        copy.Enable(block)
+        paste.Enable(self.ParentWindow.GetCopyBuffer() is not None)
 
     def _init_Editor(self, prnt):
         self.Editor = wx.ScrolledWindow(prnt, name="Viewer",
@@ -1657,11 +1634,11 @@
         for type_label, type in [(_("Input"), INPUT),
                                  (_("Output"), OUTPUT),
                                  (_("InOut"), INOUT)]:
-            new_id = wx.NewId()
-            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label)
-            self.Bind(wx.EVT_MENU, self.GetChangeVariableTypeMenuFunction(type), id=new_id)
+            item = self.AppendItem(menu, type_label,
+                                   self.GetChangeVariableTypeMenuFunction(type),
+                                   kind=wx.ITEM_RADIO)
             if type == variable_type:
-                menu.Check(new_id, True)
+                item.Check(True)
         menu.AppendSeparator()
         self.AddDefaultMenuItems(menu, block=True)
         self.Editor.PopupMenu(menu)
@@ -1672,11 +1649,11 @@
         connection_type = self.SelectedElement.GetType()
         for type_label, type in [(_("Connector"), CONNECTOR),
                                  (_("Continuation"), CONTINUATION)]:
-            new_id = wx.NewId()
-            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label)
-            self.Bind(wx.EVT_MENU, self.GetChangeConnectionTypeMenuFunction(type), id=new_id)
-            if type == connection_type:
-                menu.Check(new_id, True)
+            item = self.AppendItem(menu, type_label,
+                                   self.GetChangeConnectionTypeMenuFunction(type),
+                                   kind=wx.ITEM_RADIO)
+            if type == variable_type:
+                item.Check(True)
         menu.AppendSeparator()
         self.AddDefaultMenuItems(menu, block=True)
         self.Editor.PopupMenu(menu)
@@ -2158,9 +2135,8 @@
 
                         # Popup contextual menu
                         menu = wx.Menu()
-                        self.AddMenuItems(menu,
-                                          [(wx.NewId(), wx.ITEM_NORMAL, text, '', callback)
-                                           for text, callback in items])
+                        for text, callback in items :
+                            self.AppendItem(menu, text, callback) 
                         self.PopupMenu(menu)
 
                     self.SelectedElement.StartConnected.HighlightParentBlock(False)