def get_top_menu(self, widget):
        """Get top menu of item.

        widget (either a menu.submenu.main.Menu or
                menu.command.Command instance)

        The method goes over the object parent attribute
        recursively until it reaches the widget which is
        the top menu.
        """
        ### if the widget is the top menu, return it
        if self.is_top_menu(widget):
            return widget

        ### otherwise check its parent
        else:
            return self.get_top_menu(widget.parent)
Get top menu of item.

        widget (either a menu.submenu.main.Menu or
                menu.command.Command instance)

        The method goes over the object parent attribute
        recursively until it reaches the widget which is
        the top menu.
        
nodezator/menu/behaviour.py