Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show the output of the tabnanny command process.
8 """
9
10 import sys
11 import os
12 import types
13
14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import *
16
17 from E4Gui.E4Application import e4App
18
19 from Ui_TabnannyDialog import Ui_TabnannyDialog
20
21 import Tabnanny
22 import Utilities
23
24 class TabnannyDialog(QDialog, Ui_TabnannyDialog):
25 """
26 Class implementing a dialog to show the results of the tabnanny check run.
27 """
28 def __init__(self, parent = None):
29 """
30 Constructor
31
32 @param parent The parent widget (QWidget).
33 """
34 QDialog.__init__(self, parent)
35 self.setupUi(self)
36
37 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
38 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
39
40 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
41 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
42
43 self.noResults = True
44 self.cancelled = False
45
46 def __resort(self):
47 """
48 Private method to resort the tree.
49 """
50 self.resultList.sortItems(self.resultList.sortColumn(),
51 self.resultList.header().sortIndicatorOrder())
52
53 def __createResultItem(self, file, line, sourcecode):
54 """
55 Private method to create an entry in the result list.
56
57 @param file filename of file (string)
58 @param line linenumber of faulty source (integer or string)
59 @param sourcecode faulty line of code (string)
60 """
61 itm = QTreeWidgetItem(self.resultList, [file, str(line), sourcecode])
62 itm.setTextAlignment(1, Qt.AlignRight)
63
64 def start(self, fn):
65 """
66 Public slot to start the tabnanny check.
67
68 @param fn File or list of files or directory to be checked
69 (string or list of strings)
70 """
71 if type(fn) is types.ListType:
72 files = fn
73 elif os.path.isdir(fn):
74 files = Utilities.direntries(fn, 1, '*.py', 0)
75 files += Utilities.direntries(fn, 1, '*.pyw', 0)
76 files += Utilities.direntries(fn, 1, '*.ptl', 0)
77 else:
78 files = [fn]
79 files = [f for f in files \
80 if f.endswith(".py") or f.endswith(".pyw") or f.endswith(".ptl")]
81
82 if len(files) > 0:
83 self.checkProgress.setMaximum(len(files))
84 QApplication.processEvents()
85
86 # now go through all the files
87 progress = 0
88 for file in files:
89 if self.cancelled:
90 return
91
92 nok, fname, line, error = Tabnanny.check(file)
93 if nok:
94 self.noResults = False
95 self.__createResultItem(fname, line, error.rstrip()[1:-1])
96 progress += 1
97 self.checkProgress.setValue(progress)
98 QApplication.processEvents()
99 self.__resort()
100 else:
101 self.checkProgress.setMaximum(1)
102 self.checkProgress.setValue(1)
103 self.__finish()
104
105 def __finish(self):
106 """
107 Private slot called when the action or the user pressed the button.
108 """
109 self.cancelled = True
110 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
111 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
112 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
113
114 if self.noResults:
115 self.__createResultItem(self.trUtf8('No indentation errors found.'), "", "")
116 QApplication.processEvents()
117 self.resultList.header().resizeSections(QHeaderView.ResizeToContents)
118 self.resultList.header().setStretchLastSection(True)
119
120 def on_buttonBox_clicked(self, button):
121 """
122 Private slot called by a button of the button box clicked.
123
124 @param button button that was clicked (QAbstractButton)
125 """
126 if button == self.buttonBox.button(QDialogButtonBox.Close):
127 self.close()
128 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
129 self.__finish()
130
131 def on_resultList_itemActivated(self, itm, col):
132 """
133 Private slot to handle the activation of an item.
134
135 @param itm reference to the activated item (QTreeWidgetItem)
136 @param col column the item was activated in (integer)
137 """
138 if self.noResults:
139 return
140
141 fn = Utilities.normabspath(itm.text(0))
142 lineno = int(itm.text(1))
143
144 e4App().getObject("ViewManager").openSourceFile(fn, lineno)

eric ide

mercurial