eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 7631
2c7ccb4484bf
parent 7619
ef2b5af23ce7
child 7632
7ac16bf7695b
equal deleted inserted replaced
7630:4010cc7e9c0b 7631:2c7ccb4484bf
139 self.ecHighRiskCombo.addItems( 139 self.ecHighRiskCombo.addItems(
140 CodeStyleCheckerDialog.cryptoBitSelectionsEc) 140 CodeStyleCheckerDialog.cryptoBitSelectionsEc)
141 self.ecMediumRiskCombo.addItems( 141 self.ecMediumRiskCombo.addItems(
142 CodeStyleCheckerDialog.cryptoBitSelectionsEc) 142 CodeStyleCheckerDialog.cryptoBitSelectionsEc)
143 143
144 self.statisticsButton = self.buttonBox.addButton(
145 self.tr("Statistics..."), QDialogButtonBox.ActionRole)
146 self.statisticsButton.setToolTip(
147 self.tr("Press to show some statistics for the last run"))
148 self.statisticsButton.setEnabled(False) 144 self.statisticsButton.setEnabled(False)
149 self.showButton = self.buttonBox.addButton(
150 self.tr("Show"), QDialogButtonBox.ActionRole)
151 self.showButton.setToolTip(
152 self.tr("Press to show all files containing an issue"))
153 self.showButton.setEnabled(False) 145 self.showButton.setEnabled(False)
146 self.cancelButton.setEnabled(True)
154 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 147 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
155 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
156 148
157 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 149 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
158 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) 150 self.resultList.header().setSortIndicator(0, Qt.AscendingOrder)
159 151
160 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus")) 152 self.addBuiltinButton.setIcon(UI.PixmapCache.getIcon("plus"))
408 self.__fileOrFileList = fileList[:] 400 self.__fileOrFileList = fileList[:]
409 self.__project = project 401 self.__project = project
410 self.__forProject = True 402 self.__forProject = True
411 403
412 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 404 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
413 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
414 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 405 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
406 self.cancelButton.setEnabled(False)
415 407
416 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker") 408 self.__data = self.__project.getData("CHECKERSPARMS", "Pep8Checker")
417 if ( 409 if (
418 self.__data is None or 410 self.__data is None or
419 len(self.__data) < 6 411 len(self.__data) < 6
557 self.typedExceptionsCheckBox.setChecked( 549 self.typedExceptionsCheckBox.setChecked(
558 self.__data["SecurityChecker"]["CheckTypedException"]) 550 self.__data["SecurityChecker"]["CheckTypedException"])
559 551
560 self.__cleanupData() 552 self.__cleanupData()
561 553
554 def __prepareProgress(self):
555 """
556 Private method to prepare the progress tab for the next run.
557 """
558 self.progressList.clear()
559 if len(self.files) > 0:
560 self.checkProgress.setMaximum(len(self.files))
561 self.checkProgressLabel.setVisible(len(self.files) > 1)
562 self.checkProgress.setVisible(len(self.files) > 1)
563 if len(self.files) > 1:
564 self.progressList.addItems(self.files)
565
566 QApplication.processEvents()
567
562 def start(self, fn, save=False, repeat=None): 568 def start(self, fn, save=False, repeat=None):
563 """ 569 """
564 Public slot to start the code style check. 570 Public slot to start the code style check.
565 571
566 @param fn file or list of files or directory to be checked 572 @param fn file or list of files or directory to be checked
571 @type None or bool 577 @type None or bool
572 """ 578 """
573 if self.__project is None: 579 if self.__project is None:
574 self.__project = e5App().getObject("Project") 580 self.__project = e5App().getObject("Project")
575 581
576 self.mainWidget.setCurrentWidget(self.runTab) 582 self.mainWidget.setCurrentWidget(self.progressTab)
577 583
578 self.cancelled = False 584 self.cancelled = False
579 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 585 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
580 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 586 self.cancelButton.setEnabled(True)
581 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 587 self.cancelButton.setDefault(True)
582 self.statisticsButton.setEnabled(False) 588 self.statisticsButton.setEnabled(False)
583 self.showButton.setEnabled(False) 589 self.showButton.setEnabled(False)
584 self.fixButton.setEnabled(False) 590 self.fixButton.setEnabled(False)
585 self.startButton.setEnabled(False) 591 self.startButton.setEnabled(False)
586 self.restartButton.setEnabled(False) 592 self.restartButton.setEnabled(False)
601 for ext in extensions: 607 for ext in extensions:
602 self.files.extend(Utilities.direntries( 608 self.files.extend(Utilities.direntries(
603 fn, True, '*{0}'.format(ext), 0)) 609 fn, True, '*{0}'.format(ext), 0))
604 else: 610 else:
605 self.files = [fn] 611 self.files = [fn]
606 612
607 # filter the list depending on the filter string 613 # filter the list depending on the filter string
608 if self.files: 614 if self.files:
609 filterString = self.excludeFilesEdit.text() 615 filterString = self.excludeFilesEdit.text()
610 filterList = [f.strip() for f in filterString.split(",") 616 filterList = [f.strip() for f in filterString.split(",")
611 if f.strip()] 617 if f.strip()]
612 for fileFilter in filterList: 618 for fileFilter in filterList:
613 self.files = [ 619 self.files = [
614 f for f in self.files 620 f for f in self.files
615 if not fnmatch.fnmatch(f, fileFilter.strip()) 621 if not fnmatch.fnmatch(f, fileFilter.strip())
616 ] 622 ]
617 623
618 self.__errorItem = None 624 self.__errorItem = None
619 self.__resetStatistics() 625 self.__resetStatistics()
620 self.__clearErrors(self.files) 626 self.__clearErrors(self.files)
621 self.__cleanupData() 627 self.__cleanupData()
628 self.__prepareProgress()
622 629
623 if len(self.files) > 0: 630 if len(self.files) > 0:
624 self.securityNoteLabel.setVisible( 631 self.securityNoteLabel.setVisible(
625 "S" in self.__getCategories(True, asList=True)) 632 "S" in self.__getCategories(True, asList=True))
626 self.checkProgress.setMaximum(len(self.files))
627 self.checkProgressLabel.setVisible(len(self.files) > 1)
628 self.checkProgress.setVisible(len(self.files) > 1)
629 QApplication.processEvents()
630 633
631 # extract the configuration values 634 # extract the configuration values
632 excludeMessages = self.__assembleExcludeMessages() 635 excludeMessages = self.__assembleExcludeMessages()
633 includeMessages = self.includeMessagesEdit.text() 636 includeMessages = self.includeMessagesEdit.text()
634 repeatMessages = self.repeatCheckBox.isChecked() 637 repeatMessages = self.repeatCheckBox.isChecked()
713 # now go through all the files 716 # now go through all the files
714 self.progress = 0 717 self.progress = 0
715 self.files.sort() 718 self.files.sort()
716 if len(self.files) == 1: 719 if len(self.files) == 1:
717 self.__batch = False 720 self.__batch = False
721 self.mainWidget.setCurrentWidget(self.resultsTab)
718 self.check() 722 self.check()
719 else: 723 else:
720 self.__batch = True 724 self.__batch = True
721 self.checkBatch() 725 self.checkBatch()
722 else: 726 else:
951 self.__resort() 955 self.__resort()
952 # reenable updates of the list 956 # reenable updates of the list
953 self.resultList.setSortingEnabled(True) 957 self.resultList.setSortingEnabled(True)
954 self.resultList.setUpdatesEnabled(True) 958 self.resultList.setUpdatesEnabled(True)
955 959
960 self.__updateProgress(fn)
961
962 if not self.__batch:
963 self.check()
964
965 def __updateProgress(self, fn):
966 """
967 Private method to update the progress tab.
968
969 @param fn filename of the just checked file
970 @type str
971 """
956 self.checkProgress.setValue(self.progress) 972 self.checkProgress.setValue(self.progress)
957 self.checkProgressLabel.setPath(fn) 973 self.checkProgressLabel.setPath(fn)
974
975 # remove file from the list of jobs to do
976 fileItems = self.progressList.findItems(fn, Qt.MatchExactly)
977 if fileItems:
978 row = self.progressList.row(fileItems[0])
979 self.progressList.takeItem(row)
980
958 QApplication.processEvents() 981 QApplication.processEvents()
959
960 if not self.__batch:
961 self.check()
962 982
963 def __finish(self): 983 def __finish(self):
964 """ 984 """
965 Private slot called when the code style check finished or the user 985 Private slot called when the code style check finished or the user
966 pressed the cancel button. 986 pressed the cancel button.
968 if not self.__finished: 988 if not self.__finished:
969 self.__finished = True 989 self.__finished = True
970 990
971 self.cancelled = True 991 self.cancelled = True
972 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 992 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
973 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
974 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 993 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
994 self.cancelButton.setEnabled(False)
975 self.statisticsButton.setEnabled(True) 995 self.statisticsButton.setEnabled(True)
976 self.showButton.setEnabled(True) 996 self.showButton.setEnabled(True)
977 self.startButton.setEnabled(True) 997 self.startButton.setEnabled(True)
978 self.restartButton.setEnabled(True) 998 self.restartButton.setEnabled(True)
979 999
993 QHeaderView.ResizeToContents) 1013 QHeaderView.ResizeToContents)
994 self.resultList.header().setStretchLastSection(True) 1014 self.resultList.header().setStretchLastSection(True)
995 1015
996 self.checkProgress.setVisible(False) 1016 self.checkProgress.setVisible(False)
997 self.checkProgressLabel.setVisible(False) 1017 self.checkProgressLabel.setVisible(False)
1018
1019 self.mainWidget.setCurrentWidget(self.resultsTab)
998 1020
999 def __getEol(self, fn): 1021 def __getEol(self, fn):
1000 """ 1022 """
1001 Private method to get the applicable eol string. 1023 Private method to get the applicable eol string.
1002 1024
1546 SecurityDefaults["check_typed_exception"]) 1568 SecurityDefaults["check_typed_exception"])
1547 1569
1548 # Update UI with default values 1570 # Update UI with default values
1549 self.on_loadDefaultButton_clicked() 1571 self.on_loadDefaultButton_clicked()
1550 1572
1573 @pyqtSlot()
1574 def on_cancelButton_clicked(self):
1575 """
1576 Private slot to handle the "Cancel" button press.
1577 """
1578 if self.__batch:
1579 self.styleCheckService.cancelStyleBatchCheck()
1580 QTimer.singleShot(1000, self.__finish)
1581 else:
1582 self.__finish()
1583
1551 @pyqtSlot(QAbstractButton) 1584 @pyqtSlot(QAbstractButton)
1552 def on_buttonBox_clicked(self, button): 1585 def on_buttonBox_clicked(self, button):
1553 """ 1586 """
1554 Private slot called by a button of the button box clicked. 1587 Private slot called by a button of the button box clicked.
1555 1588
1556 @param button button that was clicked 1589 @param button button that was clicked
1557 @type QAbstractButton 1590 @type QAbstractButton
1558 """ 1591 """
1559 if button == self.buttonBox.button(QDialogButtonBox.Close): 1592 if button == self.buttonBox.button(QDialogButtonBox.Close):
1560 self.close() 1593 self.close()
1561 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
1562 if self.__batch:
1563 self.styleCheckService.cancelStyleBatchCheck()
1564 QTimer.singleShot(1000, self.__finish)
1565 else:
1566 self.__finish()
1567 elif button == self.showButton:
1568 self.on_showButton_clicked()
1569 elif button == self.statisticsButton:
1570 self.on_statisticsButton_clicked()
1571 1594
1572 def __clearErrors(self, files): 1595 def __clearErrors(self, files):
1573 """ 1596 """
1574 Private method to clear all warning markers of open editors to be 1597 Private method to clear all warning markers of open editors to be
1575 checked. 1598 checked.

eric ide

mercurial