eric6/Project/ProjectResourcesBrowser.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8265
0090cfa83159
--- a/eric6/Project/ProjectResourcesBrowser.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/Project/ProjectResourcesBrowser.py	Sat May 01 14:27:20 2021 +0200
@@ -8,6 +8,7 @@
 """
 
 import os
+import contextlib
 
 from PyQt5.QtCore import QThread, QFileInfo, pyqtSignal, QProcess
 from PyQt5.QtWidgets import QDialog, QApplication, QMenu
@@ -327,7 +328,7 @@
         if not self.project.isOpen():
             return
         
-        try:
+        with contextlib.suppress(Exception):
             categories = self.getSelectedItemsCountCategorized(
                 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem])
             cnt = categories["sum"]
@@ -357,8 +358,6 @@
                         self.backMenu.popup(self.mapToGlobal(coord))
                 else:
                     self.backMenu.popup(self.mapToGlobal(coord))
-        except Exception:           # secok
-            pass
         
     def __showContextMenu(self):
         """
@@ -495,10 +494,8 @@
                     return
             
             try:
-                if self.project.useSystemEol():
-                    newline = None
-                else:
-                    newline = self.project.getEolString()
+                newline = (None if self.project.useSystemEol()
+                           else self.project.getEolString())
                 with open(fname, 'w', encoding="utf-8",
                           newline=newline) as rcfile:
                     rcfile.write('<!DOCTYPE RCC>\n')
@@ -602,10 +599,8 @@
         ):
             ofn = os.path.join(self.project.ppath, self.compiledFile)
             try:
-                if self.project.useSystemEol():
-                    newline = None
-                else:
-                    newline = self.project.getEolString()
+                newline = (None if self.project.useSystemEol()
+                           else self.project.getEolString())
                 with open(ofn, "w", encoding="utf-8", newline=newline) as f:
                     for line in self.buf.splitlines():
                         f.write(line + "\n")
@@ -630,7 +625,7 @@
                 self.tr("Resource Compilation"),
                 self.tr(
                     "The compilation of the resource file failed."),
-                kind=NotificationTypes.Critical,
+                kind=NotificationTypes.CRITICAL,
                 timeout=0)
         self.compileProc = None
         
@@ -648,9 +643,8 @@
         self.buf = ""
         
         if self.project.getProjectLanguage() == "Python3":
-            if self.project.getProjectType() in ["PyQt5", "PyQt5C"]:
-                self.rccCompiler = Utilities.generatePyQtToolPath('pyrcc5')
-            elif self.project.getProjectType() in ["E6Plugin"]:
+            if self.project.getProjectType() in ["PyQt5", "PyQt5C",
+                                                 "E6Plugin"]:
                 self.rccCompiler = Utilities.generatePyQtToolPath('pyrcc5')
             elif self.project.getProjectType() in ["PySide2", "PySide2C"]:
                 self.rccCompiler = Utilities.generatePySideToolPath(
@@ -750,10 +744,9 @@
             progress.setModal(True)
             progress.setMinimumDuration(0)
             progress.setWindowTitle(self.tr("Resources"))
-            i = 0
             
-            for fn in self.project.pdata["RESOURCES"]:
-                progress.setValue(i)
+            for prog, fn in enumerate(self.project.pdata["RESOURCES"]):
+                progress.setValue(prog)
                 if progress.wasCanceled():
                     break
                 proc = self.__compileQRC(fn, True, progress)
@@ -764,8 +757,6 @@
                         QApplication.processEvents()
                 else:
                     break
-                i += 1
-                
             progress.setValue(numResources)
         
     def __compileSelectedResources(self):
@@ -787,10 +778,9 @@
             progress.setModal(True)
             progress.setMinimumDuration(0)
             progress.setWindowTitle(self.tr("Resources"))
-            i = 0
             
-            for fn in files:
-                progress.setValue(i)
+            for prog, fn in enumerate(files):
+                progress.setValue(prog)
                 if progress.wasCanceled():
                     break
                 if not fn.endswith('.ui.h'):
@@ -802,8 +792,6 @@
                             QApplication.processEvents()
                     else:
                         break
-                i += 1
-                
             progress.setValue(numResources)
         
     def __checkResourcesNewer(self, filename, mtime):
@@ -859,13 +847,12 @@
                 self.tr("Abort"), 0, 100, self.tr("%v/%m Resources"))
             progress.setMinimumDuration(0)
             progress.setWindowTitle(self.tr("Resources"))
-            i = 0
             
             # get list of changed resources
             changedResources = []
             progress.setMaximum(len(self.project.pdata["RESOURCES"]))
-            for fn in self.project.pdata["RESOURCES"]:
-                progress.setValue(i)
+            for prog, fn in enumerate(self.project.pdata["RESOURCES"]):
+                progress.setValue(prog)
                 QApplication.processEvents()
                 ifn = os.path.join(self.project.ppath, fn)
                 if self.project.getProjectLanguage() == "Python3":
@@ -880,24 +867,21 @@
                     return
                 if (
                     not os.path.exists(ofn) or
-                    os.stat(ifn).st_mtime > os.stat(ofn).st_mtime
+                    os.stat(ifn).st_mtime > os.stat(ofn).st_mtime or
+                    self.__checkResourcesNewer(ifn, os.stat(ofn).st_mtime)
                 ):
                     changedResources.append(fn)
-                elif self.__checkResourcesNewer(ifn, os.stat(ofn).st_mtime):
-                    changedResources.append(fn)
-                i += 1
-            progress.setValue(i)
+            progress.setValue(len(self.project.pdata["RESOURCES"]))
             QApplication.processEvents()
             
             if changedResources:
                 progress.setLabelText(
                     self.tr("Compiling changed resources..."))
                 progress.setMaximum(len(changedResources))
-                i = 0
-                progress.setValue(i)
+                progress.setValue(0)
                 QApplication.processEvents()
-                for fn in changedResources:
-                    progress.setValue(i)
+                for prog, fn in enumerate(changedResources):
+                    progress.setValue(prog)
                     if progress.wasCanceled():
                         break
                     proc = self.__compileQRC(fn, True, progress)
@@ -908,7 +892,6 @@
                             QApplication.processEvents()
                     else:
                         break
-                    i += 1
                 progress.setValue(len(changedResources))
                 QApplication.processEvents()
         

eric ide

mercurial