Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 3056
9986ec0e559a
parent 2982
556adfe76ba7
child 3145
a9de05d4a22f
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
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 __future__ import unicode_literals # __IGNORE_WARNING__
12
13 from PyQt4.QtCore import Qt, QCoreApplication
14 from PyQt4.QtGui import QDialog, QTreeWidgetItem
15
16 from . import pep8
17 from .NamingStyleChecker import NamingStyleChecker
18 from .DocStyleChecker import DocStyleChecker
19
20 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog
21
22 import UI.PixmapCache
23
24
25 class CodeStyleStatisticsDialog(QDialog, Ui_CodeStyleStatisticsDialog):
26 """
27 Class implementing a dialog showing statistical data for the last
28 code style checker run.
29 """
30 def __init__(self, statistics, parent=None):
31 """
32 Constructor
33
34 @param statistics dictionary with the statistical data
35 @param parent reference to the parent widget (QWidget)
36 """
37 super(CodeStyleStatisticsDialog, self).__init__(parent)
38 self.setupUi(self)
39
40 stats = statistics.copy()
41 filesCount = stats["_FilesCount"]
42 filesIssues = stats["_FilesIssues"]
43 fixesCount = stats["_IssuesFixed"]
44 del stats["_FilesCount"]
45 del stats["_FilesIssues"]
46 del stats["_IssuesFixed"]
47
48 totalIssues = 0
49
50 for code in sorted(stats.keys()):
51 if code in pep8.pep8_messages_sample_args:
52 message = QCoreApplication.translate(
53 "pep8", pep8.pep8_messages[code]).format(
54 *pep8.pep8_messages_sample_args[code])
55 elif code in pep8.pep8_messages:
56 message = QCoreApplication.translate(
57 "pep8", pep8.pep8_messages[code])
58 elif code in NamingStyleChecker.Messages:
59 message = QCoreApplication.translate(
60 "NamingStyleChecker", NamingStyleChecker.Messages[code])
61 elif code in DocStyleChecker.Messages:
62 message = QCoreApplication.translate(
63 "DocStyleChecker", DocStyleChecker.Messages[code])
64 else:
65 continue
66 self.__createItem(stats[code], code, message)
67 totalIssues += stats[code]
68
69 self.totalIssues.setText(
70 self.trUtf8("%n issue(s) found", "", totalIssues))
71 self.fixedIssues.setText(
72 self.trUtf8("%n issue(s) fixed", "", fixesCount))
73 self.filesChecked.setText(
74 self.trUtf8("%n file(s) checked", "", filesCount))
75 self.filesIssues.setText(
76 self.trUtf8("%n file(s) with issues found", "", filesIssues))
77
78 self.statisticsList.resizeColumnToContents(0)
79 self.statisticsList.resizeColumnToContents(1)
80
81 def __createItem(self, count, code, message):
82 """
83 Private method to create an entry in the result list.
84
85 @param count occurrences of the issue (integer)
86 @param code of a code style issue message (string)
87 @param message code style issue message to be shown (string)
88 """
89 itm = QTreeWidgetItem(self.statisticsList)
90 itm.setData(0, Qt.DisplayRole, count)
91 itm.setData(1, Qt.DisplayRole, code)
92 itm.setData(2, Qt.DisplayRole, message)
93 if code.startswith("W"):
94 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png"))
95 elif code.startswith("E"):
96 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png"))
97 elif code.startswith("N"):
98 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png"))
99 elif code.startswith("D"):
100 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.png"))
101
102 itm.setTextAlignment(0, Qt.AlignRight)
103 itm.setTextAlignment(1, Qt.AlignHCenter)

eric ide

mercurial