source: orange/orange/OrangeWidgets/Data/OWDataInfo.py @ 9546:2b6cc6f397fe

Revision 9546:2b6cc6f397fe, 3.3 KB checked in by ales_erjavec <ales.erjavec@…>, 2 years ago (diff)

Renamed widget channel names in line with the new naming rules/convention.
Added backwards compatibility in orngDoc loadDocument to enable loading of schemas saved before the change.

Line 
1"""<name>Info</name>
2<description>Shows data information.</description>
3<icon>icons/DataInfo.png</icon>
4<priority>80</priority>
5<contact>Ales Erjavec (ales.erjavec@fri.uni-lj.si)</contact>"""
6
7from OWWidget import *
8import OWGUI
9
10import orange
11import sys, os
12
13class OWDataInfo(OWWidget):
14    def __init__(self, parent=None, signalManager=None, name="Info"):
15        OWWidget.__init__(self, parent, signalManager, name, wantMainArea=0)
16       
17        self.inputs = [("Data", ExampleTable, self.data)]
18        self.rowcount = 0
19        self.columncount = 0
20        self.discattrcount = 0
21        self.contattrcount = 0
22        self.stringattrcount = 0
23        self.metaattrcount = 0
24        self.classattr = "No"
25       
26        box = OWGUI.widgetBox(self.controlArea, "Data Set Size", addSpace=True)
27        OWGUI.label(box, self, '<table><tr><td width="150">Samples (rows):</td><td align="right" width="60">%(rowcount)7i</td></tr>\
28                                <tr><td>Attributes (columns):</td><td align="right">%(columncount)7i</td></tr></table>')
29       
30        box = OWGUI.widgetBox(self.controlArea, "Attributes")
31        OWGUI.label(box, self, '<table><tr><td width="150">Discrete attributes:</td><td align="right" width="60">%(discattrcount)7i</td></tr>\
32                                <tr><td>Continuous attributes:</td><td align="right">%(contattrcount)7i</td></tr>\
33                                <tr><td>String attributes:</td><td align="right">%(stringattrcount)7i</td></tr>\
34                                <tr><td> </td></tr>\
35                                <tr><td>Meta attributes:</td><td align="right">%(metaattrcount)7i</td></tr>\
36                                <tr><td>Class attribute:</td><td align="right">%(classattr)7s</td></tr></table>')
37#        OWGUI.separator(box)
38#        OWGUI.label(box, self, '<table><tr><td width="100">Meta attributes:</td><td align="right" width="50">%(metaattrcount)7i</td></tr>\
39#                                <tr><td>Class attribute:</td><td align="right">%(classattr)7s</td></tr></table>')
40#       
41        OWGUI.rubber(self.controlArea)
42        self.resize(200, 200)
43       
44        self.loadSettings()
45       
46       
47    def data(self, data):
48        if data:
49            self.rowcount = len(data)
50            self.columncount = len(list(data.domain.attributes) + data.domain.getmetas().keys())
51            self.discattrcount = len([attr for attr in data.domain.attributes if attr.varType == orange.VarTypes.Discrete])
52            self.contattrcount = len([attr for attr in data.domain.attributes if attr.varType == orange.VarTypes.Continuous])
53            self.stringattrcount = len([attr for attr in data.domain.attributes if attr.varType == orange.VarTypes.String])
54            self.metaattrcount = len(data.domain.getmetas())
55            self.classattr = "Yes" if data.domain.classVar else "No"
56        else:
57            self.rowcount = 0
58            self.columncount = 0
59            self.discattroutn = 0
60            self.contattrcount = 0
61            self.stringattrcount = 0
62            self.metaattrcount = 0
63            self.classattr = "No"
64           
65if __name__ == "__main__":
66    app = QApplication(sys.argv)
67    w = OWDataInfo()
68    data = orange.ExampleTable("../../doc/datasets/iris.tab")
69    w.data(data)
70    w.show()
71    app.exec_()
Note: See TracBrowser for help on using the repository browser.