def accept(self): try: text = self.textedit.toPlainText() self.editor = HtmlEditor.from_string(text, 'py') super(CodeInput, self).accept() except ParseException: QtWidgets.QMessageBox.critical(self, "Parsing error", "Could not parse the given text.")