Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.py

Sun, 30 Mar 2014 22:00:14 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sun, 30 Mar 2014 22:00:14 +0200
branch
Py2 comp.
changeset 3456
96232974dcdb
parent 3178
f25fc1364c88
parent 3445
bf95eac5ce12
child 3484
645c12de6b0c
permissions
-rw-r--r--

Merge with BgService.

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
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2982
diff changeset
3 # Copyright (c) 2011 - 2014 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 """
2912
9ff696796092 Changed some display and source docu strings in the code style checker to make them more universal because the scope goes beyond PEP-8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2909
diff changeset
7 Module implementing a dialog showing statistical data for the last code
9ff696796092 Changed some display and source docu strings in the code style checker to make them more universal because the scope goes beyond PEP-8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2909
diff changeset
8 style checker run.
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
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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
11 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
12
3443
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
13 from PyQt4.QtCore import Qt
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
14 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
15
3443
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
16 from .translations import _messages, _messages_sample_args
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
17
2972
ae58d4b2562e Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2971
diff changeset
18 from .Ui_CodeStyleStatisticsDialog import Ui_CodeStyleStatisticsDialog
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
19
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
20 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
21
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 857
diff changeset
22
2972
ae58d4b2562e Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2971
diff changeset
23 class CodeStyleStatisticsDialog(QDialog, Ui_CodeStyleStatisticsDialog):
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
24 """
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 Class implementing a dialog showing statistical data for the last
2912
9ff696796092 Changed some display and source docu strings in the code style checker to make them more universal because the scope goes beyond PEP-8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2909
diff changeset
26 code style checker run.
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 """
3445
bf95eac5ce12 Typo corrected.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3443
diff changeset
28 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
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 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
31
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
32 @param statistics dictionary with the statistical data
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
33 @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
34 """
3057
10516539f238 Merge with default branch after shorten the code lines to max. 79 characters.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3056 2982
diff changeset
35 super(CodeStyleStatisticsDialog, self).__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
36 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
37
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 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
39 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
40 filesIssues = stats["_FilesIssues"]
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
41 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
42 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
43 del stats["_FilesIssues"]
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
44 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
45
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
46 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
47
2895
4a44d92757f9 Implemented some fixers for wrong naming conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2894
diff changeset
48 for code in sorted(stats.keys()):
3443
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
49 message = _messages.get(code)
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
50 if message is None:
2862
a1448560d7dc Started upgrading the pep8 checker to the latest release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 continue
3443
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
52
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
53 if code in _messages_sample_args:
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
54 message = message.format(*_messages_sample_args[code])
7d919fd299f6 Bugfix for statistics dialog of the code style checker.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
55
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
56 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
57 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
58
857
613ded9c3b69 Fixed an issue with the extended PEP 8 statistics.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 853
diff changeset
59 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
60 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
61 self.fixedIssues.setText(
853
ec7dd115e26b Continued implementing a fixer for PEP 8 issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 847
diff changeset
62 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
63 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
64 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
65 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
66 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
67
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.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
69 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
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 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
72 """
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 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
74
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 @param count occurrences of the issue (integer)
2980
2cb4e3c50b37 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2979
diff changeset
76 @param code of a code style issue message (string)
2cb4e3c50b37 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2979
diff changeset
77 @param message code style issue message to be shown (string)
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
78 """
1640
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
79 itm = QTreeWidgetItem(self.statisticsList)
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 itm.setIcon(1, UI.PixmapCache.getIcon("namingError.png"))
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2912
diff changeset
89 elif code.startswith("D"):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2912
diff changeset
90 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError.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
91
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 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
93 itm.setTextAlignment(1, Qt.AlignHCenter)

eric ide

mercurial