source: orange/Orange/doc/extend-widgets/gui_listbox_attr.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 1.5 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1from OWWidget import *
2import OWGUI
3
4class Test(OWWidget):
5    def __init__(self, parent=None):
6        OWWidget.__init__(self, parent, title='Listbox')
7
8        self.attributes = []
9        self.chosenAttribute = []
10        self.values = []
11        self.chosenValues = []
12
13        OWGUI.listBox(self.controlArea, self, "chosenAttribute", "attributes",
14                      box="Attributes", callback=self.setValues)
15        OWGUI.separator(self.controlArea)
16        OWGUI.listBox(self.controlArea, self, "chosenValues", "values",
17                      box="Values", selectionMode=QListWidget.MultiSelection)
18
19        self.controlArea.setFixedSize(150, 250)
20        self.adjustSize()
21
22
23        # The following assignments usually don't take place in __init__
24        # but later on, when the widget receives some data
25        import orange
26        self.data = orange.ExampleTable(r"..\datasets\horse-colic.tab")
27        self.attributes = [(attr.name, attr.varType) for attr in self.data.domain]
28        self.chosenAttribute = [0]
29
30    def setValues(self):
31        attrIndex = self.chosenAttribute[0]
32        attr = self.data.domain[attrIndex]
33        if attr.varType == orange.VarTypes.Discrete:
34            self.values = attr.values
35        else:
36            self.values = []
37        self.chosenValues = []
38
39##############################################################################
40# Test the widget, run from prompt
41
42if __name__=="__main__":
43    appl = QApplication(sys.argv)
44    ow = Test()
45    ow.show()
46    appl.exec_()
Note: See TracBrowser for help on using the repository browser.