def __init__(self, parent=QWidget.find(rt.windows.getMAXHWND())): super(PyMaxDialog, self).__init__(parent) self.setWindowTitle('Progress') main_layout = QVBoxLayout() label = QLabel("Progress so far") main_layout.addWidget(label) # progress bar progb = QProgressBar() progb.minimum = MINRANGE progb.maximum = MAXRANGE main_layout.addWidget(progb) # abort button btn = QPushButton("abort") main_layout.addWidget(btn) self.setLayout(main_layout) self.resize(250, 100) # start the worker self.worker = Worker() self.worker.progress.connect(progb.setValue) self.worker.start() # connect abort button btn.clicked.connect(self.worker.abort)
class Window(QWidget): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(400, 200) self._value = 0 self.setWindowTitle('Adobe Version Changer') self.setWindowIcon(QIcon('favicon.ico')) self.progressbar = QProgressBar(self) self.progressbar.setRange(0, 99) self.widget = QWidget(self) self.layout = QGridLayout(self.widget) self.label = QLabel('| Drop your file here |') self.layout.addWidget(self.label, 1, 23, 30, 10) self.layout.addWidget(self.progressbar, 2, 0, 1, 58) QToolTip.setFont(QFont('Helvetica', 20)) self.setToolTip( '''Drag and Drop into this window a <b>Premiere Project File or Motion Graphics File</b> to be converted. You will find a file named as the Project or Motion Graphic file with the extension <b>"_changed"</b> in that same location.''') self.setAcceptDrops(True) def progressStart(self): animation = QPropertyAnimation(self.progressbar, b'value', self) x = int(os.stat(self.userInput).st_size) / 20000 # print(x) animation.setDuration(x) animation.setLoopCount(1) animation.setKeyValueAt(0, self.progressbar.minimum()) animation.setKeyValueAt(0.1, 10) animation.setKeyValueAt(0.2, 30) animation.setKeyValueAt(0.5, 60) animation.setKeyValueAt(0.7, 80) animation.setKeyValueAt(1, self.progressbar.maximum()) animation.start(animation.DeleteWhenStopped) def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def dragEnterEvent(self, e): if e.mimeData().hasUrls(): e.acceptProposedAction() def dropEvent(self, e): for url in e.mimeData().urls(): self.userInput = url.toLocalFile() self.progressStart() func(self.userInput) self.label.setText("| Another file? |") # repeat return self.userInput def startprogressBar(self): self.progressBar.setVisible(True) if self.timer.isActive(): self.timer.stop() else: self.timer.start(100, self) def resetBar(self): self.step = 0 self.progressBar.setValue(0) def timerEvent(self, event): if self.step >= 100: self.timer.stop() return self.step += 1 self.progressBar.setValue(self.step)