Skip to content

Porting Orange2 widgets to Orange3

Aleš Erjavec edited this page Oct 30, 2015 · 11 revisions

Changes:

  • The widget meta data descriptions (name, desciption, icon, ...) are moved into the OWWidget's class namespace. E.g. in Orange2 the widget meta definitions would look like

    """
    <name>Widget</name>
    <description>An awesome widget</description>
    ...
    """

    or

    NAME = "Widget"
    DESCRIPTION = "An awesome widget"
    ICON = 

    defined at the module level namespace

    In Orange 3 this is changed to

    class OWAwesome(OWWidget):
        #: Widget's descriptive name
        name = "Widget"
        #: A short widget description
        description = "An awesome widget"
        #: An icon resource file path for this widget
        #: (a path relative to the module where this widget is defined)
        icon = "icons/someicon.svg"
        #: Priority within a category
        priority = 0
    
        #: A list of input definitions (here an input named "Bar" taking a
        #: value of type `object`, and specifying that a method "set_foo" is
        #: the one to receive the input)
        inputs = [("Foo", object, "set_foo")]
    
        #: A list of output definitions (here on output named "Bar"
        #: of type object)
        outputs = [("Bar", object)]
    
        ...
    
        def set_foo(self, foo):
            """Set the foo widget input"""
            ...
  • The OWWidget.__init__ method no longer takes any parameters. The signalManager and title are no longer passed to the __init__, while the parameters specifying the requested GUI layout, ... are (again) defined in the widget's class namespace. E.g. what was once in Orange2

    class FooWidget(OWWidget):
        def __init__(self, parent=None, signalManager=None, title="blabla"):
            OWWidget.__init__(self, parent, signalManager, title, wantMainArea=False, ...)

    is now changed to

    class FooWidget(OWWidget):
        #: Do not want the default layout with the main area.
        want_main_area = False
        def __init__(self):
            super().__init__()
  • How settings are defined has changed. In Orange2 the settings (widget members) were specified by a class variable settingsList containing a list of member names to store.

    class FooWidget(OWWidget):
        settingsList = ["bar"]
        def __init__(self, *args, *kwargs)
             OWWidget.__init__(self, *args, **kwargs)
             # initialize the 'members' to the defaults
             self.bar = 2
             # load/restore the saved state; bar member would be modified here
             self.loadSettings()

    In Orange3 the same is accomplished by defining/initializing the settings in the class namespace using the Orange.widget.setttings.Setting 'descriptor'

    from Orange.widgets.settings import Setting
    class FooWidget(OWWidget):
        #: Initialize bar and mark it as a persistent setting (i.e. it will be restored
        #: from a previous session or a saved workflow)
        bar = Setting(2)
        def __init__(self):
            super().__init__()
            # note that there is no self.loadSettings() or equivalent the `bar` member was
            # already restored and is ready for use.