def setPlainText(self, p_str): # FixMe: Keep a reference to old QTextDocuments form previously loaded # files. This is needed to prevent garbage collection which results in a # seg fault if the document is discarded while still being highlighted. self.old_docs.append(self.document()) doc = QTextDocument() doc.setDocumentLayout(QPlainTextDocumentLayout(doc)) doc.setPlainText(p_str) self.setDocument(doc) self.margin.updateWidth() # start syntax heightening self.gCodeHighlighter = GcodeSyntaxHighlighter(self)