2013-08-03 15:06:58 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2013-07-01
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2013-08-03 15:06:58 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2013-08-03 15:06:58 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2013-08-03 15:06:58 +00:00
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, QTimer
|
|
|
|
from PyQt5.QtWidgets import QProgressDialog
|
2013-08-03 15:06:58 +00:00
|
|
|
|
|
|
|
class ProgressWindow(QProgressDialog):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, parent, model, **kwargs):
|
2013-08-03 15:06:58 +00:00
|
|
|
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__('', "Cancel", 0, 100, parent, flags, **kwargs)
|
2013-08-03 15:06:58 +00:00
|
|
|
self.model = model
|
|
|
|
model.view = self
|
|
|
|
# We don't have access to QProgressDialog's labels directly, so we se the model label's view
|
|
|
|
# to self and we'll refresh them together.
|
|
|
|
self.model.jobdesc_textfield.view = self
|
|
|
|
self.model.progressdesc_textfield.view = self
|
|
|
|
self.setModal(True)
|
|
|
|
self.setAutoReset(False)
|
|
|
|
self.setAutoClose(False)
|
2013-08-04 01:28:02 +00:00
|
|
|
self._timer = QTimer(self)
|
2013-08-03 15:06:58 +00:00
|
|
|
self._timer.timeout.connect(self.model.pulse)
|
|
|
|
|
|
|
|
# --- Callbacks
|
|
|
|
def refresh(self): # Labels
|
|
|
|
self.setWindowTitle(self.model.jobdesc_textfield.text)
|
|
|
|
self.setLabelText(self.model.progressdesc_textfield.text)
|
|
|
|
|
|
|
|
def set_progress(self, last_progress):
|
|
|
|
self.setValue(last_progress)
|
|
|
|
|
|
|
|
def show(self):
|
2013-08-04 01:28:02 +00:00
|
|
|
self.reset()
|
2013-10-20 19:53:59 +00:00
|
|
|
super().show()
|
2013-08-04 01:28:02 +00:00
|
|
|
self.canceled.connect(self.model.cancel)
|
2013-08-03 15:06:58 +00:00
|
|
|
self._timer.start(500)
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self._timer.stop()
|
2013-08-04 01:28:02 +00:00
|
|
|
# For some weird reason, canceled() signal is sent upon close, whether the user canceled
|
|
|
|
# or not. If we don't want a false cancellation, we have to disconnect it.
|
|
|
|
self.canceled.disconnect()
|
2013-10-20 19:53:59 +00:00
|
|
|
super().close()
|
2013-08-03 15:06:58 +00:00
|
|
|
|