forked from wonder-sk/qgis-first-aid-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframesview.py
57 lines (44 loc) · 1.88 KB
/
framesview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#-----------------------------------------------------------
# Copyright (C) 2015 Martin Dobias
#-----------------------------------------------------------
# Licensed under the terms of GNU GPL 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#---------------------------------------------------------------------
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
import os
import traceback
from qgis.PyQt.QtWidgets import QTreeView
class FramesModel(QAbstractListModel):
def __init__(self, tb, parent=None):
QAbstractListModel.__init__(self, parent)
if isinstance(tb, list):
self.tb = None
self.entries = tb
else:
self.tb = tb
self.entries = traceback.extract_tb(tb)
def rowCount(self, parent):
return len(self.entries)
def data(self, index, role):
if not index.isValid():
return
if role == Qt.DisplayRole:
entry = self.entries[index.row()]
return "%s [%s:%d]" % (entry[2], os.path.basename(entry[0]), entry[1])
elif role == Qt.ToolTipRole:
entry = self.entries[index.row()]
return "<b>Method:</b> %s\n<br>\n<b>Line:</b> %d\n<br><br>\n<b>Path:</b><br>\n%s" % (entry[2], entry[1], entry[0])
def headerData(self, section, orientation, role):
if section == 0 and orientation == Qt.Horizontal and role == Qt.DisplayRole:
return "Traceback (most recent call last)" #"Frames"
class FramesView(QTreeView):
def __init__(self, parent=None):
QTreeView.__init__(self, parent)
self.setRootIsDecorated(False)
def setTraceback(self, tb):
self.setModel(FramesModel(tb, self))