'Reimplement Qt method'

def contextMenuEvent(self, event):

    nonempty_selection = self.has_selected_text()
    self.copy_action.setEnabled(nonempty_selection)
    self.cut_action.setEnabled(nonempty_selection)
    self.clear_all_output_action.setVisible((self.is_json() and (nbformat is not None)))
    self.ipynb_convert_action.setVisible((self.is_json() and (nbformat is not None)))
    self.run_cell_action.setVisible(self.is_python())
    self.run_cell_and_advance_action.setVisible(self.is_python())
    self.run_selection_action.setVisible(self.is_python())
    self.re_run_last_cell_action.setVisible(self.is_python())
    self.gotodef_action.setVisible((self.go_to_definition_enabled and self.is_python_like()))
    cursor = self.textCursor()
    text = to_text_string(cursor.selectedText())
    if (len(text) == 0):
        cursor.select(QTextCursor.WordUnderCursor)
        text = to_text_string(cursor.selectedText())
    self.undo_action.setEnabled(self.document().isUndoAvailable())
    self.redo_action.setEnabled(self.document().isRedoAvailable())
    menu = self.menu
    if self.isReadOnly():
        menu = self.readonly_menu
    menu.popup(event.globalPos())
    event.accept()
