OWWidget

The 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.

class IntConstant(OWWidget):
    name = "Integer Constant"
    description = "A simple integer constant"

    class Outputs:
        constant = Output("Constant", int)

    ...

    def commit(self):
        """Commit/send the outputs."""
        self.Outputs.constant.send(42)

Omitting the implementation details, this defines a simple node named Integer Constant which outputs (on a signal called Constant) a single object of type int.

The node's inputs are defined similarly. Each input is then used as a decorator of its corresponding handler method, which accepts the inputs at runtime:

class Adder(OWWidget):
    name = "Add two integers"
    description = "Add two numbers"

    class Inputs:
        a = Input("A", int)
        b = Input("B", int)

    class Outputs:
        sum = Input("A + B", int)

    ...

    @Inputs.a
    def set_A(self, a):
        """Set the `A` input."""
        self.A = a

    @Inputs.b
    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.Outputs.sum.send("self.A + self.B)

Input/Output Signal Definitions

Widgets specify their input/output capabilities in their class definitions by defining classes named Inputs and Outputs, which contain class attributes of type Input and Output, correspondingly. Input and Output require at least two arguments, the signal's name (as shown in canvas) and type. Optional arguments further define the behaviour of the signal.

Note: old-style signals define the input and output signals using class attributes inputs and outputs instead of classes Input and Output. The two attributes contain a list of tuples with the name and type and, for inputs, the name of the handler method. The optional last argument is an integer constant giving the flags. This style of signal definition is deprecated.

class Orange.widgets.widget.Input(name, type, id=None, doc=None, replaces=None, *, multiple=False, default=False, explicit=False, auto_summary=None, closing_sentinel=None)[source]

Description of an input signal.

The class is used to declare input signals for a widget as follows (the example is taken from the widget Test & Score):

class Inputs:
    train_data = Input("Data", Table, default=True)
    test_data = Input("Test Data", Table)
    learner = Input("Learner", Learner, multiple=True)
    preprocessor = Input("Preprocessor", Preprocess)

Every input signal must be used to decorate exactly one method that serves as the input handler, for instance:

@Inputs.train_data
def set_train_data(self, data):
    ...
Parameters:
  • (str) (id) -- signal name

  • (type) (type) -- signal type

  • (str) -- a unique id of the signal

  • (str (doc) -- signal documentation

  • optional) -- signal documentation

  • str) (replaces (list of) -- a list with names of signals replaced by this signal

  • (bool (auto_summary) -- if set, multiple signals can be connected to this output (default: False)

  • optional) -- if set, multiple signals can be connected to this output (default: False)

  • (bool -- when the widget accepts multiple signals of the same type, one of them can set this flag to act as the default (default: False)

  • optional) -- when the widget accepts multiple signals of the same type, one of them can set this flag to act as the default (default: False)

  • (bool -- if set, this signal is only used when it is the only option or when explicitly connected in the dialog (default: False)

  • optional) -- if set, this signal is only used when it is the only option or when explicitly connected in the dialog (default: False)

  • (bool -- by default, the input is reflected in widget's summary for all types with registered summarize function. This can be overridden by explicitly setting auto_summary to False or True. Explicitly setting this argument will also silence warnings for types without the summary function and for types defined with a fully qualified string instead of an actual type object.

  • optional) -- by default, the input is reflected in widget's summary for all types with registered summarize function. This can be overridden by explicitly setting auto_summary to False or True. Explicitly setting this argument will also silence warnings for types without the summary function and for types defined with a fully qualified string instead of an actual type object.

class Orange.widgets.widget.Output(name, type, id=None, doc=None, replaces=None, *, default=False, explicit=False, dynamic=True, auto_summary=None)[source]

Description of an output signal.

The class is used to declare output signals for a widget as follows (the example is taken from the widget Test & Score):

class Outputs:
    predictions = Output("Predictions", Table)
    evaluations_results = Output("Evaluation Results", Results)

The signal is then transmitted by, for instance:

self.Outputs.predictions.send(predictions)
Parameters:
  • (str) (id) -- signal name

  • (type) (type) -- signal type

  • (str) -- a unique id of the signal

  • (str (doc) -- signal documentation

  • optional) -- signal documentation

  • str) (replaces (list of) -- a list with names of signals replaced by this signal

  • (bool (auto_summary) -- when the widget accepts multiple signals of the same type, one of them can set this flag to act as the default (default: False)

  • optional) -- when the widget accepts multiple signals of the same type, one of them can set this flag to act as the default (default: False)

  • (bool -- if set, this signal is only used when it is the only option or when explicitly connected in the dialog (default: False)

  • optional) -- if set, this signal is only used when it is the only option or when explicitly connected in the dialog (default: False)

  • (bool -- 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 signal which can accept a subtype of the declared output type (default: True)

  • optional) -- 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 signal which can accept a subtype of the declared output type (default: True)

  • (bool -- by default, the output is reflected in widget's summary for all types with registered summarize function. This can be overridden by explicitly setting auto_summary to False or True. Explicitly setting this argument will also silence warnings for types without the summary function and for types defined with a fully qualified string instead of an actual type object.

  • optional) -- by default, the output is reflected in widget's summary for all types with registered summarize function. This can be overridden by explicitly setting auto_summary to False or True. Explicitly setting this argument will also silence warnings for types without the summary function and for types defined with a fully qualified string instead of an actual type object.

Sending/Receiving

The widgets receive inputs at runtime with the handler method decorated with the signal, as shown in the above examples.

If an input is defined with the flag multiple set, the input handler method also receives a connection id uniquely identifying a connection/link on which the value was sent (see also Channels and Tokens)

The widget sends an output by calling the signal's send method, as shown above.

Accessing Controls though Attribute Names

The preferred way for constructing the user interface is to use functions from module Orange.widgets.gui that insert a Qt widget and establish the signals for synchronization with the widget's attributes.

gui.checkBox(box, self, "binary_trees", "Induce binary tree")

This inserts a QCheckBox into the layout of box, and make it reflect and changes the attriubte self.binary_trees. The instance of QCheckbox can be accessed through the name it controls. E.g. we can disable the check box by calling

self.controls.binary_trees.setDisabled(True)

This may be more practical than having to store the attribute and the Qt widget that controls it, e.g. with

self.binarization_cb = gui.checkBox(

box, self, "binary_trees", "Induce binary tree")

Class Member Documentation

class Orange.widgets.widget.OWWidget(*args, captionTitle=None, **kwargs)[source]

OWBaseWidget extended with Orange.data.Table related report methods (Report)

class Orange.widgets.widget.Message(text, persistent_id, icon=None, moreurl=None)[source]

A user message.

Parameters:
  • text (str) -- Message text

  • persistent_id (str) -- A persistent message id.

  • icon (QIcon or QStyle.StandardPixmap) -- Message icon

  • moreurl (str) -- An url to open when a user clicks a 'Learn more' button.

See also

OWBaseWidget.UserAdviceMessages

class Orange.widgets.widget.StateInfo(*args, **kwargs)[source]

A namespace for OWBaseWidget's detailed input/output/state summary reporting.

See also

OWBaseWidget.info

class Summary(brief: str = '', details: str = '', icon: ~PyQt5.QtGui.QIcon = <PyQt5.QtGui.QIcon object>, format: ~PyQt5.QtCore.Qt.TextFormat = 0)[source]

Input/output summary description.

This class is used to hold and report detailed I/O summaries.

brief

A brief (inline) description.

Type:

str

details

A richer detailed description.

Type:

str

icon

An custom icon. If not set a default set will be used to indicate special states (i.e. empty input ...)

Type:

QIcon

format

Qt.PlainText if brief and details are to be rendered as plain text or Qt.RichText if they are HTML.

Type:

Qt.TextFormat

classmethod default_icon(role: str) QIcon[source]

Return a default icon for input/output role.

Parameters:

role (str) -- "input" or "output"

Returns:

icon

Return type:

QIcon

class Empty(brief: str = '', details: str = '', icon: ~PyQt5.QtGui.QIcon = <PyQt5.QtGui.QIcon object>, format: ~PyQt5.QtCore.Qt.TextFormat = 0)[source]

Bases: Summary

Input/output summary description indicating empty I/O state.

class Partial(brief: str = '', details: str = '', icon: ~PyQt5.QtGui.QIcon = <PyQt5.QtGui.QIcon object>, format: ~PyQt5.QtCore.Qt.TextFormat = 0)[source]

Bases: Summary

Input summary indicating partial input.

This state indicates that some inputs are present but more are needed in order for the widget to proceed.

NoInput Empty()

A default message displayed to indicate no inputs.

NoOutput Empty()

A default message displayed to indicate no output.

set_input_summary(summary: Optional[StateInfo.Summary]])[source]

Set the input summary description.

Parameters:

summary (Optional[StateInfo.Summary]) --

set_input_summary(brief: str, detailed: str = '', icon: QIcon = QIcon, format: Qt.TextFormat = Qt.PlainText)[source]
set_output_summary(summary: Optional[StateInfo.Summary]])[source]

Set the output summary description.

Parameters:

summary (Optional[StateInfo.Summary]) --

set_output_summary(brief: str, detailed: str = '', icon: QIcon = QIcon, format: Qt.TextFormat = Qt.PlainText)[source]
input_summary_changed(message: StateInfo.Message)

Signal emitted when the input summary changes

output_summary_changed(message: StateInfo.Message)

Signal emitted when the output summary changes