1 from HTMLComponent import *
2 from GUIComponent import *
5 from MenuList import MenuList
7 from Tools.Directories import *
32 def FileEntryComponent(name, absolute, isDir = False):
33 res = [ (absolute, isDir) ]
34 res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 200, 20, 0, RT_HALIGN_LEFT ,name))
36 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
38 extension = name.split('.')
39 extension = extension[-1]
40 if EXTENSIONS.has_key(extension):
41 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png"))
43 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
47 class FileList(HTMLComponent, GUIComponent, MenuList):
48 def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None):
49 GUIComponent.__init__(self)
50 self.l = eListboxPythonMultiContent()
52 self.showDirectories = showDirectories
53 self.showFiles = showFiles
54 # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
55 self.matchingPattern = matchingPattern
56 self.changeDir(directory)
58 self.l.setFont(0, gFont("Regular", 18))
60 def getSelection(self):
61 return self.l.getCurrentSelection()[0]
63 def changeDir(self, directory):
66 files = os.listdir(directory)
69 if directory != "/" and self.showDirectories:
70 self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
74 if os.path.isdir(directory + x):
78 if self.showDirectories:
80 self.list.append(FileEntryComponent(name = x, absolute = directory + x + "/" , isDir = True))
85 if self.matchingPattern is not None:
86 if re.compile(self.matchingPattern).search(x):
87 self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
89 self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
91 self.l.setList(self.list)
93 def GUIcreate(self, parent):
94 self.instance = eListbox(parent)
95 self.instance.setContent(self.l)
96 self.instance.setItemHeight(23)