2019-09-10 00:54:28 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-09-14
|
|
|
|
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
|
|
|
|
from PyQt5.QtCore import pyqtSignal, Qt, QTimer
|
|
|
|
from PyQt5.QtWidgets import QProgressDialog
|
|
|
|
|
|
|
|
from . import performer
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2019-09-10 00:54:28 +00:00
|
|
|
class Progress(QProgressDialog, performer.ThreadedJobPerformer):
|
2020-01-01 02:16:27 +00:00
|
|
|
finished = pyqtSignal(["QString"])
|
2019-09-10 00:54:28 +00:00
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
2020-01-01 02:16:27 +00:00
|
|
|
QProgressDialog.__init__(self, "", "Cancel", 0, 100, parent, flags)
|
2019-09-10 00:54:28 +00:00
|
|
|
self.setModal(True)
|
|
|
|
self.setAutoReset(False)
|
|
|
|
self.setAutoClose(False)
|
|
|
|
self._timer = QTimer()
|
2020-01-01 02:16:27 +00:00
|
|
|
self._jobid = ""
|
2019-09-10 00:54:28 +00:00
|
|
|
self._timer.timeout.connect(self.updateProgress)
|
|
|
|
|
|
|
|
def updateProgress(self):
|
|
|
|
# the values might change before setValue happens
|
|
|
|
last_progress = self.last_progress
|
|
|
|
last_desc = self.last_desc
|
|
|
|
if not self._job_running or last_progress is None:
|
|
|
|
self._timer.stop()
|
|
|
|
self.close()
|
|
|
|
if not self.job_cancelled:
|
|
|
|
self.finished.emit(self._jobid)
|
|
|
|
return
|
|
|
|
if self.wasCanceled():
|
|
|
|
self.job_cancelled = True
|
|
|
|
return
|
|
|
|
if last_desc:
|
|
|
|
self.setLabelText(last_desc)
|
|
|
|
self.setValue(last_progress)
|
|
|
|
|
|
|
|
def run(self, jobid, title, target, args=()):
|
|
|
|
self._jobid = jobid
|
|
|
|
self.reset()
|
2020-01-01 02:16:27 +00:00
|
|
|
self.setLabelText("")
|
2019-09-10 00:54:28 +00:00
|
|
|
self.run_threaded(target, args)
|
|
|
|
self.setWindowTitle(title)
|
|
|
|
self.show()
|
|
|
|
self._timer.start(500)
|