from pyswt import *

class mylistener(SelectionListener):

    def widgetSelected(self, event):
        print "hello"

    #def widgetDefaultSelected(self, event):
    #    pass

class test:
    def __init__(self):
        self.display = Display()
        self.shell = Shell(self.display)
        self.shell.setText("hello")

        layout = RowLayout()
        layout.justify = True
        layout.pack = True

        self.shell.setLayout(layout)

        print self.shell.getText()

        print SWT.PUSH

        listener = mylistener()
        for i in range(10):
            b = Button(self.shell, SWT.PUSH)
            l = Label(self.shell, SWT.None)
            b.setText("button %d" % i)
            l.setText("label %d" % i)
            b.addSelectionListener(listener)

    def run(self):
        self.shell.pack()
        self.shell.open()
        while not self.shell.isDisposed():
            if not self.display.readAndDispatch():
                self.display.sleep()
        self.display.dispose()

if __name__ == "__main__":
    t = test()
    t.run()