Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py

branch
BgService
changeset 3414
448cfee96f45
parent 3145
a9de05d4a22f
child 3456
96232974dcdb
equal deleted inserted replaced
3413:5e63f809732a 3414:448cfee96f45
8 process. 8 process.
9 """ 9 """
10 10
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 try: 12 try:
13 str = unicode # __IGNORE_WARNING__ 13 str = unicode
14 except (NameError): 14 except (NameError):
15 pass 15 pass
16 16
17 import os 17 import os
18 import fnmatch 18 import fnmatch
31 31
32 class TabnannyDialog(QDialog, Ui_TabnannyDialog): 32 class TabnannyDialog(QDialog, Ui_TabnannyDialog):
33 """ 33 """
34 Class implementing a dialog to show the results of the tabnanny check run. 34 Class implementing a dialog to show the results of the tabnanny check run.
35 """ 35 """
36 def __init__(self, parent=None): 36 def __init__(self, indentCheckService, parent=None):
37 """ 37 """
38 Constructor 38 Constructor
39 39
40 @param indentCheckService reference to the service (IndentCheckService)
40 @param parent The parent widget (QWidget). 41 @param parent The parent widget (QWidget).
41 """ 42 """
42 super(TabnannyDialog, self).__init__(parent) 43 super(TabnannyDialog, self).__init__(parent)
43 self.setupUi(self) 44 self.setupUi(self)
44 45
45 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 46 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
46 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 47 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
47 48
48 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 49 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
49 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 50 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
51
52 self.indentCheckService = indentCheckService
53 self.indentCheckService.indentChecked.connect(self.__processResult)
54 self.filename = None
50 55
51 self.noResults = True 56 self.noResults = True
52 self.cancelled = False 57 self.cancelled = False
53 58
54 self.__fileList = [] 59 self.__fileList = []
118 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 123 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
119 self.checkProgress.setVisible(True) 124 self.checkProgress.setVisible(True)
120 QApplication.processEvents() 125 QApplication.processEvents()
121 126
122 if isinstance(fn, list): 127 if isinstance(fn, list):
123 files = fn 128 self.files = fn
124 elif os.path.isdir(fn): 129 elif os.path.isdir(fn):
125 files = [] 130 self.files = []
126 extensions = set(Preferences.getPython("PythonExtensions") + 131 extensions = set(Preferences.getPython("PythonExtensions") +
127 Preferences.getPython("Python3Extensions")) 132 Preferences.getPython("Python3Extensions"))
128 for ext in extensions: 133 for ext in extensions:
129 files.extend( 134 self.files.extend(
130 Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) 135 Utilities.direntries(fn, True, '*{0}'.format(ext), 0))
131 else: 136 else:
132 files = [fn] 137 self.files = [fn]
133 138
134 if len(files) > 0: 139 if len(self.files) > 0:
135 self.checkProgress.setMaximum(len(files)) 140 self.checkProgress.setMaximum(len(self.files))
136 self.checkProgress.setVisible(len(files) > 1) 141 self.checkProgress.setVisible(len(self.files) > 1)
137 self.checkProgressLabel.setVisible(len(files) > 1) 142 self.checkProgressLabel.setVisible(len(self.files) > 1)
138 QApplication.processEvents() 143 QApplication.processEvents()
139 144
140 # now go through all the files 145 # now go through all the files
141 progress = 0 146 self.progress = 0
142 for file in files: 147 self.check()
143 self.checkProgress.setValue(progress) 148
144 self.checkProgressLabel.setPath(file) 149 def check(self, codestring=''):
145 QApplication.processEvents() 150 """
146 self.__resort() 151 Start a style check for one file.
147 152
148 if self.cancelled: 153 The results are reported to the __processResult slot.
149 return 154 @keyparam codestring optional sourcestring (str)
150 155 """
151 try: 156 if not self.files:
152 source = Utilities.readEncodedFile(file)[0]
153 source = Utilities.normalizeCode(source)
154 except (UnicodeError, IOError) as msg:
155 self.noResults = False
156 self.__createResultItem(
157 file, 1,
158 "Error: {0}".format(str(msg)).rstrip()[1:-1])
159 progress += 1
160 continue
161
162 from . import Tabnanny
163 nok, fname, line, error = Tabnanny.check(file, source)
164 if nok:
165 self.noResults = False
166 self.__createResultItem(fname, line, error.rstrip())
167 progress += 1
168
169 self.checkProgress.setValue(progress)
170 self.checkProgressLabel.setPath("") 157 self.checkProgressLabel.setPath("")
171 QApplication.processEvents()
172 self.__resort()
173 else:
174 self.checkProgress.setMaximum(1) 158 self.checkProgress.setMaximum(1)
175 self.checkProgress.setValue(1) 159 self.checkProgress.setValue(1)
176 self.__finish() 160 self.__finish()
177 161 return
162
163 self.filename = self.files.pop(0)
164 self.checkProgress.setValue(self.progress)
165 self.checkProgressLabel.setPath(self.filename)
166 QApplication.processEvents()
167 self.__resort()
168
169 if self.cancelled:
170 return
171
172 try:
173 self.source = Utilities.readEncodedFile(self.filename)[0]
174 self.source = Utilities.normalizeCode(self.source)
175 except (UnicodeError, IOError) as msg:
176 self.noResults = False
177 self.__createResultItem(
178 self.filename, 1,
179 "Error: {0}".format(str(msg)).rstrip())
180 self.progress += 1
181 # Continue with next file
182 self.check()
183 return
184
185 self.indentCheckService.indentCheck(
186 None, self.filename, self.source)
187
188 def __processResult(self, fn, nok, line, error):
189 """
190 Privat slot called after perfoming a style check on one file.
191
192 @param fn filename of the just checked file (str)
193 @param nok flag if a problem was found (bool)
194 @param line line number (str)
195 @param error text of the problem (str)
196 """
197 # Check if it's the requested file, otherwise ignore signal
198 if fn != self.filename:
199 return
200
201 if nok:
202 self.noResults = False
203 self.__createResultItem(fn, line, error.rstrip())
204 self.progress += 1
205
206 self.checkProgress.setValue(self.progress)
207 self.checkProgressLabel.setPath("")
208 QApplication.processEvents()
209 self.__resort()
210
211 self.check()
212
178 def __finish(self): 213 def __finish(self):
179 """ 214 """
180 Private slot called when the action or the user pressed the button. 215 Private slot called when the action or the user pressed the button.
181 """ 216 """
182 self.cancelled = True 217 self.cancelled = True

eric ide

mercurial