RefactoringRope/ProgressHandle.py

Tue, 13 Aug 2013 21:13:02 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Tue, 13 Aug 2013 21:13:02 +0200
branch
Py2 comp.
changeset 50
a29c3d2e6dc0
parent 43
39924831c795
child 63
c02061242598
permissions
-rw-r--r--

rope for Python2 projects enabled, if running on Python2

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a TaskHandle class with a progress dialog.
"""

from __future__ import unicode_literals    # __IGNORE_WARNING__

from PyQt4.QtGui import QApplication, QProgressDialog, QLabel

import rope.base.taskhandle


class ProgressHandle(rope.base.taskhandle.TaskHandle):
    """
    Class implementing TaskHandle with a progress dialog.
    """
    def __init__(self, title, interruptable=True, parent=None):
        """
        Constructor
        
        @param title title for the taskhandle (string)
        @param interruptable flag indicating, that the task may be
            interrupted (boolean)
        @param parent reference to the parent widget (QWidget)
        """
        rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable)
        if interruptable:
            cancelLabel = QApplication.translate("ProgressHandle", "Interrupt")
        else:
            cancelLabel = ""
        self.__progress = QProgressDialog("", cancelLabel, 0, 100, parent)
        label = QLabel("")
        label.setWordWrap(True)
        self.__progress.setLabel(label)
        self.add_observer(self.__updateProgress)
    
    def __updateProgress(self):
        """
        Private slot to handle the task progress.
        """
        jobset = self.current_jobset()
        if jobset:
            text = ''
            if jobset.get_name() is not None:
                text += jobset.get_name()
            if jobset.get_active_job_name() is not None:
                text += ' : ' + jobset.get_active_job_name()
            self.__progress.setLabelText(text)
            percent = jobset.get_percent_done()
            if percent is not None:
                self.__progress.setValue(percent)
        QApplication.processEvents()
        if not self.is_stopped() and self.__progress.wasCanceled():
            self.stop()
    
    def show(self):
        """
        Public slot to show the progress dialog.
        """
        self.__progress.show()
    
    def reset(self):
        """
        Public slot to reset the progress dialog.
        """
        self.__progress.reset()

eric ide

mercurial