Orange Forum • View topic - Orange Widgets input/output

Orange Widgets input/output

A place to ask questions about methods in Orange and how they are used and other general support.

Orange Widgets input/output

Postby jimmy » Mon Apr 25, 2005 21:27

Hi,

Is it possible to creat widgets that pass other type of variables (string, filePointer...) or is it limited to ExampleTable class only? For example, one widget read in a JPG file and another widget display it? Thanks.

Jimmy

Postby Blaz » Tue Apr 26, 2005 20:53

Widgets can pass around any type of data. You can inspect the widgets in the current distribution, and see that apart of orange.ExampleTable (admittedly, one of prevailing classes), other classes like learners, classfiers and evaluation scores are passed around. The current practice is to either use an existing orange class, or create a class in python and then use this as a type for a widget channel.

So for JPG, create a Python class that can store a picture, and use it as a type to pass data from and to widgets.

For additional info, see http://www.ailab.si/orange/doc/widgets/channels.htm. Perhaps we should add an example with a new type defined in Python. Let us know if this is neccesary.

Postby jimmy » Wed Apr 27, 2005 0:16

Thanks a lot for your reply. Sorry I am new to Orange and class. Here are two widget I created. First widget should pass a string and second widget receive a string and print it. But when I linked them together on the orangeCanvas, it doesn't work. What did I do wrong? THank you very much!



First one:

"""
<name>output_string</name>
<description>output string</description>
<icon>icons/test1.png</icon>
<priority>10</priority>
"""
from OWWidget import *
import OWGUI

class output_string(OWWidget):

def __init__(self, parent=None):
OWWidget.__init__(self, parent, 'SampleData')

self.inputs = []
self.outputs = [("Examples", str)]

# GUI
box = QVGroupBox("Info", self.controlArea)
data=11
self.info = QLabel(str(data), box)
self.resize(100,50)

self.send("Example",str(data))
==============================
second one:
"""
<name>print_string</name>
<description>print string</description>
<icon>icons/test1.png</icon>
<priority>10</priority>
"""
from OWWidget import *
import OWGUI

class print_string(OWWidget):

def __init__(self, parent=None):
OWWidget.__init__(self, parent, 'SampleData')

self.inputs = [("Examples", str, self.data)]
self.outputs = []

def data(self,dataset):
box = QVGroupBox("Info", self.controlArea)
self.info = QLabel(str(dataset), box)
self.resize(100,50)

print dataset

Postby Blaz » Wed Apr 27, 2005 9:05

There is only one bug in your code: output_string defines a channel "Examples", but then writes to a channel "Example" ("s" is missing). So nothing was sent out to Examples, and nothing was received by print_string.

If you add this "s", your widgets should work (they do on my machine).

Also notice that we have changed the widgets about two months ago and needed to add another attribute in initalization (signalManager). With versions of Orange from two months back and on your widgets would not work (you are obviously working with the old version). You may consider updating to the lates release.

Inspired by your questions, I wrote two widgets where in one you type the string and the other one displays it. I also used the settings to save what one types in the entry field. I will probably add this as another example in widget documentation (OK?).

Here is the widget for entering the text:

Code: Select all
"""
<name>OWStringOut</name>
<description>Edit a string and send it out</description>
<icon>icons/test1.png</icon>
<priority>10</priority>
"""
from OWWidget import *
import OWGUI

class OWStringOut(OWWidget):
    settingsList = ['outstring']
    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager)

        self.inputs = []
        self.outputs = [("String", str)]

        self.outstring = "Default"  # this is the default string
        self.loadSettings()  # overwrite it if set in previous sessions

        # GUI
        OWGUI.lineEdit(self.controlArea, self, "outstring",
                       box="Enter a String")
        OWGUI.button(self.controlArea, self, "Commit", \
                     callback=lambda: self.send("String", self.outstring))
        self.send("String", self.outstring)  # send out the initial value
        self.resize(100,50)


and here is the receiver:

Code: Select all
"""
<name>OWPrintString</name>
<description>Prints a string received in the input</description>
<icon>icons/PrintString.png</icon>
<priority>20</priority>
"""
from OWWidget import *
import OWGUI

class OWPrintString(OWWidget):

    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager)
        self.inputs = [("String", str, self.data)]
        self.outputs = []

        # GUI
        box = QVGroupBox("String", self.controlArea)
        self.info = QLabel('<no data yet>', box)
        self.resize(200,50)

    def data(self, mystring):
        self.info.setText(mystring)


Prior to running widgets in OrangeCanvas, I like to test widgets independenly, so my widgets often include something like the following at the end (this one for OWPrintString widget):

Code: Select all
if __name__=="__main__":
    appl = QApplication(sys.argv)
    ow = OWPrintString()
    appl.setMainWidget(ow)
    ow.show()
    appl.exec_loop()

Postby jimmy » Wed Apr 27, 2005 14:36

Blaz:

Thanks a lot. Feel free to add it to the example.

Jimmy


Return to Questions & Support