Exemple #1
0
    def __init__(self, parent, view, tb):
        QDialog.__init__(self, parent)
        loadUi(self, 'dialogs/traceback.ui')
        self.tb = tb
        self.view = view
        self.client = parent.client

        assert tb.startswith('Traceback')
        # split into frames and message
        frames = []
        message = ''
        curframe = []
        for line in tb.splitlines():
            if line.startswith('        '):
                try:
                    name, v = line.split('=', 1)
                except ValueError:
                    pass  # most probably the "^" line of a SyntaxError
                else:
                    if curframe:
                        curframe[2][name.strip()] = v.strip()
            elif line.startswith('    '):
                if curframe:
                    curframe[1] = line.strip()
            elif line.startswith('  '):
                curframe = [line.strip(), '', {}]
                frames.append(curframe)
            elif not line.startswith('Traceback'):
                message += line

        button = QPushButton('To clipboard', self)
        self.buttonBox.addButton(button, QDialogButtonBox.ActionRole)

        def copy():
            QApplication.clipboard().setText(tb+'\n', QClipboard.Selection)
            QApplication.clipboard().setText(tb+'\n', QClipboard.Clipboard)
        button.clicked.connect(copy)

        self.message.setText(message[:200])
        self.tree.setFont(view.font())
        boldfont = QFont(view.font())
        boldfont.setBold(True)
        for filename, line, bindings in frames:
            item = QTreeWidgetItem(self.tree, [filename])
            item.setFirstColumnSpanned(True)
            item = QTreeWidgetItem(self.tree, [line])
            item.setFirstColumnSpanned(True)
            item.setFont(0, boldfont)
            for var, value in iteritems(bindings):
                QTreeWidgetItem(item, ['', var, value])
Exemple #2
0
 def line_item(msg):
     item = QTreeWidgetItem(self.tree, [msg])
     item.setFirstColumnSpanned(True)
     return item