def addItemBefore(self, caption, icon, command, itemToAddBefore):
        """Add an item before some item. If the given item does not exist the
        item is added at the end of the menu. Icon and command can be null,
        but a caption must be given.

        @param caption:
                   the text for the menu item
        @param icon:
                   the icon for the menu item
        @param command:
                   the command for the menu item
        @param itemToAddBefore:
                   the item that will be after the new item
        @raise ValueError:
                    If the item is checkable and thus cannot have children.
        """
        if self.isCheckable():
            raise ValueError, 'A checkable item cannot have children'

        newItem = None

        if self.hasChildren() and itemToAddBefore in self._itsChildren:
            try:
                index = self._itsChildren.index(itemToAddBefore)
            except __HOLE__:
                index = -1
            newItem = MenuItem(caption, icon, command, self._menu)
            newItem.setParent(self)
            self._itsChildren.append(index, newItem)
        else:
            newItem = self.addItem(caption, icon, command)
        self._menu.requestRepaint()
        return newItem
dataset/ETHPy150Open rwl/muntjac/muntjac/ui/menu_bar.py/MenuItem.addItemBefore