class LongOperationBox(QDialog): def __init__(self, text, operation, args=[], kwargs={}, progress_method = None, parent=None): QDialog.__init__(self, parent) self._ui = Ui_LongOperationBox() self._ui.setupUi(self) self._ui.label.setText(text) self._operation = operation self._progress_method = progress_method self._thread = RunLongOperation(operation, args, kwargs) self.connect(self._thread, SIGNAL("finished()"), self.thread_finished) self._progress_thread = None if self._progress_method: self._progress_thread = ProgressOperation(self._progress_method) self.connect(self._progress_thread, SIGNAL("update"), self.update) self._ui.progressBar.setValue(0) def thread_finished(self): if self._progress_thread: self._progress_thread.terminate() self.accept() def update(self, value): if value: self._ui.progressBar.setValue(int(value * 100)) def result(self): return self._thread.result() def exec_(self): self._thread.start() if self._progress_thread: self._progress_thread.start() QDialog.exec_(self)
def __init__(self, text, operation, args=[], kwargs={}, progress_method = None, parent=None): QDialog.__init__(self, parent) self._ui = Ui_LongOperationBox() self._ui.setupUi(self) self._ui.label.setText(text) self._operation = operation self._progress_method = progress_method self._thread = RunLongOperation(operation, args, kwargs) self.connect(self._thread, SIGNAL("finished()"), self.thread_finished) self._progress_thread = None if self._progress_method: self._progress_thread = ProgressOperation(self._progress_method) self.connect(self._progress_thread, SIGNAL("update"), self.update) self._ui.progressBar.setValue(0)