Utility Classes

class ilastik.utility.bind[source]

Behaves like functools.partial, but discards any extra parameters it gets when called. Also, bind objects can be compared for equality and hashed.

bind objects are immutable.

Inspired by boost::bind (C++).

__init__()

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

__call__(*args)[source]

Execute the callback. If more args are provided than the callback accepts, silently discard the extra args.

class ilastik.utility.SimpleSignal[source]

A simple python-only signal class for implementing the observer pattern. For familarity, mimics a SUBSET of the pyqt signal interface. Not threadsafe. No fine-grained unsubcribe mechanism.

connect(callable)[source]

Add a subscriber.

emit(*args, **kwargs)[source]

Fire the signal with the given arguments.

disconnectAll()[source]

Remove all subscribers.

class ilastik.utility.OperatorSubView(op, index)[source]

An adapter class that makes a specific lane of a multi-image operator look like a single image operator.

If the adapted operator is an OperatorWrapper, then the view provides all of the members of the inner operator at the specified index, except that the slot members will refer to the OperatorWrapper’s slots (i.e. the OUTER slots).

If the adapted operator is NOT an OperatorWrapper, then the view provides all the members of the adapted operator, except that ALL MULTISLOT members will be replaced with a reference to the subslot for the specified index. Non-multislot members will not be replaced.

__init__(op, index)[source]

Constructor. Creates a view of the given operator for the specified index.

Parameters:
  • op – The operator to view.
  • index – The index of this subview. All multislots of the original operator will be replaced with the corresponding subslot at this index.
class ilastik.utility.MultiLaneOperatorABC[source]

This abstract base class specifies the interface to which all top-level applet operators must adhere. The distinguishing characteristic of a top-level operator is the fact that they must be capable of supporting multiple images via multi-slots that are indexed by image lane number.

Image lanes of the top-level operator are added, removed, and accessed via the addLane, removeLane, and getLane functions.

Note

Most applets can simply inherit from the StandardApplet base class, which will automatically adapt single-lane top-level operators to satisfy this interface.

addLane(laneIndex)[source]

Add an image lane. Called by the workflow when the user has added a new image to the pipeline.

Postcondition: The operator must be fully prepared to accept a new image.
All input and output slots that are used by the image lane must be resized. Any internal operators that are part of the lane must be expanded).

Note

Multi-slots that are connected together are auto-resized to stay in sync. To resize a network of connected multi-slots (including OperatorWrapper inputs and outputs), it is generally sufficient to resize only one of the multi-slots. The others will auto-resize to adjust. See lazyflow documentation for details. If your operator has any slots that are NOT connected to the rest of the inputs or outputs, then be sure to resize it explicitly in this function.

removeLane(laneIndex, finalLength)[source]

Remove an image lane. Called by the workflow when the user has removed an image from the pipeline.

Postcondition: The lane must be removed from all slots that were added in addLane()

Note

See note in addLane() documentation.

getLane(laneIndex)[source]

Get an object that exposes the relevant slots for the specific lane. The object may be an operator, or may merely be an operator-like “view” object.

class ilastik.utility.OpMultiLaneWrapper(operatorClass, operator_args=None, operator_kwargs=None, parent=None, graph=None, promotedSlotNames=None, broadcastingSlotNames=None)[source]

An extension of the OperatorWrapper that provides the functions needed to satisfy MultiLaneOperatorABC. See OperatorWrapper class documentation for details on that class.

addLane(laneIndex)[source]

Add an image lane to this object. Simply inserts a new inner operator into the base OperatorWrapper.

removeLane(laneIndex, finalLength)[source]

Remove an image lane. Simply removes the appropriate inner operator from the base OperatorWrapper.

getLane(laneIndex)[source]

Create sub-view that exposes the correct inner operator from the base OperatorWrapper.

GUI Utilities

QT can be finicky about calling certain functions from non-GUI threads. These two utility classes provide mechanisms for forcing code to be called from within the GUI thread.

class ilastik.utility.gui.ThunkEventHandler(parent)[source]

GUI objects can instantiate an instance of this class and then start using it to post ThunkEvents, which execute a given callable in the GUI event loop. The callable will NOT be called synchronously. It will be called when the QT event system eventually passes the event to the GUI object’s event filters.

In the following example, C.setCaption() can be called from ANY thread safely. The widget’s text will ONLY be updated in the main thread, at some point in the future.

class C(QObject):
    def __init__(self, parent):
        QObject.__init__(self, parent=parent)
        self.thunkEventHandler = ThunkEventHandler(self)
 
 
    def setCaption(self, text):
        self.thunkEventHandler.post( self.mywidget.setText, text )    
__init__(parent)[source]

Create a ThunkEventHandler that installs itself in the event loop for parent.

post(func, *args)[source]

Post an event to the GUI event system that will eventually execute the given function with the given arguments. This is implemented using QApplication.post()

send(func, *args)[source]

Send an event to the GUI event system that will eventually execute the given function with the given arguments. Note that this is done using QApplication.send(), which may not be what you wanted.

ilastik.utility.gui.threadRouted(func)

Decorator that routes calls to the given member function into the object’s parent thread. If a member function f is decorated with @threadRouted, all calls to f will execute in the GUI thread. The calling thread will block while f is executing, so the call will appear synchronous. This mechanism is slow, and should only be used for functions that MUST execute in the GUI thread.

Note

Objects that use the @threadRouted decorator MUST have a ThreadRouter member called self.threadRouter

class ilastik.utility.gui.ThreadRouter(parent)[source]

Create an instance of this class called ‘threadRouter’ to enable the @threadRouted decorator for methods of your object.

__init__(parent)[source]

Construct a threadRouter object. You must call it self.threadRouter.

Parameters:parent – The parent object, which whose thread will be used for all @threadRouted functions.