Package qubx :: Module GTK :: Class Requestable
[hide private]
[frames] | no frames]

Class Requestable

source code

object --+
         |
        Requestable
Known Subclasses:

Defines a resource which is calculated when needed and cached until invalidated; it may take a long time to calculate, so request is asynchronous -- you provide a receiver callback, which is called by gobject some time later.

Instance Methods [hide private]
 
__init__(self, get=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
get(self, receiver)
Override this method to compute the answer(s) and pass them via gobject; e.g.:
source code
 
invalidate(self)
Dumps any cached value; next request will recompute.
source code
 
request(self, receiver)
Requests that the value be calculated if needed, then receiver(answer_part_1, answer_part_2, ...) is called by gobject.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, get=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • get - lambda receiver: gobject.idle_add(receiver, answer_part_1, answer_part_2, ...) -- computation function to replace self.get (or you can inherit this class and override self.get)
Overrides: object.__init__

get(self, receiver)

source code 

Override this method to compute the answer(s) and pass them via gobject; e.g.:

>>> val = 2+2
>>> val2 = 2*2
>>> gobject.idle_add(receiver, val, val2) # it's up to you how many args are passed

Alternatively, pass get=lambda receiver: ... to the constructor.