Beispiel #1
0
class Lists(Sink):
    def __init__(self):
        Sink.__init__(self)
        self.sStrings = [["foo0", "bar0", "baz0", "toto0", "tintin0"],
                         ["foo1", "bar1", "baz1", "toto1", "tintin1"],
                         ["foo2", "bar2", "baz2", "toto2", "tintin2"],
                         ["foo3", "bar3", "baz3", "toto3", "tintin3"],
                         ["foo4", "bar4", "baz4", "toto4", "tintin4"]]

        self.combo = ListBox()
        self.list = ListBox()
        self.echo = Label()

        self.combo.setVisibleItemCount(1)
        self.combo.addChangeListener(self)
        self.list.setVisibleItemCount(10)
        self.list.setMultipleSelect(True)

        for i in range(len(self.sStrings)):
            self.combo.addItem("List %d" % i)
        self.combo.setSelectedIndex(0)
        self.fillList(0)

        self.list.addChangeListener(self)

        horz = HorizontalPanel()
        horz.setVerticalAlignment(HasAlignment.ALIGN_TOP)
        horz.setSpacing(8)
        horz.add(self.combo)
        horz.add(self.list)

        panel = VerticalPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
        panel.add(horz)
        panel.add(self.echo)
        self.initWidget(panel)

        self.echoSelection()

    def onChange(self, sender):
        print sender, self.list, self.combo
        if sender is self.combo:
            print "fill list"
            self.fillList(self.combo.getSelectedIndex())
        elif sender is self.list:
            print "echo "
            self.echoSelection()
        else:
            print "oops"

    def onShow(self):
        pass

    def fillList(self, idx):
        self.list.clear()
        strings = self.sStrings[idx]
        for i in range(len(strings)):
            self.list.addItem(strings[i])

        self.echoSelection()

    def echoSelection(self):
        msg = "Selected items: "
        print msg, self.list.getItemCount()
        for i in range(self.list.getItemCount()):
            if self.list.isItemSelected(i):
                msg += "%d" % i + self.list.getItemText(i) + " "
        self.echo.setText(msg)
class Lists(Sink):
    def __init__(self):
        self.sStrings=[["foo0", "bar0", "baz0", "toto0", "tintin0"],
            ["foo1", "bar1", "baz1", "toto1", "tintin1"],
            ["foo2", "bar2", "baz2", "toto2", "tintin2"],
            ["foo3", "bar3", "baz3", "toto3", "tintin3"],
            ["foo4", "bar4", "baz4", "toto4", "tintin4"]]

        self.combo=ListBox()
        self.list=ListBox()
        self.echo=Label()

        self.combo.setVisibleItemCount(1)
        self.combo.addChangeListener(self)
        self.list.setVisibleItemCount(10)
        self.list.setMultipleSelect(True)
        
        for i in range(len(self.sStrings)):
            self.combo.addItem("List " + i)
        self.combo.setSelectedIndex(0)
        self.fillList(0)
        
        self.list.addChangeListener(self)
        
        horz = HorizontalPanel()
        horz.setVerticalAlignment(HasAlignment.ALIGN_TOP)
        horz.setSpacing(8)
        horz.add(self.combo)
        horz.add(self.list)
        
        panel = VerticalPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
        panel.add(horz)
        panel.add(self.echo)
        self.setWidget(panel)
        
        self.echoSelection()

    def onChange(self, sender):
        if sender == self.combo:
            self.fillList(self.combo.getSelectedIndex())
        elif sender == self.list:
            self.echoSelection()

    def onShow(self):
        pass
    
    def fillList(self, idx):
        self.list.clear()
        strings = self.sStrings[idx]
        for i in range(len(strings)):
            self.list.addItem(strings[i])

        self.echoSelection()

    def echoSelection(self):
        msg = "Selected items: "
        for i in range(self.list.getItemCount()):
            if self.list.isItemSelected(i):
                msg += self.list.getItemText(i) + " "
        self.echo.setText(msg)