2 |
2 |
3 # Copyright (c) 2003 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2003 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show the output of the tabnanny command process. |
7 Module implementing a dialog to show the output of the tabnanny command |
|
8 process. |
8 """ |
9 """ |
9 |
10 |
10 import os |
11 import os |
11 import fnmatch |
12 import fnmatch |
12 |
13 |
13 from PyQt4.QtCore import pyqtSlot, Qt, QProcess |
14 from PyQt4.QtCore import pyqtSlot, Qt, QProcess |
14 from PyQt4.QtGui import QDialog, QDialogButtonBox, QTreeWidgetItem, QApplication, \ |
15 from PyQt4.QtGui import QDialog, QDialogButtonBox, QTreeWidgetItem, \ |
15 QHeaderView |
16 QApplication, QHeaderView |
16 |
17 |
17 from E5Gui.E5Application import e5App |
18 from E5Gui.E5Application import e5App |
18 |
19 |
19 from .Ui_TabnannyDialog import Ui_TabnannyDialog |
20 from .Ui_TabnannyDialog import Ui_TabnannyDialog |
20 |
21 |
52 |
53 |
53 def __resort(self): |
54 def __resort(self): |
54 """ |
55 """ |
55 Private method to resort the tree. |
56 Private method to resort the tree. |
56 """ |
57 """ |
57 self.resultList.sortItems(self.resultList.sortColumn(), |
58 self.resultList.sortItems( |
58 self.resultList.header().sortIndicatorOrder()) |
59 self.resultList.sortColumn(), |
|
60 self.resultList.header().sortIndicatorOrder()) |
59 |
61 |
60 def __createResultItem(self, file, line, sourcecode): |
62 def __createResultItem(self, file, line, sourcecode): |
61 """ |
63 """ |
62 Private method to create an entry in the result list. |
64 Private method to create an entry in the result list. |
63 |
65 |
111 if isinstance(fn, list): |
113 if isinstance(fn, list): |
112 files = fn |
114 files = fn |
113 elif os.path.isdir(fn): |
115 elif os.path.isdir(fn): |
114 files = [] |
116 files = [] |
115 for ext in Preferences.getPython("Python3Extensions"): |
117 for ext in Preferences.getPython("Python3Extensions"): |
116 files.extend(Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
118 files.extend( |
|
119 Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
117 for ext in Preferences.getPython("PythonExtensions"): |
120 for ext in Preferences.getPython("PythonExtensions"): |
118 files.extend(Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
121 files.extend( |
|
122 Utilities.direntries(fn, 1, '*{0}'.format(ext), 0)) |
119 else: |
123 else: |
120 files = [fn] |
124 files = [fn] |
121 py3files = [f for f in files \ |
125 py3files = [f for f in files |
122 if f.endswith(tuple(Preferences.getPython("Python3Extensions")))] |
126 if f.endswith( |
123 py2files = [f for f in files \ |
127 tuple(Preferences.getPython("Python3Extensions")))] |
124 if f.endswith(tuple(Preferences.getPython("PythonExtensions")))] |
128 py2files = [f for f in files |
|
129 if f.endswith( |
|
130 tuple(Preferences.getPython("PythonExtensions")))] |
125 |
131 |
126 if len(py3files) + len(py2files) > 0: |
132 if len(py3files) + len(py2files) > 0: |
127 self.checkProgress.setMaximum(len(py3files) + len(py2files)) |
133 self.checkProgress.setMaximum(len(py3files) + len(py2files)) |
128 QApplication.processEvents() |
134 QApplication.processEvents() |
129 |
135 |
155 file in py2files or \ |
161 file in py2files or \ |
156 (ext in [".py", ".pyw"] and \ |
162 (ext in [".py", ".pyw"] and \ |
157 Preferences.getProject("DeterminePyFromProject") and \ |
163 Preferences.getProject("DeterminePyFromProject") and \ |
158 self.__project.isOpen() and \ |
164 self.__project.isOpen() and \ |
159 self.__project.isProjectFile(file) and \ |
165 self.__project.isProjectFile(file) and \ |
160 self.__project.getProjectLanguage() in ["Python", "Python2"]): |
166 self.__project.getProjectLanguage() in ["Python", |
|
167 "Python2"]): |
161 nok, fname, line, error = self.__py2check(file) |
168 nok, fname, line, error = self.__py2check(file) |
162 else: |
169 else: |
163 from . import Tabnanny |
170 from . import Tabnanny |
164 nok, fname, line, error = Tabnanny.check(file, source) |
171 nok, fname, line, error = Tabnanny.check(file, source) |
165 if nok: |
172 if nok: |
183 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
190 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
184 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
191 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
185 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
192 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
186 |
193 |
187 if self.noResults: |
194 if self.noResults: |
188 self.__createResultItem(self.trUtf8('No indentation errors found.'), "", "") |
195 self.__createResultItem( |
|
196 self.trUtf8('No indentation errors found.'), "", "") |
189 QApplication.processEvents() |
197 QApplication.processEvents() |
190 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) |
198 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) |
191 self.resultList.header().setStretchLastSection(True) |
199 self.resultList.header().setStretchLastSection(True) |
192 |
200 |
193 def on_buttonBox_clicked(self, button): |
201 def on_buttonBox_clicked(self, button): |
238 fn = Utilities.normabspath(itm.text(0)) |
246 fn = Utilities.normabspath(itm.text(0)) |
239 lineno = int(itm.text(1)) |
247 lineno = int(itm.text(1)) |
240 |
248 |
241 e5App().getObject("ViewManager").openSourceFile(fn, lineno) |
249 e5App().getObject("ViewManager").openSourceFile(fn, lineno) |
242 |
250 |
243 ############################################################################ |
251 ########################################################################### |
244 ## Python 2 interface below |
252 ## Python 2 interface below |
245 ############################################################################ |
253 ########################################################################### |
246 |
254 |
247 def __py2check(self, filename): |
255 def __py2check(self, filename): |
248 """ |
256 """ |
249 Private method to perform the indentation check for Python 2 files. |
257 Private method to perform the indentation check for Python 2 files. |
250 |
258 |