src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2022 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 PyQt6.QtCore import Qt
14 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem
15
16 from .translations import getTranslatedMessage
17
18 from . import CodeStyleCheckerUtilities
19
20 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog
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, statisticData, parent=None):
29 """
30 Constructor
31
32 @param statisticData 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 = statisticData.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 msgCode in sorted(stats.keys()):
56 message = getTranslatedMessage(msgCode, [], example=True)
57 if message is None:
58 continue
59
60 self.__createItem(stats[msgCode], msgCode,
61 "\n".join(textWrapper.wrap(message)))
62 totalIssues += stats[msgCode]["total"]
63 ignoresCount += stats[msgCode]["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, msgCode, 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 msgCode 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 msgCode, "{0:6d}".format(counts["total"] - counts["ignored"]),
96 "{0:6d}".format(counts["ignored"]), message])
97 CodeStyleCheckerUtilities.setItemIcon(itm, 0, msgCode)
98
99 itm.setTextAlignment(
100 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter)
101 itm.setTextAlignment(
102 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
103 itm.setTextAlignment(
104 2, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)

eric ide

mercurial