Plugins/CheckerPlugins/Pep8/Pep8StatisticsDialog.py

Fri, 13 Sep 2013 18:38:34 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 13 Sep 2013 18:38:34 +0200
changeset 2909
c3fb85fe41f9
parent 2895
4a44d92757f9
child 2912
9ff696796092
permissions
-rw-r--r--

Added the forgotten icon to the PEP-8 statistics dialog.

847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog showing statistical data for the last PEP 8 run.
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt4.QtCore import Qt, QCoreApplication
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from . import pep8
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
14 from .Pep8NamingChecker import Pep8NamingChecker
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .Ui_Pep8StatisticsDialog import Ui_Pep8StatisticsDialog
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import UI.PixmapCache
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 857
diff changeset
20
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class Pep8StatisticsDialog(QDialog, Ui_Pep8StatisticsDialog):
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing a dialog showing statistical data for the last
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 PEP 8 run.
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 857
diff changeset
26 def __init__(self, statistics, parent=None):
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param dictionary with the statistical data
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param parent reference to the parent widget (QWidget)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
33 super().__init__(parent)
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setupUi(self)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 stats = statistics.copy()
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 filesCount = stats["_FilesCount"]
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 filesIssues = stats["_FilesIssues"]
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
39 fixesCount = stats["_IssuesFixed"]
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 del stats["_FilesCount"]
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 del stats["_FilesIssues"]
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
42 del stats["_IssuesFixed"]
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 totalIssues = 0
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
46 for code in sorted(stats.keys()):
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if code in pep8.pep8_messages_sample_args:
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
48 message = QCoreApplication.translate(
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
49 "pep8", pep8.pep8_messages[code]).format(
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
50 *pep8.pep8_messages_sample_args[code])
2862
a1448560d7dc Started upgrading the pep8 checker to the latest release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 elif code in pep8.pep8_messages:
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
52 message = QCoreApplication.translate(
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
53 "pep8", pep8.pep8_messages[code])
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
54 elif code in Pep8NamingChecker.Messages:
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
55 message = QCoreApplication.translate(
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
56 "Pep8NamingChecker", Pep8NamingChecker.Messages[code])
2862
a1448560d7dc Started upgrading the pep8 checker to the latest release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
57 else:
a1448560d7dc Started upgrading the pep8 checker to the latest release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
58 continue
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__createItem(stats[code], code, message)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 totalIssues += stats[code]
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
857
613ded9c3b69 Fixed an issue with the extended PEP 8 statistics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 853
diff changeset
62 self.totalIssues.setText(
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.trUtf8("%n issue(s) found", "", totalIssues))
857
613ded9c3b69 Fixed an issue with the extended PEP 8 statistics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 853
diff changeset
64 self.fixedIssues.setText(
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
65 self.trUtf8("%n issue(s) fixed", "", fixesCount))
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.filesChecked.setText(
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.trUtf8("%n file(s) checked", "", filesCount))
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.filesIssues.setText(
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.trUtf8("%n file(s) with issues found", "", filesIssues))
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.statisticsList.resizeColumnToContents(0)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.statisticsList.resizeColumnToContents(1)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def __createItem(self, count, code, message):
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 Private method to create an entry in the result list.
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @param count occurrences of the issue (integer)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @param code of a PEP 8 message (string)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @param message PEP 8 message to be shown (string)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
1640
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
82 itm = QTreeWidgetItem(self.statisticsList)
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
83 itm.setData(0, Qt.DisplayRole, count)
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
84 itm.setData(1, Qt.DisplayRole, code)
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
85 itm.setData(2, Qt.DisplayRole, message)
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if code.startswith("W"):
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 itm.setIcon(1, UI.PixmapCache.getIcon("warning.png"))
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 elif code.startswith("E"):
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError.png"))
2909
c3fb85fe41f9 Added the forgotten icon to the PEP-8 statistics dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2895
diff changeset
90 elif code.startswith("N"):
c3fb85fe41f9 Added the forgotten icon to the PEP-8 statistics dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2895
diff changeset
91 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png"))
847
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 itm.setTextAlignment(0, Qt.AlignRight)
cc18fbcde9fc Added a dialog to show some statistics for the last PEP 8 check to the PEP 8 dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 itm.setTextAlignment(1, Qt.AlignHCenter)

eric ide

mercurial