13 from PyQt6.QtCore import Qt |
13 from PyQt6.QtCore import Qt |
14 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem |
14 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem |
15 |
15 |
16 from .translations import getTranslatedMessage |
16 from .translations import getTranslatedMessage |
17 |
17 |
|
18 from . import CodeStyleCheckerUtilities |
|
19 |
18 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog |
20 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog |
19 |
|
20 import UI.PixmapCache |
|
21 |
21 |
22 |
22 |
23 class CodeStyleStatisticsDialog(QDialog, Ui_CodeStyleStatisticsDialog): |
23 class CodeStyleStatisticsDialog(QDialog, Ui_CodeStyleStatisticsDialog): |
24 """ |
24 """ |
25 Class implementing a dialog showing statistical data for the last |
25 Class implementing a dialog showing statistical data for the last |
26 code style checker run. |
26 code style checker run. |
27 """ |
27 """ |
28 def __init__(self, statistics, parent=None): |
28 def __init__(self, statisticData, parent=None): |
29 """ |
29 """ |
30 Constructor |
30 Constructor |
31 |
31 |
32 @param statistics dictionary with the statistical data |
32 @param statisticData dictionary with the statistical data |
33 @type dict |
33 @type dict |
34 @param parent reference to the parent widget |
34 @param parent reference to the parent widget |
35 @type QWidget |
35 @type QWidget |
36 """ |
36 """ |
37 super().__init__(parent) |
37 super().__init__(parent) |
38 self.setupUi(self) |
38 self.setupUi(self) |
39 |
39 |
40 stats = statistics.copy() |
40 stats = statisticData.copy() |
41 filesCount = stats["_FilesCount"] |
41 filesCount = stats["_FilesCount"] |
42 filesIssues = stats["_FilesIssues"] |
42 filesIssues = stats["_FilesIssues"] |
43 fixesCount = stats["_IssuesFixed"] |
43 fixesCount = stats["_IssuesFixed"] |
44 securityOk = stats["_SecurityOK"] |
44 securityOk = stats["_SecurityOK"] |
45 del stats["_FilesCount"] |
45 del stats["_FilesCount"] |
50 totalIssues = 0 |
50 totalIssues = 0 |
51 ignoresCount = 0 |
51 ignoresCount = 0 |
52 |
52 |
53 textWrapper = textwrap.TextWrapper(width=80) |
53 textWrapper = textwrap.TextWrapper(width=80) |
54 |
54 |
55 for code in sorted(stats.keys()): |
55 for msgCode in sorted(stats.keys()): |
56 message = getTranslatedMessage(code, [], example=True) |
56 message = getTranslatedMessage(msgCode, [], example=True) |
57 if message is None: |
57 if message is None: |
58 continue |
58 continue |
59 |
59 |
60 self.__createItem(stats[code], code, |
60 self.__createItem(stats[msgCode], msgCode, |
61 "\n".join(textWrapper.wrap(message))) |
61 "\n".join(textWrapper.wrap(message))) |
62 totalIssues += stats[code]["total"] |
62 totalIssues += stats[msgCode]["total"] |
63 ignoresCount += stats[code]["ignored"] |
63 ignoresCount += stats[msgCode]["ignored"] |
64 |
64 |
65 self.totalIssues.setText( |
65 self.totalIssues.setText( |
66 self.tr("%n issue(s) found", "", totalIssues)) |
66 self.tr("%n issue(s) found", "", totalIssues)) |
67 self.ignoredIssues.setText( |
67 self.ignoredIssues.setText( |
68 self.tr("%n issue(s) ignored", "", ignoresCount)) |
68 self.tr("%n issue(s) ignored", "", ignoresCount)) |
77 |
77 |
78 self.statisticsList.resizeColumnToContents(0) |
78 self.statisticsList.resizeColumnToContents(0) |
79 self.statisticsList.resizeColumnToContents(1) |
79 self.statisticsList.resizeColumnToContents(1) |
80 self.statisticsList.resizeColumnToContents(2) |
80 self.statisticsList.resizeColumnToContents(2) |
81 |
81 |
82 def __createItem(self, counts, code, message): |
82 def __createItem(self, counts, msgCode, message): |
83 """ |
83 """ |
84 Private method to create an entry in the result list. |
84 Private method to create an entry in the result list. |
85 |
85 |
86 @param counts dictionary containing the total and ignored occurrences |
86 @param counts dictionary containing the total and ignored occurrences |
87 of the issue |
87 of the issue |
88 @type dict |
88 @type dict |
89 @param code of a code style issue message |
89 @param msgCode code of a code style issue message |
90 @type str |
90 @type str |
91 @param message code style issue message to be shown |
91 @param message code style issue message to be shown |
92 @type str |
92 @type str |
93 """ |
93 """ |
94 itm = QTreeWidgetItem(self.statisticsList, [ |
94 itm = QTreeWidgetItem(self.statisticsList, [ |
95 code, "{0:6d}".format(counts["total"] - counts["ignored"]), |
95 msgCode, "{0:6d}".format(counts["total"] - counts["ignored"]), |
96 "{0:6d}".format(counts["ignored"]), message]) |
96 "{0:6d}".format(counts["ignored"]), message]) |
97 if code.startswith(("W", "C", "M")): |
97 CodeStyleCheckerUtilities.setItemIcon(itm, 0, msgCode) |
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 |
98 |
112 itm.setTextAlignment( |
99 itm.setTextAlignment( |
113 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) |
100 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) |
114 itm.setTextAlignment( |
101 itm.setTextAlignment( |
115 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) |
102 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) |