from pgu.gui import FileDialog
import os
from pgu.gui import FileDialog
import os
+from xml.etree import ElementTree
class FileOpenDialog(FileDialog):
class FileOpenDialog(FileDialog):
files = []
try:
for i in os.listdir(self.curdir):
files = []
try:
for i in os.listdir(self.curdir):
+ if i.startswith('.') : continue
if os.path.isdir(os.path.join(self.curdir, i)): dirs.append(i)
else: files.append(i)
except:
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('..')
+ self.input_file.value = "Dossier innacessible !"
+
files.sort()
for i in dirs:
files.sort()
for i in dirs:
- if i.startswith('.') and i != '..' :
- continue
self.list.add(i, image=self.dir_img, value=i)
for i in files:
self.list.add(i, image=self.dir_img, value=i)
for i in files:
- if i.startswith('.') or (not i.endswith('.xml')) :
+ if not i.endswith('.xml') :
- self.list.add(i,value=i)
-
+ filepath = os.path.join(self.curdir, i)
+ self.list.add(FileOpenDialog.getSongTitle(filepath), value=i)
+
self.list.set_vertical_scroll(0)
self.list.set_vertical_scroll(0)
+
+ @staticmethod
+ def getSongTitle(file) :
+ it = ElementTree.iterparse(file, ['start', 'end'])
+ creditFound = False
+
+ for evt, el in it :
+ if el.tag == 'credit' :
+ creditFound = True
+ if el.tag == 'credit-words' and creditFound:
+ return el.text.encode('iso-8859-1')
+ if el.tag == 'part-list' :
+ # plus de chance de trouver un titre
+ return os.path.basename(file)
\ No newline at end of file