RefactoringRope/ProgressHandle.py

changeset 2
fc72a5b922a6
child 20
83b71483e198
equal deleted inserted replaced
1:9f687137a929 2:fc72a5b922a6
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a TaskHandle class with a progress dialog.
8 """
9
10 from PyQt4.QtGui import QApplication, QProgressDialog, QLabel
11
12 import rope.base.taskhandle
13
14 class ProgressHandle(rope.base.taskhandle.TaskHandle):
15 """
16 Class implementing TaskHandle with a progress dialog.
17 """
18 def __init__(self, title, interruptable=True, parent=None):
19 """
20 Constructor
21
22 @param title title for the taskhandle (string)
23 @param interruptable flag indicating, that the task may be
24 interrupted (boolean)
25 @param parent reference to the parent widget (QWidget)
26 """
27 rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable)
28 if interruptable:
29 cancelLabel = QApplication.translate("ProgressHandle","Interrupt")
30 else:
31 cancelLabel = ""
32 self.__progress = QProgressDialog("", cancelLabel, 0, 100, parent)
33 label = QLabel("")
34 label.setWordWrap(True)
35 self.__progress.setLabel(label)
36 self.add_observer(self.__updateProgress)
37
38 def __updateProgress(self):
39 """
40 Private slot to handle the task progress.
41 """
42 jobset = self.current_jobset()
43 if jobset:
44 text = ''
45 if jobset.get_name() is not None:
46 text += jobset.get_name()
47 if jobset.get_active_job_name() is not None:
48 text += ' : ' + jobset.get_active_job_name()
49 self.__progress.setLabelText(text)
50 percent = jobset.get_percent_done()
51 if percent is not None:
52 self.__progress.setValue(percent)
53 QApplication.processEvents()
54 if not self.is_stopped() and self.__progress.wasCanceled():
55 self.stop()
56
57 def show(self):
58 """
59 Public slot to show the progress dialog.
60 """
61 self.__progress.show()
62
63 def reset(self):
64 """
65 Public slot to reset the progress dialog.
66 """
67 self.__progress.reset()

eric ide

mercurial