|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2019 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 from __future__ import unicode_literals |
|
12 |
|
13 from PyQt5.QtCore import Qt |
|
14 from PyQt5.QtWidgets import QDialog, QTreeWidgetItem |
|
15 |
|
16 from .translations import _messages, _messages_sample_args |
|
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 @param parent reference to the parent widget (QWidget) |
|
34 """ |
|
35 super(CodeStyleStatisticsDialog, self).__init__(parent) |
|
36 self.setupUi(self) |
|
37 |
|
38 stats = statistics.copy() |
|
39 filesCount = stats["_FilesCount"] |
|
40 filesIssues = stats["_FilesIssues"] |
|
41 fixesCount = stats["_IssuesFixed"] |
|
42 ignoresCount = stats["_IgnoredErrors"] |
|
43 del stats["_FilesCount"] |
|
44 del stats["_FilesIssues"] |
|
45 del stats["_IssuesFixed"] |
|
46 del stats["_IgnoredErrors"] |
|
47 |
|
48 totalIssues = 0 |
|
49 |
|
50 for code in sorted(stats.keys()): |
|
51 message = _messages.get(code) |
|
52 if message is None: |
|
53 continue |
|
54 |
|
55 if code in _messages_sample_args: |
|
56 message = message.format(*_messages_sample_args[code]) |
|
57 |
|
58 self.__createItem(stats[code], code, message) |
|
59 totalIssues += stats[code] |
|
60 |
|
61 self.totalIssues.setText( |
|
62 self.tr("%n issue(s) found", "", totalIssues)) |
|
63 self.ignoredIssues.setText( |
|
64 self.tr("%n issue(s) ignored", "", ignoresCount)) |
|
65 self.fixedIssues.setText( |
|
66 self.tr("%n issue(s) fixed", "", fixesCount)) |
|
67 self.filesChecked.setText( |
|
68 self.tr("%n file(s) checked", "", filesCount)) |
|
69 self.filesIssues.setText( |
|
70 self.tr("%n file(s) with issues found", "", filesIssues)) |
|
71 |
|
72 self.statisticsList.resizeColumnToContents(0) |
|
73 self.statisticsList.resizeColumnToContents(1) |
|
74 |
|
75 def __createItem(self, count, code, message): |
|
76 """ |
|
77 Private method to create an entry in the result list. |
|
78 |
|
79 @param count occurrences of the issue (integer) |
|
80 @param code of a code style issue message (string) |
|
81 @param message code style issue message to be shown (string) |
|
82 """ |
|
83 itm = QTreeWidgetItem(self.statisticsList) |
|
84 itm.setData(0, Qt.DisplayRole, count) |
|
85 itm.setData(1, Qt.DisplayRole, code) |
|
86 itm.setData(2, Qt.DisplayRole, message) |
|
87 if code.startswith(("W", "C", "M")): |
|
88 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png")) |
|
89 elif code.startswith("E"): |
|
90 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png")) |
|
91 elif code.startswith("N"): |
|
92 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png")) |
|
93 elif code.startswith("D"): |
|
94 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png")) |
|
95 |
|
96 itm.setTextAlignment(0, Qt.AlignRight) |
|
97 itm.setTextAlignment(1, Qt.AlignHCenter) |