|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a TaskHandle class with a progress dialog. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication |
|
13 from PyQt5.QtWidgets import QLabel |
|
14 |
|
15 from E5Gui.E5ProgressDialog import E5ProgressDialog |
|
16 |
|
17 |
|
18 class RopeProgressDialog(E5ProgressDialog): |
|
19 """ |
|
20 Class implementing TaskHandle with a progress dialog. |
|
21 """ |
|
22 def __init__(self, server, title, interruptable=True, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param server reference to the JSON server |
|
27 @type JsonServer |
|
28 @param title title for the dialog |
|
29 @type str |
|
30 @param interruptable flag indicating, that the task may be |
|
31 interrupted |
|
32 @type bool |
|
33 @param parent reference to the parent widget |
|
34 @type QWidget |
|
35 """ |
|
36 if interruptable: |
|
37 cancelLabel = self.tr("Interrupt") |
|
38 else: |
|
39 cancelLabel = "" |
|
40 barFormat = self.tr("%v/%m files") |
|
41 super(RopeProgressDialog, self).__init__("", cancelLabel, 0, 1, |
|
42 barFormat, parent) |
|
43 label = QLabel("") |
|
44 label.setWordWrap(True) |
|
45 self.setLabel(label) |
|
46 self.setWindowTitle(self.tr("eric6 - {0}").format(title)) |
|
47 |
|
48 self.__server = server |
|
49 |
|
50 def updateProgress(self, params): |
|
51 """ |
|
52 Public slot to handle the task progress. |
|
53 |
|
54 @param params dictionary containing the data to be set |
|
55 @type dict |
|
56 """ |
|
57 if params: |
|
58 self.setLabelText(params["Text"]) |
|
59 if "Maximum" in params: |
|
60 # these are always sent together |
|
61 self.setMaximum(params["Maximum"]) |
|
62 self.setValue(params["Value"]) |
|
63 |
|
64 QCoreApplication.processEvents() |
|
65 |
|
66 if self.wasCanceled(): |
|
67 self.__server.sendJson("AbortAction", {}) |