Esempio n. 1
0
class Downloader(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        layout = QVBoxLayout()

        self.url = QLineEdit()
        self.url.setPlaceholderText("URL")
        self.save_location = QLineEdit("File save location")
        self.progressbar = QProgressBar()
        download = QPushButton("Download")

        self.progressbar.setValue(0)
        self.progressbar.setAlignment(Qt.AlignHCenter)
        layout.addWidget(self.url)
        layout.addWidget(self.save_location)
        layout.addWidget(self.progressbar)
        layout.addWidget(download)

        self.setLayout(layout)
        self.setWindowTitle("Python Downloader using PyQt5")
        self.setFocus()

        download.clicked.connect(self.download)

    def download(self):
        url = self.url.text()
        save_location = self.save_location.text()
        urllib.request.urlretrieve(url, save_location, self.report)

    def report(self, blocknum, blocksize, totalsize):
        print(blocknum, blocksize, totalsize)
        readsofar = blocknum * blocksize

        if totalsize > 0:
            percent = readsofar * 100 / totalsize
            print(percent)
            self.progressbar.setValue(int(percent))
Esempio n. 2
0
        imgDir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'img')

    ### -- style stuff
    spmtLogo_file = os.path.join(imgDir, 'splashscreen.png')
    labelstyle = "QLabel { font-size: 14px; color: purple; font-style: italic; text-align: center;}"
    barStyle = "QProgressBar::chunk {background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #372f43,stop: 0.6 #5c4c7a, stop: 0.8 #663399);border-bottom-right-radius: 7px;border-bottom-left-radius: 7px;border-top: 2px solid #8A2BE2;}"

    splash_pix = QPixmap(spmtLogo_file)
    splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)

    progressBar = QProgressBar(splash)
    progressBar.setGeometry(0,
                            splash_pix.height() - 13, splash_pix.width(), 13)
    progressBar.setStyleSheet(barStyle)
    progressBar.setAlignment(Qt.AlignRight)

    label = QLabel(splash)
    label.setStyleSheet(labelstyle)
    label.setGeometry((splash_pix.width() - 500) / 2,
                      splash_pix.height() - 40, 500, 20)
    label.setAlignment(Qt.AlignCenter)

    progressText = "loading..."
    label.setText(progressText)

    splash.show()

    for i in range(0, 100):
        progressBar.setValue(i)
        updateSplash(label, i)