tobby48 6 лет назад
Родитель
Сommit
3122180a07

+ 60
- 0
src/kr/co/swh/lecture/python/pyqt5/progressbar.py Просмотреть файл

@@ -0,0 +1,60 @@
1
+import sys
2
+from PyQt5.QtWidgets import *
3
+from PyQt5.QtCore import *
4
+
5
+class MyWindow(QMainWindow):
6
+    def __init__(self):
7
+        super().__init__()
8
+        self.initUI()
9
+
10
+    def initUI(self):
11
+        self.setWindowTitle('SWH Academy Window.')
12
+        self.setGeometry(200, 200, 300, 200)
13
+
14
+        self.progressBar1 = QProgressBar(self)
15
+        self.progressBar1.setGeometry(20, 20, 25, 150)
16
+        self.progressBar1.setStyleSheet("QProgressBar { text-align: center; } QProgressBar::chunk { background-color: red; }")
17
+        self.progressBar1.setOrientation(Qt.Vertical)
18
+        self.progressBar1.setMaximum(0)
19
+        self.progressBar1.setMaximum(100)
20
+        self.progressBar1.setValue(0)
21
+        
22
+        self.progressBar2 = QProgressBar(self)
23
+        self.progressBar2.setGeometry(120, 20, 150, 25)
24
+        self.progressBar2.setStyleSheet("QProgressBar { text-align: top; } QProgressBar::chunk { background-color: blue; }")
25
+        self.progressBar2.setOrientation(Qt.Horizontal)
26
+        self.progressBar2.setMaximum(0)
27
+        self.progressBar2.setMaximum(100)
28
+        self.progressBar2.setValue(0)
29
+        
30
+        self.basicTimer = QBasicTimer()
31
+        self.ing = 0
32
+        
33
+        self.button = QPushButton('시작', self)
34
+        self.button.move(150, 130)
35
+        self.button.clicked.connect(self.goProgressBar)
36
+        
37
+    def timerEvent(self, e):
38
+        if self.ing >= 100:
39
+            self.basicTimer.stop()
40
+            self.ing = 0
41
+            self.button.setText('시작')
42
+            return
43
+
44
+        self.ing = self.ing + 1
45
+        self.progressBar1.setValue(self.ing)
46
+        self.progressBar2.setValue(self.ing)
47
+        
48
+    def goProgressBar(self):
49
+        if self.basicTimer.isActive():
50
+            self.basicTimer.stop()
51
+            self.button.setText('시작')
52
+        else:
53
+            self.basicTimer.start(100, self)
54
+            self.button.setText('정지')
55
+        
56
+if __name__ == "__main__":
57
+    app = QApplication(sys.argv)
58
+    window = MyWindow()
59
+    window.show()
60
+    sys.exit(app.exec_())

+ 10
- 0
src/kr/co/swh/lecture/python/pyqt5/webdownload.py Просмотреть файл

@@ -0,0 +1,10 @@
1
+import urllib3
2
+
3
+url = "https://swhacademy.ga:8888/files/codeblocks-17.12mingw-setup.exe"
4
+
5
+fileName = url.split('/')[-1]
6
+u = urllib3.PoolManager().request('GET', url)
7
+fileSize = int(u.info().getheaders("Content-Length")[0])
8
+print("Downloading: %s Bytes: %s" % (fileName, fileSize))
9
+f = open(fileName, 'w')
10
+f.close()