RefactoringRope/ProgressHandle.py

changeset 2
fc72a5b922a6
child 20
83b71483e198
diff -r 9f687137a929 -r fc72a5b922a6 RefactoringRope/ProgressHandle.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RefactoringRope/ProgressHandle.py	Sat Jan 29 13:38:30 2011 +0100
@@ -0,0 +1,67 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a TaskHandle class with a progress dialog.
+"""
+
+from PyQt4.QtGui import QApplication, QProgressDialog, QLabel
+
+import rope.base.taskhandle
+
+class ProgressHandle(rope.base.taskhandle.TaskHandle):
+    """
+    Class implementing TaskHandle with a progress dialog.
+    """
+    def __init__(self, title, interruptable=True, parent=None):
+        """
+        Constructor
+        
+        @param title title for the taskhandle (string)
+        @param interruptable flag indicating, that the task may be 
+            interrupted (boolean)
+        @param parent reference to the parent widget (QWidget)
+        """
+        rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable)
+        if interruptable:
+            cancelLabel = QApplication.translate("ProgressHandle","Interrupt")
+        else:
+            cancelLabel = ""
+        self.__progress = QProgressDialog("", cancelLabel, 0, 100, parent)
+        label = QLabel("")
+        label.setWordWrap(True)
+        self.__progress.setLabel(label)
+        self.add_observer(self.__updateProgress)
+    
+    def __updateProgress(self):
+        """
+        Private slot to handle the task progress.
+        """
+        jobset = self.current_jobset()
+        if jobset:
+            text = ''
+            if jobset.get_name() is not None:
+                text += jobset.get_name()
+            if jobset.get_active_job_name() is not None:
+                text += ' : ' + jobset.get_active_job_name()
+            self.__progress.setLabelText(text)
+            percent = jobset.get_percent_done()
+            if percent is not None:
+                self.__progress.setValue(percent)
+        QApplication.processEvents()
+        if not self.is_stopped() and self.__progress.wasCanceled():
+            self.stop()
+    
+    def show(self):
+        """
+        Public slot to show the progress dialog.
+        """
+        self.__progress.show()
+    
+    def reset(self):
+        """
+        Public slot to reset the progress dialog.
+        """
+        self.__progress.reset()

eric ide

mercurial