Package gen :: Package utils :: Module longop :: Class LongOpStatus
[frames] | no frames]

Class LongOpStatus

source code


LongOpStatus provides a way of communicating the status of a long
running operations. The intended use is that when a long running operation
is about to start it should create an instance of this class and emit
it so that any listeners can pick it up and use it to record the status 
of the operation.


Signals
=======

  op-heartbeat - emitted every 'interval' calls to heartbeat. 
  op-end       - emitted once when the operation completes.


Example usage:

class MyClass(Callback):

    __signals__ = {
       'op-start'   : object
    }

    def long(self):
    status = LongOpStatus("doing long job", 100, 10)

        for i in xrange(0,99):
        time.sleep(0.1)
        status.heartbeat()

        status.end()


class MyListener(object):

     def __init__(self):
     self._op = MyClass()
     self._op.connect('op-start', self.start)
     self._current_op = None

     def start(self,long_op):
     self._current_op.connect('op-heartbeat', self.heartbeat)
     self._current_op.connect('op-end', self.stop)

     def hearbeat(self):
     # update status display

     def stop(self):
     # close the status display
         self._current_op = None

Instance Methods
 
__init__(self, msg='', total_steps=None, interval=1, can_cancel=False)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__del__(self) source code
 
heartbeat(self)
This should be called for each step in the operation.
source code
int
estimated_secs_to_complete(self)
Return the number of seconds estimated left before operation completes.
source code
 
cancel(self)
Inform the operation that it should complete.
source code
 
end(self)
End the operation.
source code
bool
should_cancel(self)
Return true of the user has asked for the operation to be cancelled.
source code
bool
can_cancel(self)
Returns: True if the operation can be cancelled.
source code
string
get_msg(self)
Returns: The current status description messages.
source code
 
set_msg(self, msg)
Set the current description message.
source code
int
get_total_steps(self)
Get to total number of steps.
source code
int
get_interval(self)
Get the interval between 'op-hearbeat' signals.
source code

Inherited from callback.Callback: connect, disable_logging, disable_signals, disconnect, emit, enable_logging, enable_signals

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods

Inherited from callback.Callback: disable_all_signals, enable_all_signals, log_all

Class Variables
  __signals__ = {'op-end': None, 'op-heartbeat': None}
Properties

Inherited from object: __class__

Method Details

__init__(self, msg='', total_steps=None, interval=1, can_cancel=False)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • msg (string) - A Message to indicated the purpose of the operation.
  • total_steps () - The total number of steps that the operation will perform.
  • interval () - The number of iterations between emissions.
  • can_cancel () - Set to True if the operation can be cancelled. If this is set the operation that creates the status object should check the 'should_cancel' method regularly so that it can cancel the operation.
Overrides: object.__init__

heartbeat(self)

source code 

This should be called for each step in the operation. It will emit a 'op-heartbeat' every 'interval' steps. It recalcuates the 'estimated_secs_to_complete' from the time taken for previous steps.

estimated_secs_to_complete(self)

source code 

Return the number of seconds estimated left before operation completes. This will change as 'hearbeat' is called.

Returns: int
estimated seconds to complete.

end(self)

source code 

End the operation. Causes the 'op-end' signal to be emitted.

should_cancel(self)

source code 

Return true of the user has asked for the operation to be cancelled.

Returns: bool
True of the operation should be cancelled.

can_cancel(self)

source code 
Returns: bool
True if the operation can be cancelled.

get_msg(self)

source code 
Returns: string
The current status description messages.

set_msg(self, msg)

source code 

Set the current description message.

Parameters:
  • msg (string) - The description message.

get_total_steps(self)

source code 

Get to total number of steps. NOTE: this is not the number of times that the 'op-heartbeat' message will be emited. 'op-heartbeat' is emited get_total_steps/interval times.

Returns: int
total number of steps.

get_interval(self)

source code 

Get the interval between 'op-hearbeat' signals.

Returns: int
the interval between 'op-hearbeat' signals.