source: orange/docs/extend-widgets/rst/OWDataSamplerA.py @ 11593:6edc44eb9655

Revision 11593:6edc44eb9655, 1.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 10 months ago (diff)

Updated Widget development tutorial.

Line 
1"""
2<name>Data Sampler</name>
3<description>Randomly selects a subset of instances from the data set</description>
4<icon>icons/DataSamplerA.svg</icon>
5<priority>10</priority>
6"""
7
8import Orange
9from OWWidget import *
10import OWGUI
11
12class OWDataSamplerA(OWWidget):
13
14    def __init__(self, parent=None, signalManager=None):
15        OWWidget.__init__(self, parent, signalManager)
16
17        self.inputs = [("Data", Orange.data.Table, self.data)]
18        self.outputs = [("Sampled Data", Orange.data.Table)]
19
20        # GUI
21        box = OWGUI.widgetBox(self.controlArea, "Info")
22        self.infoa = OWGUI.widgetLabel(box, 'No data on input yet, waiting to get something.')
23        self.infob = OWGUI.widgetLabel(box, '')
24        self.resize(100,50)
25
26    def data(self, dataset):
27        if dataset:
28            self.infoa.setText('%d instances in input data set' % len(dataset))
29            indices = Orange.data.sample.SubsetIndices2(p0=0.1)
30            ind = indices(dataset)
31            sample = dataset.select(ind, 0)
32            self.infob.setText('%d sampled instances' % len(sample))
33            self.send("Sampled Data", sample)
34        else:
35            self.infoa.setText('No data on input yet, waiting to get something.')
36            self.infob.setText('')
37            self.send("Sampled Data", None)
38
39
40if __name__=="__main__":
41    appl = QApplication(sys.argv)
42    ow = OWDataSamplerA()
43    ow.show()
44    dataset = Orange.data.Table('iris.tab')
45    ow.data(dataset)
46    appl.exec_()
47
Note: See TracBrowser for help on using the repository browser.