eric6/UI/FindFileDialog.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8265
0090cfa83159
--- a/eric6/UI/FindFileDialog.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/UI/FindFileDialog.py	Sat May 01 14:27:20 2021 +0200
@@ -55,7 +55,7 @@
         @param replaceMode flag indicating the replace dialog mode (boolean)
         @param parent parent widget of this dialog (QWidget)
         """
-        super(FindFileDialog, self).__init__(parent)
+        super().__init__(parent)
         self.setupUi(self)
         self.setWindowFlags(Qt.WindowType.Window)
         
@@ -197,7 +197,7 @@
             self.findList.clear()
             self.replacetextCombo.setEditText("")
         
-        super(FindFileDialog, self).show()
+        super().show()
         
     def on_findtextCombo_editTextChanged(self, text):
         """
@@ -438,10 +438,7 @@
         wo = self.wordCheckBox.isChecked()
         cs = self.caseCheckBox.isChecked()
         ct = self.findtextCombo.currentText()
-        if reg:
-            txt = ct
-        else:
-            txt = re.escape(ct)
+        txt = ct if reg else re.escape(ct)
         if wo:
             txt = "\\b{0}\\b".format(txt)
         flags = re.UNICODE
@@ -502,11 +499,10 @@
         # now go through all the files
         self.__populating = True
         self.findList.setUpdatesEnabled(False)
-        progress = 0
         breakSearch = False
         occurrences = 0
         fileOccurrences = 0
-        for file in files:
+        for progress, file in enumerate(files, start=1):
             self.__lastFileItem = None
             found = False
             if self.__cancelSearch or breakSearch:
@@ -514,26 +510,24 @@
             
             self.findProgressLabel.setPath(file)
             
-            if self.projectButton.isChecked():
-                fn = os.path.join(self.project.ppath, file)
-            else:
-                fn = file
+            fn = (
+                os.path.join(self.project.ppath, file)
+                if self.projectButton.isChecked() else
+                file
+            )
             # read the file and split it into textlines
             try:
                 text, encoding, hashStr = Utilities.readEncodedFileWithHash(fn)
                 lines = text.splitlines(True)
             except (UnicodeError, OSError):
-                progress += 1
                 self.findProgress.setValue(progress)
                 continue
             
             # now perform the search and display the lines found
-            count = 0
-            for line in lines:
+            for count, line in enumerate(lines, start=1):
                 if self.__cancelSearch:
                     break
                 
-                count += 1
                 contains = search.search(line)
                 if contains:
                     occurrences += 1
@@ -566,7 +560,6 @@
             
             if found:
                 fileOccurrences += 1
-            progress += 1
             self.findProgress.setValue(progress)
         
         if not files:
@@ -615,10 +608,7 @@
             start = 0
             end = 0
         
-        if self.project:
-            fn = os.path.join(self.project.ppath, file)
-        else:
-            fn = file
+        fn = os.path.join(self.project.ppath, file) if self.project else file
         if fn.endswith('.ui'):
             self.designerFile.emit(fn)
         else:
@@ -678,7 +668,6 @@
         self.findProgress.setMaximum(self.findList.topLevelItemCount())
         self.findProgress.setValue(0)
         
-        progress = 0
         for index in range(self.findList.topLevelItemCount()):
             itm = self.findList.topLevelItem(index)
             if itm.checkState(0) in [Qt.CheckState.PartiallyChecked,
@@ -708,8 +697,7 @@
                             """ Skipping it.</p><p>Reason: {1}</p>""")
                         .format(fn, str(err))
                     )
-                    progress += 1
-                    self.findProgress.setValue(progress)
+                    self.findProgress.setValue(index)
                     continue
                 
                 # Check the original and the current hash. Skip the file,
@@ -724,8 +712,7 @@
                             """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")
                         .format(fn, origHash, hashStr)
                     )
-                    progress += 1
-                    self.findProgress.setValue(progress)
+                    self.findProgress.setValue(index)
                     continue
                 
                 # replace the lines authorized by the user
@@ -750,8 +737,7 @@
                         .format(fn, str(err))
                     )
             
-            progress += 1
-            self.findProgress.setValue(progress)
+            self.findProgress.setValue(index + 1)
         
         self.findProgressLabel.setPath("")
         
@@ -786,10 +772,7 @@
         Private method to copy the path of an entry to the clipboard.
         """
         itm = self.findList.selectedItems()[0]
-        if itm.parent():
-            fn = itm.parent().text(0)
-        else:
-            fn = itm.text(0)
+        fn = itm.parent().text(0) if itm.parent() else itm.text(0)
         
         cb = QApplication.clipboard()
         cb.setText(fn)

eric ide

mercurial