OWWidget is the main component for implementing a widget in the Orange Canvas workflow. It both defines the widget input/output capabilities and implements it’s functionality within the canvas.
Widget Meta Description
Every widget in the canvas framework needs to define it’s meta definition. This includes the widget’s name and text descriptions but more importantly also its input/output specification. This is done by defining constants in the widget’s class namespace:
class IntConstant(OWWidget): name = "Integer Constant" description "A simple integer constant" outputs = [("Constant", int)] ... def commit(self): """ Commit/send the outputs. """ self.send("Constant", 42)
Omitting the implementation details, this defines a simple node namedInteger Constant which outputs (on a signal called Constant) a single object of type
The node’s inputs are defined similarly but with and extra field naming the widget instance method which accepts the inputs at runtime:
class Adder(OWWidget): name = "Add two integers" description = "Add two numbers" inputs = [("A", int, "set_A"), ("B", int, "set_B")] outputs = [("A + B", int")] ... def set_A(self, a): """Set the `A` input.""" self.A = a def set_B(self, b): """Set the `B` input.""" self.B = b def handleNewSignals(self): """Coalescing update.""" self.commit() def commit(self): """ Commit/send the outputs. """ sef.send("result", self.A + self.B)
Input/Output Signal Definitions
Widgets specify their input/output capabilities in their class definitions by means of a
outputs class attributes which are lists of tuples or lists of
An input is defined by a
(name, type, methodname [, flags])tuple or an
Thenameis the input’s descriptive name,typethe type of objects received,methodnameastrnaming a widget member method that will receive the input, and optionalflags.
An output is defined by a
(name, type, flags)tuple or an
This input is the default for it’s type. When there are multiple IO signals with the same type the one with the default flag takes precedence when adding a new link in the canvas.
Multiple signal (more then one input on the channel). Input with this flag receive a second parameterid.
Only applies to output. Specifies that the instances on the output will in general be subtypes of the declared type and that the output can be connected to any input which can accept a subtype of the declared output type.
The widgets receive inputs at runtime with the designated handler method (specified in the
OWWidget.inputs class member).
If a widget defines multiple inputs it can coalesce updates by reimplementing
def set_foo(self, foo): self.foo = foodef set_bar(self, bar): self.bar = bardef handleNewSignals(self) dosomething(self.foo, self.bar)
The widgets publish their outputs using