'Can be called by any item in the scene to expand its context menu to include parent context menus.
Parents may implement getContextMenus to add new menus / actions to the existing menu.
getContextMenus must accept 1 argument (the event that generated the original menu) and
return a single QMenu or a list of QMenus.
The final menu will look like:
|    Original Item 1
|    Original Item 2
|    Original Item N
|    Parent Item 1
|    Parent Item 2
|    Grandparent Item 1
**Arguments:**
item            The item that initially created the context menu
(This is probably the item making the call to this function)
menu            The context menu being shown by the item
event           The original event that triggered the menu to appear.'

def addParentContextMenus(self, item, menu, event):

    menusToAdd = []
    while (item is not self):
        item = item.parentItem()
        if (item is None):
            item = self
        if (not hasattr(item, 'getContextMenus')):
            continue
        subMenus = (item.getContextMenus(event) or [])
        if isinstance(subMenus, list):
            menusToAdd.extend(subMenus)
        else:
            menusToAdd.append(subMenus)
    if menusToAdd:
        menu.addSeparator()
    for m in menusToAdd:
        if isinstance(m, QtGui.QMenu):
            menu.addMenu(m)
        elif isinstance(m, QtGui.QAction):
            menu.addAction(m)
        else:
            raise Exception(('Cannot    add    object    %s    (type=%s)    to    QMenu.' % (str(m), str(type(m)))))
    return menu
