RefactoringRope/ProgressHandle.py

Mon, 10 May 2021 20:13:48 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 10 May 2021 20:13:48 +0200
changeset 360
2b35968f3d02
parent 347
b5048b5ff454
child 365
f740b50380df
permissions
-rw-r--r--

Version 8.0.0
- bug fixes
- removed the included 'rope' library and have it as an external dependency installed during the plug-in installation (for eric > 21.5)

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

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

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

import rope.base.taskhandle


class ProgressHandle(rope.base.taskhandle.TaskHandle):
    """
    Class implementing distributed TaskHandle with a progress dialog.
    
    This is the client side.
    """
    def __init__(self, client, title, interruptable=True):
        """
        Constructor
        
        @param client reference to the JSON client
        @type E5JsonClient
        @param title title for the taskhandle
        @type str
        @param interruptable flag indicating, that the task may be
            interrupted
        @type bool
        """
        rope.base.taskhandle.TaskHandle.__init__(self, title, interruptable)
        
        self.__client = client
        
        self.__client.sendJson("Progress", {
            "Subcommand": "Init",
            "Title": title,
            "Interruptable": interruptable,
        })
        
        self.add_observer(self.__updateProgress)
    
    def __updateProgress(self):
        """
        Private slot to handle the task progress.
        """
        params = {
            "Subcommand": "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()
            params["Text"] = text
            if jobset.count is not None:
                params["Maximum"] = jobset.count
                params["Value"] = jobset.done
        
        self.__client.sendJson("Progress", params)
        self.__client.poll()
    
    def reset(self):
        """
        Public slot to reset the progress dialog.
        """
        self.__client.sendJson("Progress", {
            "Subcommand": "Reset",
        })
        self.__client.poll()

eric ide

mercurial