# -*- coding: utf-8 -*-
'''
Created on 17 dec. 2009

@author: samsam
'''

import pgu.gui as pguGui
import os
import constants

class MINWiiDialog(pguGui.FileDialog):
    '''
    classdocs
    '''
    
    def __init__(self, font = None, width = 800, height = 600,path=None):
        pguGui.FileDialog.__init__(self,title_txt = "Choisir une chanson", customFont = font,customWidth = width, customHeight = height,folderText = "", fileText = "",path =path,showCurDir = False)
    
    def _list_dir_(self):
        self.input_dir.value = self.curdir
        self.input_dir.pos = len(self.curdir)
        self.input_dir.vpos = 0
        dirs = []
        files = []
        try:
            for i in os.listdir(self.curdir):
                if os.path.isdir(os.path.join(self.curdir, i)): dirs.append(i)
                else: files.append(i)
        except:
            self.input_file.value = "Opps! no access"
        #if '..' not in dirs: dirs.append('..')
        dirs.sort()
        dirs = ['..'] + dirs
        
        files.sort()
        for i in dirs:
            #item = ListItem(image=self.dir_img, text=i, value=i)
            if self.customFont == None :
                self.list.add(i,image=self.dir_img,value=i)
            else :
                if i == ".." or i[0] != ".":
                    label = pguGui.basic.Label(i,font = self.customFont)
                    self.list.add(label,image=self.dir_img,value=i)
        for i in files:
            #item = ListItem(image=None, text=i, value=i)
            if self.customFont == None :
                self.list.add(i,value=i)
            else:
                if i.endswith(".smwi"):
                    key = i[:-5]
                    if key in constants.reversedReadabilityDict :                     
                        label = pguGui.basic.Label(constants.reversedReadabilityDict[key],font = self.customFont)
                    else :
                        label = pguGui.basic.Label(key,font = self.customFont)
                    self.list.add(label,value=i)
                elif i.endswith(".xml") :
                    # TODO : afficher le Titre de la chanson au lieu du nom
                    # de fichier
                    label = pguGui.basic.Label(i, font=self.customFont)
                    self.list.add(label,value=i)
        #self.list.resize()
        self.list.set_vertical_scroll(0)
        #self.list.repaintall()
        