Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py

changeset 4237
ff8a3e769fca
parent 4021
195a471c327b
child 4278
ccd1e13cb9bd
equal deleted inserted replaced
4236:8d4e498a7af8 4237:ff8a3e769fca
15 pass 15 pass
16 16
17 import os 17 import os
18 import fnmatch 18 import fnmatch
19 19
20 from PyQt5.QtCore import pyqtSlot, Qt 20 from PyQt5.QtCore import pyqtSlot, Qt, QTimer
21 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \ 21 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem, \
22 QApplication, QHeaderView 22 QApplication, QHeaderView
23 23
24 from E5Gui.E5Application import e5App 24 from E5Gui.E5Application import e5App
25 25
49 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 49 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
50 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 50 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
51 51
52 self.indentCheckService = indentCheckService 52 self.indentCheckService = indentCheckService
53 self.indentCheckService.indentChecked.connect(self.__processResult) 53 self.indentCheckService.indentChecked.connect(self.__processResult)
54 self.indentCheckService.batchFinished.connect(self.__batchFinished)
54 self.filename = None 55 self.filename = None
55 56
56 self.noResults = True 57 self.noResults = True
57 self.cancelled = False 58 self.cancelled = False
59 self.__finished = True
58 60
59 self.__fileList = [] 61 self.__fileList = []
60 self.__project = None 62 self.__project = None
61 self.filterFrame.setVisible(False) 63 self.filterFrame.setVisible(False)
62 64
139 if len(self.files) > 0: 141 if len(self.files) > 0:
140 self.checkProgress.setMaximum(len(self.files)) 142 self.checkProgress.setMaximum(len(self.files))
141 self.checkProgress.setVisible(len(self.files) > 1) 143 self.checkProgress.setVisible(len(self.files) > 1)
142 self.checkProgressLabel.setVisible(len(self.files) > 1) 144 self.checkProgressLabel.setVisible(len(self.files) > 1)
143 QApplication.processEvents() 145 QApplication.processEvents()
144 146
145 # now go through all the files 147 # now go through all the files
146 self.progress = 0 148 self.progress = 0
147 self.check() 149 self.files.sort()
150 if len(self.files) == 1:
151 self.__batch = False
152 self.check()
153 else:
154 self.__batch = True
155 self.checkBatch()
148 156
149 def check(self, codestring=''): 157 def check(self, codestring=''):
150 """ 158 """
151 Public method to start a style check for one file. 159 Public method to start an indentation check for one file.
152 160
153 The results are reported to the __processResult slot. 161 The results are reported to the __processResult slot.
154 @keyparam codestring optional sourcestring (str) 162 @keyparam codestring optional sourcestring (str)
155 """ 163 """
156 if not self.files: 164 if not self.files:
180 self.progress += 1 188 self.progress += 1
181 # Continue with next file 189 # Continue with next file
182 self.check() 190 self.check()
183 return 191 return
184 192
193 self.__finished = False
185 self.indentCheckService.indentCheck( 194 self.indentCheckService.indentCheck(
186 None, self.filename, self.source) 195 None, self.filename, self.source)
187 196
197 def checkBatch(self):
198 """
199 Public method to start an indentation check batch job.
200
201 The results are reported to the __processResult slot.
202 """
203 self.__lastFileItem = None
204
205 self.checkProgressLabel.setPath(self.tr("Preparing files..."))
206 progress = 0
207
208 argumentsList = []
209 for filename in self.files:
210 progress += 1
211 self.checkProgress.setValue(progress)
212 QApplication.processEvents()
213
214 try:
215 source = Utilities.readEncodedFile(filename)[0]
216 source = Utilities.normalizeCode(source)
217 except (UnicodeError, IOError) as msg:
218 self.noResults = False
219 self.__createResultItem(
220 filename, 1,
221 "Error: {0}".format(str(msg)).rstrip())
222 continue
223
224 argumentsList.append((filename, source))
225
226 # reset the progress bar to the checked files
227 self.checkProgress.setValue(self.progress)
228 QApplication.processEvents()
229
230 self.__finished = False
231 self.indentCheckService.indentBatchCheck(argumentsList)
232
233 def __batchFinished(self):
234 """
235 Private slot handling the completion of a batch job.
236 """
237 self.checkProgressLabel.setPath("")
238 self.checkProgress.setMaximum(1)
239 self.checkProgress.setValue(1)
240 self.__finish()
241
188 def __processResult(self, fn, nok, line, error): 242 def __processResult(self, fn, nok, line, error):
189 """ 243 """
190 Private slot called after perfoming a style check on one file. 244 Private slot called after perfoming a style check on one file.
191 245
192 @param fn filename of the just checked file (str) 246 @param fn filename of the just checked file (str)
193 @param nok flag if a problem was found (bool) 247 @param nok flag if a problem was found (bool)
194 @param line line number (str) 248 @param line line number (str)
195 @param error text of the problem (str) 249 @param error text of the problem (str)
196 """ 250 """
197 # Check if it's the requested file, otherwise ignore signal 251 if self.__finished:
198 if fn != self.filename: 252 return
253
254 # Check if it's the requested file, otherwise ignore signal if not
255 # in batch mode
256 if not self.__batch and fn != self.filename:
199 return 257 return
200 258
201 if nok: 259 if nok:
202 self.noResults = False 260 self.noResults = False
203 self.__createResultItem(fn, line, error.rstrip()) 261 self.__createResultItem(fn, line, error.rstrip())
204 self.progress += 1 262 self.progress += 1
205 263
206 self.checkProgress.setValue(self.progress) 264 self.checkProgress.setValue(self.progress)
207 self.checkProgressLabel.setPath("") 265 self.checkProgressLabel.setPath(fn)
208 QApplication.processEvents() 266 QApplication.processEvents()
209 self.__resort() 267 self.__resort()
210 268
211 self.check() 269 if not self.__batch:
270 self.check()
212 271
213 def __finish(self): 272 def __finish(self):
214 """ 273 """
215 Private slot called when the action or the user pressed the button. 274 Private slot called when the action or the user pressed the button.
216 """ 275 """
217 self.cancelled = True 276 if not self.__finished:
218 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 277 self.__finished = True
219 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 278
220 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 279 self.cancelled = True
221 280 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
222 if self.noResults: 281 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
223 self.__createResultItem( 282 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
224 self.tr('No indentation errors found.'), "", "") 283
225 QApplication.processEvents() 284 if self.noResults:
226 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) 285 self.__createResultItem(
227 self.resultList.header().setStretchLastSection(True) 286 self.tr('No indentation errors found.'), "", "")
228 287 QApplication.processEvents()
229 self.checkProgress.setVisible(False) 288 self.resultList.header().resizeSections(
230 self.checkProgressLabel.setVisible(False) 289 QHeaderView.ResizeToContents)
290 self.resultList.header().setStretchLastSection(True)
291
292 self.checkProgress.setVisible(False)
293 self.checkProgressLabel.setVisible(False)
231 294
232 def on_buttonBox_clicked(self, button): 295 def on_buttonBox_clicked(self, button):
233 """ 296 """
234 Private slot called by a button of the button box clicked. 297 Private slot called by a button of the button box clicked.
235 298
236 @param button button that was clicked (QAbstractButton) 299 @param button button that was clicked (QAbstractButton)
237 """ 300 """
238 if button == self.buttonBox.button(QDialogButtonBox.Close): 301 if button == self.buttonBox.button(QDialogButtonBox.Close):
239 self.close() 302 self.close()
240 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 303 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
241 self.__finish() 304 if self.__batch:
305 self.indentCheckService.cancelIndentBatchCheck()
306 QTimer.singleShot(1000, self.__finish)
307 else:
308 self.__finish()
242 309
243 @pyqtSlot() 310 @pyqtSlot()
244 def on_startButton_clicked(self): 311 def on_startButton_clicked(self):
245 """ 312 """
246 Private slot to start a code metrics run. 313 Private slot to start a code metrics run.

eric ide

mercurial