forked from jacklam718/PyQt-ProgressDialog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQtProgressDialog.py
More file actions
executable file
·124 lines (101 loc) · 3.89 KB
/
QtProgressDialog.py
File metadata and controls
executable file
·124 lines (101 loc) · 3.89 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# --*--codig: utf8 --*--
from PyQt4 import QtGui
from PyQt4 import QtCore
class BaseProgressDialog(QtGui.QWidget):
updateProgress = QtCore.pyqtSignal(str)
def __init__(self, text='', parent=None):
super(BaseProgressDialog, self).__init__(parent)
self.setFixedHeight(50)
self.text = text
self.progressbar = QtGui.QProgressBar( )
self.progressbar.setTextVisible(True)
self.updateProgress.connect(self.setValue)
self.bottomBorder = QtGui.QWidget( )
self.bottomBorder.setStyleSheet("""
background: palette(shadow);
""")
self.bottomBorder.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed))
self.bottomBorder.setMinimumHeight(1)
self.label = QtGui.QLabel(self.text)
self.label.setStyleSheet("""
font-weight: bold;
""")
self.layout = QtGui.QVBoxLayout( )
self.layout.setContentsMargins(10,0,10,0)
self.layout.addWidget(self.label)
self.layout.addWidget(self.progressbar)
self.mainLayout = QtGui.QVBoxLayout( )
self.mainLayout.setContentsMargins(0,0,0,0)
self.mainLayout.addLayout(self.layout)
self.mainLayout.addWidget(self.bottomBorder)
self.setLayout(self.mainLayout)
self.totalValue = 0
def setValue(self, value):
self.totalValue += len(value)
self.progressbar.setValue(self.totalValue)
def setMax(self, value):
self.progressbar.setMaximum(value)
class DownloadProgressBar(BaseProgressDialog):
def __init__(self, text='Downloading', parent=None):
super(self.__class__, self).__init__(text, parent)
style ="""
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center;
}
QProgressBar::chunk {
background-color: #37DA7E;
width: 20px;
}"""
self.progressbar.setStyleSheet(style)
class UploadProgressBar(BaseProgressDialog):
def __init__(self, text='Uploading', parent=None):
super(self.__class__, self).__init__(text, parent)
style ="""
QProgressBar {
border: 2px solid grey;
border-radius: 5px;
text-align: center;
}
QProgressBar::chunk {
background-color: #88B0EB;
width: 20px;
}"""
self.progressbar.setStyleSheet(style)
class ProgressDialog(QtGui.QMainWindow):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
self.resize(500, 250)
self.scrollArea = QtGui.QScrollArea( )
self.scrollArea.setWidgetResizable(True)
self.setCentralWidget(self.scrollArea)
self.centralWidget = QtGui.QWidget( )
self.scrollArea.setWidget(self.centralWidget)
self.layout = QtGui.QVBoxLayout( )
self.layout.setAlignment(QtCore.Qt.AlignTop)
self.layout.setContentsMargins(0,10,0,0)
self.centralWidget.setLayout(self.layout)
def addProgressbar(self, progressbar):
self.layout.addWidget(progressbar)
if __name__ == "__main__":
import random
app = QtGui.QApplication([])
progressNumbers = [x for x in range(1, 101)]
progressItems = []
while len(progressItems) <= 20:
progressItems.append(random.choice(progressNumbers))
progressDialog = ProgressDialog()
for progressItem in progressItems:
progressBar = DownloadProgressBar(text="download")
progressBar.setMax(100)
progressBar.setValue(' ' * progressItem)
progressDialog.addProgressbar(progressBar)
for progressItem in progressItems:
progressBar = UploadProgressBar(text="Upload")
progressBar.setMax(100)
progressBar.setValue(' ' * progressItem)
progressDialog.addProgressbar(progressBar)
progressDialog.show()
app.exec_()