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