#!/usr/bin/env python

import sys
from qt import *

class MultiList:
    def currentItem(self): pass
    def insertListOfStrings(self, list, pos = -1): pass
    def removeItemAt(self, pos): pass
    def getSelectedItems(self): return None

class PyQTList(MultiList, QHBox):
    def __init__(self, parent):
        QHBox.__init__(self, parent)
        self.list = QListBox(self)

    def currentItem(self):
        return self.list.currentItem()

    def insertListOfStrings(self, list, pos = -1):
        self.list.insertStrList(list, -1)

    def removeItemAt(self, pos):
        self.list.removeItem(pos)

    def getSelectedItems(self):
        return [str(self.list.text(self.list.currentItem()))]

# définition d'une nouvelle classe
# héritant du widget QHBox
class MyWidget(QVBox):
    def __init__(self, parent = None, name = None):
        QVBox.__init__(self, parent, name)

        # nous positionnons la fenêtre et lui
        # attribuons une taille spécifique
        self.setGeometry(4, 24, 200, 200)

        lists = QHBox(self)

        # liste 1
        self.list1 = PyQTList(lists)
        self.list1.insertListOfStrings(['Marina', 'Laure', 'Elodie'])

        # liste 2
        self.list2 = PyQTList(lists)
        self.list2.insertListOfStrings(['Charlotte', 'Marie'])

        # boutons
        buttons = QHBox(self)
        toRight = QPushButton("-->", buttons)
        self.connect(toRight, SIGNAL("clicked()"), self.toRight)
        toLeft = QPushButton("<--", buttons)
        self.connect(toLeft, SIGNAL("clicked()"), self.toLeft)

    def toRight(self):
        self.list2.insertListOfStrings(self.list1.getSelectedItems())
        self.list1.removeItemAt(self.list1.currentItem())

    def toLeft(self):
        self.list1.insertListOfStrings(self.list2.getSelectedItems())
        self.list2.removeItemAt(self.list2.currentItem())

# création de l'application
app = QApplication(sys.argv)

# création du widget principal
wgHello = MyWidget()
app.setMainWidget(wgHello)

# exécution de l'application
wgHello.show()
app.exec_loop()

# fin du script adaptateur.py 
