def showProgress(text, iter, cancel=False): """ Show a progress dialog for the given task. The task should be an iterable, yielding progress info as (current, max) or (current, max, statusString) tuples. Return the last value yielded by the task. :param text: :type text: :param iter: :type iter: :param cancel: :type cancel: :return: :rtype: """ progress = None i = 0 start = time.time() with LoaderTimer.stopCtx(): for progress in iter: if time.time() - start > timeBeforeDialog: break else: return progress dialog = QtGui.QProgressDialog(QtGui.qApp.mainWindow) dialog.setWindowTitle(text) dialog.setWindowModality(Qt.WindowModal) dialog.show() for progress in iter: if isinstance(progress, basestring): max = current = 0 status = progress elif isinstance(progress, tuple): if len(progress) > 2: current, max, status = progress[:3] else: current, max = progress status = "" else: current = max = 1 status = "" dialog.setValue(current) dialog.setMaximum(max) dialog.setLabelText(status) QtGui.QApplication.processEvents() if dialog.wasCanceled(): return False dialog.close() return progress
def showProgress(text, iter, cancel=False): """ Show a progress dialog for the given task. The task should be an iterable, yielding progress info as (current, max) or (current, max, statusString) tuples. Return the last value yielded by the task. :param text: :type text: :param iter: :type iter: :param cancel: :type cancel: :return: :rtype: """ progress = None i = 0 with LoaderTimer.stopCtx(): for progress in iter: i += 1 if i > itersBeforeDialog: break else: return progress dialog = QtGui.QProgressDialog(QtGui.qApp.mainWindow) dialog.setWindowTitle(text) dialog.setWindowModality(Qt.WindowModal) dialog.show() for progress in iter: if isinstance(progress, basestring): max = current = 0 status = progress elif isinstance(progress, (tuple, list)): if len(progress) > 2: current, max, status = progress[:3] else: current, max = progress status = "" else: current = max = 1 status = "" dialog.setValue(current) dialog.setMaximum(max) dialog.setLabelText(status) QtGui.QApplication.processEvents() if dialog.wasCanceled(): return False dialog.close() return progress
def showProgress(text, *tasks, **kwargs): """ Show a progress dialog for the given task(s). Each task should be an iterable, yielding progress info as (current, max) or (current, max, statusString) tuples. Return the last value yielded by the task. :param text: :type text: :param iter: :type iter: :param cancel: :type cancel: :return: :rtype: """ progress = None cancel = kwargs.pop('cancel', None) start = time.time() shown = False with LoaderTimer.stopCtx(): dialog = MCEProgressDialog(QtGui.qApp.mainWindow) if not cancel: dialog.setCancelButtonText(None) dialog.setWindowTitle(text) dialog.setWindowModality(Qt.WindowModal) log.info("Starting progress: %d tasks." % len(tasks)) totalMaximum = len(tasks) * 100 for i, task in enumerate(tasks): log.info("Task #%d", i) task = rescaleProgress(task, i*100, i*100+100) for progress in task: if isinstance(progress, basestring): current = 0 maximum = 0 status = progress elif isinstance(progress, tuple): if len(progress) > 2: current, maximum, status = progress[:3] else: current, maximum = progress status = "" else: current = 0 maximum = 0 status = "" dialog.setValue(current) if maximum == 0: # Task progress is indeterminate dialog.setMaximum(0) else: dialog.setMaximum(totalMaximum) dialog.setLabelText(status) if time.time() > start + timeBeforeDialog: if not shown: dialog.show() shown = True QtGui.QApplication.processEvents() if dialog.wasCanceled(): return False dialog.reset() return progress
def showProgress(text, *tasks, **kwargs): """ Show a progress dialog for the given task(s). Each task should be an iterable, yielding progress info as (current, max) or (current, max, statusString) tuples. Return the last value yielded by the task. :param text: :type text: :param iter: :type iter: :param cancel: :type cancel: :return: :rtype: """ progress = None cancel = kwargs.pop('cancel', None) start = time.time() shown = False with LoaderTimer.stopCtx(): dialog = MCEProgressDialog(QtGui.qApp.mainWindow) if not cancel: dialog.setCancelButtonText(None) dialog.setWindowTitle(text) dialog.setWindowModality(Qt.WindowModal) log.info("Starting progress: %d tasks." % len(tasks)) totalMaximum = len(tasks) * 100 for i, task in enumerate(tasks): log.info("Task #%d", i) task = rescaleProgress(task, i * 100, i * 100 + 100) for progress in task: if isinstance(progress, basestring): current = 0 maximum = 0 status = progress elif isinstance(progress, tuple): if len(progress) > 2: current, maximum, status = progress[:3] else: current, maximum = progress status = "" else: current = 0 maximum = 0 status = "" dialog.setValue(current) if maximum == 0: # Task progress is indeterminate dialog.setMaximum(0) else: dialog.setMaximum(totalMaximum) dialog.setLabelText(status) if time.time() > start + timeBeforeDialog: if not shown: dialog.show() shown = True QtGui.QApplication.processEvents() if dialog.wasCanceled(): return False dialog.reset() return progress