from HTMLComponent import *
from GUIComponent import *
+import re
from MenuList import MenuList
RT_VALIGN_CENTER = 8
RT_VALIGN_BOTTOM = 16
+EXTENSIONS = {
+ "mp3": "music",
+ "wav": "music",
+ "jpg": "picture",
+ "jpeg": "picture",
+ "png": "picture",
+ "ts": "movie",
+ "avi": "movie",
+ "mpg": "movie",
+ "mpeg": "movie",
+ }
+
def FileEntryComponent(name, absolute, isDir = False):
res = [ (absolute, isDir) ]
res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 200, 20, 0, RT_HALIGN_LEFT ,name))
png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/extensions/directory.png"))
else:
# FIXME: detect file extensions correctly
- png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/extensions/" + name[-3:] + ".png"))
+ if EXTENSIONS.has_key(name[-3:]):
+ png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/extensions/" + EXTENSIONS[name[-3:]] + ".png"))
if png is not None:
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
return res
class FileList(HTMLComponent, GUIComponent, MenuList):
- def __init__(self, directory, showDirectories = True, showFiles = True):
+ def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None):
GUIComponent.__init__(self)
self.l = eListboxPythonMultiContent()
self.showDirectories = showDirectories
self.showFiles = showFiles
+ # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
+ self.matchingPattern = matchingPattern
self.changeDir(directory)
self.l.setFont(0, gFont("Regular", 18))
if self.showDirectories:
self.list.append(FileEntryComponent(name = x, absolute = directory + x + "/" , isDir = True))
elif self.showFiles:
+ if self.matchingPattern is not None:
+ if re.compile(self.matchingPattern).search(x):
+ self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
+ else:
self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
+
self.l.setList(self.list)
def GUIcreate(self, parent):