Plugins/CheckerPlugins/Pep8/Pep8StatisticsDialog.py

changeset 847
cc18fbcde9fc
child 853
ec7dd115e26b
equal deleted inserted replaced
846:869c200be26e 847:cc18fbcde9fc
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog showing statistical data for the last PEP 8 run.
8 """
9
10 from PyQt4.QtCore import Qt, QCoreApplication
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem
12
13 from . import pep8
14
15 from .Ui_Pep8StatisticsDialog import Ui_Pep8StatisticsDialog
16
17 import UI.PixmapCache
18
19 class Pep8StatisticsDialog(QDialog, Ui_Pep8StatisticsDialog):
20 """
21 Class implementing a dialog showing statistical data for the last
22 PEP 8 run.
23 """
24 def __init__(self, statistics, parent = None):
25 """
26 Constructor
27
28 @param dictionary with the statistical data
29 @param parent reference to the parent widget (QWidget)
30 """
31 QDialog.__init__(self, parent)
32 self.setupUi(self)
33
34 stats = statistics.copy()
35 filesCount = stats["_FilesCount"]
36 filesIssues = stats["_FilesIssues"]
37 del stats["_FilesCount"]
38 del stats["_FilesIssues"]
39
40 totalIssues = 0
41
42 for code in sorted(stats.keys(), key=lambda a: a[1:]):
43 if code in pep8.pep8_messages_sample_args:
44 message = QCoreApplication.translate("pep8",
45 pep8.pep8_messages[code]).format(
46 *pep8.pep8_messages_sample_args[code])
47 else:
48 message = QCoreApplication.translate("pep8",
49 pep8.pep8_messages[code])
50 self.__createItem(stats[code], code, message)
51 totalIssues += stats[code]
52
53 self.total.setText(
54 self.trUtf8("%n issue(s) found", "", totalIssues))
55 self.filesChecked.setText(
56 self.trUtf8("%n file(s) checked", "", filesCount))
57 self.filesIssues.setText(
58 self.trUtf8("%n file(s) with issues found", "", filesIssues))
59
60 self.statisticsList.resizeColumnToContents(0)
61 self.statisticsList.resizeColumnToContents(1)
62
63 def __createItem(self, count, code, message):
64 """
65 Private method to create an entry in the result list.
66
67 @param count occurrences of the issue (integer)
68 @param code of a PEP 8 message (string)
69 @param message PEP 8 message to be shown (string)
70 """
71 itm = QTreeWidgetItem(self.statisticsList,
72 ["{0:6}".format(count), code, message])
73 if code.startswith("W"):
74 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png"))
75 elif code.startswith("E"):
76 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png"))
77
78 itm.setTextAlignment(0, Qt.AlignRight)
79 itm.setTextAlignment(1, Qt.AlignHCenter)

eric ide

mercurial