Correction des liaisons entre syllabes.
[minwii.git] / src / minwii / widgets / songfilebrowser.py
1 # -*- coding: utf-8 -*-
2 """
3 Boîte de dialogue pour sélection des chansons.
4
5 $Id$
6 $URL$
7 """
8
9 from pgu.gui import FileDialog
10 import os
11 from xml.etree import ElementTree
12
13 class FileOpenDialog(FileDialog):
14
15
16
17 def __init__(self, path):
18 FileDialog.__init__(self,
19 title_txt="Ouvrir une chanson",
20 button_txt="Ouvrir",
21 path=path,
22 )
23
24 def _list_dir_(self):
25 self.input_dir.value = self.curdir
26 self.input_dir.pos = len(self.curdir)
27 self.input_dir.vpos = 0
28 dirs = []
29 files = []
30 try:
31 for i in os.listdir(self.curdir):
32 if i.startswith('.') : continue
33 if os.path.isdir(os.path.join(self.curdir, i)): dirs.append(i)
34 else: files.append(i)
35 except:
36 self.input_file.value = "Dossier innacessible !"
37
38 dirs.sort()
39 dirs.insert(0, '..')
40
41 files.sort()
42 for i in dirs:
43 self.list.add(i, image=self.dir_img, value=i)
44
45 for i in files:
46 if not i.endswith('.xml') :
47 continue
48 filepath = os.path.join(self.curdir, i)
49 self.list.add(FileOpenDialog.getSongTitle(filepath), value=i)
50
51 self.list.set_vertical_scroll(0)
52
53 @staticmethod
54 def getSongTitle(file) :
55 it = ElementTree.iterparse(file, ['start', 'end'])
56 creditFound = False
57
58 for evt, el in it :
59 if el.tag == 'credit' :
60 creditFound = True
61 if el.tag == 'credit-words' and creditFound:
62 return el.text.encode('iso-8859-1')
63 if el.tag == 'part-list' :
64 # plus de chance de trouver un titre
65 return os.path.basename(file)