#from __future__ import unicode_literals
# -*- coding: utf-8 -*-
from __future__ import division
from time import time, sleep, strftime, localtime
from sys import argv
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from lib.Combattant import Combattant
from lib.ui.ecran_selectionPj import Ui_spj_fenetre

from lib.outilsSvg import *

class EcranSelectionPj(QDialog):
    """interface de creation/chargement de plateau"""
    def __init__(self, terrain=None, parent=None):
        """initialisation de la fenetre"""
        super (EcranSelectionPj, self).__init__(parent)
        self._pjs = []
        self._nbLignes = 0
        self.createWidgets()

    def createWidgets(self):
        """construction de l'interface"""
        #construction de l'interface
        self.ui = Ui_spj_fenetre()
        self.ui.setupUi(self)
        self.connect(self.ui.spj_ok, SIGNAL("clicked()"), self.ok)
        self.connect(self.ui.spj_annuler, SIGNAL("clicked()"), self.annuler)

    def charger(self, listePj):
        idPj = 0
        for pj in listePj:
            item = QListWidgetItem()
            item.setData(0, idPj)
            item.setIcon(QIcon("img\\{}".format(pj.logo)))
            item.setText(QString().fromUtf8(pj.nom))
            police = QFont(QString("Verdana"))
            police.setBold(True)
            item.setFont(police)
            self.ui.spj_liste.insertItem(idPj, item)
            idPj += 1
        self._nbLignes = idPj
            
    def selection(self):
        return self._pjs

    def ok(self):
        for ligne in range(0, self._nbLignes):
            item = self.ui.spj_liste.item(ligne)
            if self.ui.spj_liste.isItemSelected(item):
                self._pjs.append(str(item.data(ligne).toString().toUtf8()))
        self.done(1)

    def annuler(self):
        self.done(0)
    
        
if __name__ == "__main__":
   app = QApplication(argv)
   lst = chargerUnique("F:\\DMonde\\parties\\Partie1\\groupe")
   dm = EcranSelectionPj()
   dm.charger(lst)
   dm.show()
   r = app.exec_()
   print dm.selection()
   exit(r)      
