1 # -*- coding: ISO-8859-1 -*-
2 #===============================================================================
3 # VLC Player Plugin by A. Lätsch 2007
4 # modified by Volker Christian 2008
6 # This is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2, or (at your option) any later
10 #===============================================================================
15 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, gFont
16 from Tools.LoadPixmap import LoadPixmap
17 from Tools.Directories import SCOPE_SKIN_IMAGE, SCOPE_PLUGINS, resolveFilename
18 from Components.MenuList import MenuList
20 from pyexpat import ExpatError
22 from skin import parseFont
40 PLAYLIST_EXTENSIONS = {
41 "m3u": "playlist.png",
42 "pls": "playlist.png",
43 "xspf": "playlist.png",
47 class VlcFileList(MenuList):
48 def __init__(self, getFilesAndDirsCB, baseDir, matchingPattern):
49 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
50 self.font = gFont("Regular", 18)
51 self.l.setFont(0, self.font)
52 self.l.setItemHeight(23)
53 self.l.setBuildFunc(self.buildListboxEntry)
54 self.currentDirectory = baseDir
55 self.getFilesAndDirsCB = getFilesAndDirsCB
56 self.changeRegex(matchingPattern)
58 def applySkin(self, desktop, parent):
60 if self.skinAttributes is not None:
61 for (attrib, value) in self.skinAttributes:
63 self.font = parseFont(value, ((1,1),(1,1)))
64 self.l.setFont(0, self.font)
65 elif attrib == "itemHeight":
66 self.l.setItemHeight(int(value))
68 attribs.append((attrib, value))
69 self.skinAttributes = attribs
70 return MenuList.applySkin(self, desktop, parent)
72 def buildListboxEntry(self, path, isDir, name):
73 size = self.l.getItemSize()
74 height = size.height()
77 (eListboxPythonMultiContent.TYPE_TEXT, height + 15, 0, size.width() - height - 15, height, 0, RT_HALIGN_LEFT, name)
81 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
83 extension = name.split('.')
84 extension = extension[-1].lower()
85 if MEDIA_EXTENSIONS.has_key(extension):
86 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + MEDIA_EXTENSIONS[extension] + ".png"))
87 elif PLAYLIST_EXTENSIONS.has_key(extension):
88 png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/VlcPlayer/") + PLAYLIST_EXTENSIONS[extension])
93 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 0, height, height, png))
99 filelistEntries = self.getFilesAndDirsCB(self.currentDirectory, self.regex)
101 directoryEntries = []
102 if filelistEntries is not None:
103 files, directories = filelistEntries
106 fileEntries.append((path, False, name))
107 for directory in directories:
108 name, path = directory
109 directoryEntries.append((path, True, name))
110 fileEntries.sort(cmp = lambda x, y: cmp(x[0], y[0]))
111 directoryEntries.sort(cmp = lambda x, y: cmp(x[0], y[0]))
113 self.list = directoryEntries + fileEntries
114 self.l.setList(self.list)
120 if e[1] == True and e[0].upper().endswith("VIDEO_TS"):
124 def changeDirectory(self, directory):
125 previousDirectory = self.currentDirectory
126 self.currentDirectory = directory
130 ret = "dvdsimple://" + self.currentDirectory + "/VIDEO_TS", self.currentDirectory
131 self.currentDirectory = previousDirectory
134 ret = None, self.currentDirectory
136 self.currentDirectory = previousDirectory
138 except ExpatError, e:
140 self.currentDirectory = previousDirectory
142 ret = None, self.currentDirectory
146 cur = self.getCurrent()
149 ret = self.changeDirectory(cur[0])
156 def changeRegex(self, matchingPattern):
157 if matchingPattern is not None:
158 self.regex = re.compile(matchingPattern)
162 def getNextFile(self):
163 i = self.getSelectedIndex() + 1
169 return cur[0], cur[2]
173 def getPrevFile(self):
174 i = self.getSelectedIndex() - 1
179 return cur[0], cur[2]