eric6/E5Gui/E5ProcessDialog.py

changeset 7354
d6aec4160f6b
parent 7252
c5e3705073eb
child 7360
9190402e4505
--- a/eric6/E5Gui/E5ProcessDialog.py	Sun Dec 08 12:38:34 2019 +0100
+++ b/eric6/E5Gui/E5ProcessDialog.py	Sun Dec 08 13:07:46 2019 +0100
@@ -9,6 +9,7 @@
 
 
 import os
+import re
 
 from PyQt5.QtCore import (
     QProcess, QTimer, pyqtSlot, Qt, QCoreApplication, QProcessEnvironment
@@ -31,7 +32,8 @@
     shows the output of the process. The dialog is modal,
     which causes a synchronized execution of the process.
     """
-    def __init__(self, outputTitle="", windowTitle="", parent=None):
+    def __init__(self, outputTitle="", windowTitle="", showProgress=False,
+                 parent=None):
         """
         Constructor
         
@@ -39,6 +41,8 @@
         @type str
         @param windowTitle title of the dialog
         @type str
+        @param showProgress flag indicating to show a progress bar
+        @type bool
         @param parent reference to the parent widget
         @type QWidget
         """
@@ -52,8 +56,11 @@
             self.setWindowTitle(windowTitle)
         if outputTitle:
             self.outputGroup.setTitle(outputTitle)
+        self.__showProgress = showProgress
+        self.progressBar.setVisible(self.__showProgress)
         
         self.__process = None
+        self.__progressRe = re.compile(r"""(\d{1,3})\s*%""")
         
         self.show()
         QCoreApplication.processEvents()
@@ -206,6 +213,13 @@
             s = str(self.__process.readAllStandardOutput(),
                     Preferences.getSystem("IOEncoding"),
                     'replace')
+            if self.__showProgress:
+                match = self.__progressRe.search(s)
+                if match:
+                    progress = int(match.group(1))
+                    self.progressBar.setValue(progress)
+                    if not s.endswith("\n"):
+                        s = s + "\n"
             self.resultbox.insertPlainText(s)
             self.resultbox.ensureCursorVisible()
             

eric ide

mercurial