RefactoringRope/ProgressHandle.py

branch
server_client_variant
changeset 164
121d426d4ed7
parent 147
3f8a995f6e49
child 167
3c8e875d0326
equal deleted inserted replaced
163:6a9e7b37a18b 164:121d426d4ed7
7 Module implementing a TaskHandle class with a progress dialog. 7 Module implementing a TaskHandle class with a progress dialog.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import QCoreApplication
13 from PyQt5.QtWidgets import QApplication, QLabel
14
15 import rope.base.taskhandle 12 import rope.base.taskhandle
16 13
17 14
18 class ProgressHandle(rope.base.taskhandle.TaskHandle): 15 class ProgressHandle(rope.base.taskhandle.TaskHandle):
19 """ 16 """
20 Class implementing TaskHandle with a progress dialog. 17 Class implementing TaskHandle with a progress dialog.
21 """ 18 """
22 def __init__(self, title, interruptable=True, parent=None): 19 def __init__(self, client, title, interruptable=True):
23 """ 20 """
24 Constructor 21 Constructor
25 22
26 @param title title for the taskhandle (string) 23 @param client reference to the JSON client
24 @type JsonClient
25 @param title title for the taskhandle
26 @type str
27 @param interruptable flag indicating, that the task may be 27 @param interruptable flag indicating, that the task may be
28 interrupted (boolean) 28 interrupted
29 @param parent reference to the parent widget (QWidget) 29 @type bool
30 """ 30 """
31 rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable) 31 rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable)
32 if interruptable: 32
33 cancelLabel = QCoreApplication.translate( 33 self.__client = client
34 "ProgressHandle", "Interrupt") 34
35 else: 35 self.__client.sendJson("ProgressInit", {
36 cancelLabel = "" 36 "Title": title,
37 barFormat = QCoreApplication.translate("ProgressHandle", "%v/%m files") 37 "Interrutable": interruptable,
38 try: 38 })
39 from E5Gui.E5ProgressDialog import E5ProgressDialog 39
40 self.__progress = E5ProgressDialog("", cancelLabel, 0, 1,
41 barFormat, parent)
42 except ImportError:
43 from PyQt5.QtWidgets import QProgressDialog, QProgressBar
44 self.__progress = QProgressDialog("", cancelLabel, 0, 1, parent)
45 bar = QProgressBar(self.__progress)
46 bar.setFormat(barFormat)
47 self.__progress.setBar(bar)
48 label = QLabel("")
49 label.setWordWrap(True)
50 self.__progress.setLabel(label)
51 self.__progress.setWindowTitle(
52 QCoreApplication.translate("ProgressHandle", "eric6 - {0}")
53 .format(title))
54 self.add_observer(self.__updateProgress) 40 self.add_observer(self.__updateProgress)
55 41
56 def __updateProgress(self): 42 def __updateProgress(self):
57 """ 43 """
58 Private slot to handle the task progress. 44 Private slot to handle the task progress.
62 text = '' 48 text = ''
63 if jobset.get_name() is not None: 49 if jobset.get_name() is not None:
64 text += jobset.get_name() 50 text += jobset.get_name()
65 if jobset.get_active_job_name() is not None: 51 if jobset.get_active_job_name() is not None:
66 text += ': ' + jobset.get_active_job_name() 52 text += ': ' + jobset.get_active_job_name()
67 self.__progress.setLabelText(text) 53 params = {
54 "Text": text,
55 }
68 if jobset.count is not None: 56 if jobset.count is not None:
69 self.__progress.setMaximum(jobset.count) 57 params["Maximum"] = jobset.count
70 self.__progress.setValue(jobset.done) 58 params["Value"] = jobset.done
71 QApplication.processEvents() 59 else:
72 if not self.is_stopped() and self.__progress.wasCanceled(): 60 params = {}
73 self.stop() 61
74 62 self.__client.sendJson("Progress", params)
75 def show(self): 63 self.__client.poll()
76 """
77 Public slot to show the progress dialog.
78 """
79 self.__progress.show()
80 64
81 def reset(self): 65 def reset(self):
82 """ 66 """
83 Public slot to reset the progress dialog. 67 Public slot to reset the progress dialog.
84 """ 68 """
85 self.__progress.reset() 69 self.__client.sendJson("ProgressReset", {})
70 self.__client.poll()

eric ide

mercurial