-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.py
More file actions
63 lines (55 loc) · 2.09 KB
/
Copy pathprogressbar.py
File metadata and controls
63 lines (55 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QWidget, QProgressBar, QLabel, QHBoxLayout
class ProgressBarCustom(QWidget):
def __init__(self, filename: str):
super().__init__()
self._filename = filename
self._text_label = QLabel(filename)
self._progressbar = QProgressBar()
self._progressbar_label = QLabel()
layout = QHBoxLayout()
layout.setContentsMargins(10, 0, 10, 0)
self._progressbar.setMaximum(0)
self._progressbar.setValue(0)
self._progressbar.setTextVisible(False)
layout.addWidget(self._text_label)
layout.addWidget(self._progressbar)
layout.addWidget(self._progressbar_label)
self.setLayout(layout)
self.hide()
def _update(self):
self._text_label.setStyleSheet("color: white")
self._text_label.setText(self._filename)
self._progressbar.show()
if self.fvalue == self.fmaximum:
self._progressbar_label.setText(f"{self.fmaximum:.1f} Mo")
else:
self._progressbar_label.setText(
f"{self.fvalue:.1f} / {self.fmaximum:.1f} Mo"
)
self._progressbar_label.show()
self.update()
def setValueAndMax(self, value: int, maximum: int):
self.fvalue = value / 1048576
self.fmaximum = maximum / 1048576
self._progressbar.setValue(value)
self._progressbar.setMaximum(maximum)
self._update()
@Slot(str)
def showInformationText(self, text: str):
self._progressbar.hide()
self._progressbar_label.hide()
self._text_label.setStyleSheet("color: blue")
self._text_label.setText(text)
@Slot(str)
def showErrorText(self, error: str):
self._progressbar.hide()
self._progressbar_label.hide()
self._text_label.setStyleSheet("color: red")
self._text_label.setText(error)
@Slot()
def showDoneText(self):
self._progressbar.hide()
self._progressbar_label.hide()
self._text_label.setStyleSheet("color: green")
self._text_label.setText("Done!")