def is_top_command(self, widget):
        """Return True if widget is a top command.

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

        A top command is a widget which has an 'invoke'
        attribute and whose parent is the MenuManager
        instance (the root of the whole menu structure).
        """
        ### evaluate conditions

        a = hasattr(widget, "invoke")
        b = isinstance(widget.parent, self.__class__)

        ### return True if both conditions are True
        return a and b
Return True if widget is a top command.

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

        A top command is a widget which has an 'invoke'
        attribute and whose parent is the MenuManager
        instance (the root of the whole menu structure).
        
nodezator/menu/behaviour.py