Orange Forum • View topic - Creating widgets outside Canvas

Creating widgets outside Canvas

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

Creating widgets outside Canvas

Postby bgbg » Sun Apr 26, 2009 9:49

Hello,
I would like to create a widget outside Canvas. For example, I would like to present fully functional ROC widget (http://www.ailab.si/orange/doc/widgets/catalog/Evaluate/ROCAnalysis.htm) at the end of this code:


Code: Select all
import orange
import orngSVM
import orngBayes
import orngTest

data = orange.ExampleTable(r'C:\Python25\Lib\site-packages\orange\doc\datasets\iris.tab')
learnerSVM = orngSVM.SVMLearner()
learnerSVM.name = 'SVM'

learnerBayes = orngBayes.BayesLearner()
learnerBayes.name = 'Bayes'

results = orngTest.crossValidation([learnerSVM, learnerBayes], data)
# ROC analysis here


Can anyone please complete this example, including all the required import-s?

Postby Janez » Tue Apr 28, 2009 13:15

Code: Select all
import sys
sys.path.append(r"c:\Python25\lib\site-packages\orange\OrangeWidgets\Evaluate")

from OWROC import *
a = QApplication(sys.argv)
ow = OWROC()
ow.show()
ow.test_results(results)
a.exec_()


A similar code works for any other widget, you will just need to replace ow.test_results(results) with something else. Method test_results is actually the method which receives the signal when the widget is on the canvas. For other widgets you might want to use, you will find the method in the line which begins with "self.inputs". The first argument in the tuple is the signal name (as you see it in the canvas), the second is its type and the third is the name of the method to call.

I'm not sure whether you need the first two lines - I do not have a regular installation on my machine, so you can already have the widget on the path.

Before calling a.exec_() you can also set other parameters of the widget (e.g. ow.AveragingMethodIndex = 3) or call its methods. There is no documentation for that, since this is widget's internal stuff and can change anytime.

After a.exec()_, you are in the Qt's loop and can work with the widget as usual.

Instead of calling exec_, you can also do other things with the widget. I sometimes call the method for saving the widget's content (typically a plot of some kind) to a file.

If you run this script from an IDE, such as PythonWin, it will crash on the second run (unless you close the session in between). The problem is that it "re-initializes" Qt. If you use PyScripter, you should use "remote engine".

Postby bgbg » Thu Apr 30, 2009 7:12

Thank you


Return to Questions & Support



cron