eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog showing statistical data for the last code
8 style checker run.
9 """
10
11 import textwrap
12
13 from PyQt5.QtCore import Qt
14 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem
15
16 from .translations import getTranslatedMessage
17
18 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog
19
20 import UI.PixmapCache
21
22
23 class CodeStyleStatisticsDialog(QDialog, Ui_CodeStyleStatisticsDialog):
24 """
25 Class implementing a dialog showing statistical data for the last
26 code style checker run.
27 """
28 def __init__(self, statistics, parent=None):
29 """
30 Constructor
31
32 @param statistics dictionary with the statistical data
33 @type dict
34 @param parent reference to the parent widget
35 @type QWidget
36 """
37 super().__init__(parent)
38 self.setupUi(self)
39
40 stats = statistics.copy()
41 filesCount = stats["_FilesCount"]
42 filesIssues = stats["_FilesIssues"]
43 fixesCount = stats["_IssuesFixed"]
44 securityOk = stats["_SecurityOK"]
45 del stats["_FilesCount"]
46 del stats["_FilesIssues"]
47 del stats["_IssuesFixed"]
48 del stats["_SecurityOK"]
49
50 totalIssues = 0
51 ignoresCount = 0
52
53 textWrapper = textwrap.TextWrapper(width=80)
54
55 for code in sorted(stats.keys()):
56 message = getTranslatedMessage(code, [], example=True)
57 if message is None:
58 continue
59
60 self.__createItem(stats[code], code,
61 "\n".join(textWrapper.wrap(message)))
62 totalIssues += stats[code]["total"]
63 ignoresCount += stats[code]["ignored"]
64
65 self.totalIssues.setText(
66 self.tr("%n issue(s) found", "", totalIssues))
67 self.ignoredIssues.setText(
68 self.tr("%n issue(s) ignored", "", ignoresCount))
69 self.fixedIssues.setText(
70 self.tr("%n issue(s) fixed", "", fixesCount))
71 self.filesChecked.setText(
72 self.tr("%n file(s) checked", "", filesCount))
73 self.filesIssues.setText(
74 self.tr("%n file(s) with issues found", "", filesIssues))
75 self.securityOk.setText(
76 self.tr("%n security issue(s) acknowledged", "", securityOk))
77
78 self.statisticsList.resizeColumnToContents(0)
79 self.statisticsList.resizeColumnToContents(1)
80 self.statisticsList.resizeColumnToContents(2)
81
82 def __createItem(self, counts, code, message):
83 """
84 Private method to create an entry in the result list.
85
86 @param counts dictionary containing the total and ignored occurrences
87 of the issue
88 @type dict
89 @param code of a code style issue message
90 @type str
91 @param message code style issue message to be shown
92 @type str
93 """
94 itm = QTreeWidgetItem(self.statisticsList, [
95 code, "{0:6d}".format(counts["total"] - counts["ignored"]),
96 "{0:6d}".format(counts["ignored"]), message])
97 if code.startswith(("W", "C", "M")):
98 itm.setIcon(0, UI.PixmapCache.getIcon("warning"))
99 elif code.startswith("E"):
100 itm.setIcon(0, UI.PixmapCache.getIcon("syntaxError"))
101 elif code.startswith("N"):
102 itm.setIcon(0, UI.PixmapCache.getIcon("namingError"))
103 elif code.startswith("D"):
104 itm.setIcon(0, UI.PixmapCache.getIcon("docstringError"))
105 elif code.startswith("S"):
106 itm.setIcon(0, UI.PixmapCache.getIcon("securityLow"))
107 elif code.startswith("P"):
108 itm.setIcon(0, UI.PixmapCache.getIcon("dirClosed"))
109 elif code.startswith("Y"):
110 itm.setIcon(0, UI.PixmapCache.getIcon("filePython"))
111
112 itm.setTextAlignment(
113 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter)
114 itm.setTextAlignment(
115 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
116 itm.setTextAlignment(
117 2, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)

eric ide

mercurial