Example #1
0
    def new_tab(self, title, text):
        new_editor = QPlainTextEdit()
        new_editor.setFont(self._font)
        new_editor.setPlainText(text)
        TemplateHighlighter(new_editor.document())

        new_editor.textChanged.connect(self._text_changed)
        self._widgets_indexes[new_editor] = self.count()
        self.addTab(new_editor, title)
Example #2
0
class _ReportingWindow(QDialog):
    def __init__(self, name, report, parent=None):
        QDialog.__init__(self, parent)
        icon = self.style().standardIcon(QStyle.SP_MessageBoxCritical)

        self.setWindowTitle('Error reporting')
        self.setWindowIcon(icon)

        try:
            font = QFontDatabase().systemFont(QFontDatabase.FixedFont)
        except AttributeError as e:
            font = QFont()
            font.setStyleHint(QFont.TypeWriter)

        self.text = QPlainTextEdit()
        self.text.setFont(font)
        self.text.setReadOnly(True)
        self.text.setLineWrapMode(QPlainTextEdit.NoWrap)
        self.text.setPlainText(report)
        TracebackHighlighter(self.text.document())

        icon_label = QLabel()
        icon_label.setPixmap(icon.pixmap(ICON_SIZE, ICON_SIZE))

        label = QLabel("{} error !".format(name))
        label.setFont(QFont('default', pointSize=14))

        button_copy = QPushButton('Copy to clipboard')
        button_copy.clicked.connect(self._copy)

        layout = QGridLayout(self)
        layout.addWidget(icon_label, 0, 0)
        layout.addWidget(label, 0, 1)
        layout.addWidget(self.text, 1, 0, 1, 2)
        layout.addWidget(button_copy, 2, 0, 1, 2)
        layout.setColumnStretch(1, 100)

        self.setModal(True)
        self.resize(600, 400)

    def _copy(self):
        clipboard = QApplication.clipboard()
        clipboard.setText('```\n' + self.text.toPlainText() + '\n```')