diff options
Diffstat (limited to 'lib/python/Components/FileList.py')
| -rw-r--r-- | lib/python/Components/FileList.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/python/Components/FileList.py b/lib/python/Components/FileList.py new file mode 100644 index 00000000..a6b5bf2f --- /dev/null +++ b/lib/python/Components/FileList.py @@ -0,0 +1,64 @@ +from HTMLComponent import * +from GUIComponent import * + +from MenuList import MenuList + +from Tools.Directories import * + +from enigma import * + +RT_HALIGN_LEFT = 0 +RT_HALIGN_RIGHT = 1 +RT_HALIGN_CENTER = 2 +RT_HALIGN_BLOCK = 4 + +RT_VALIGN_TOP = 0 +RT_VALIGN_CENTER = 8 +RT_VALIGN_BOTTOM = 16 + +def FileEntryComponent(name, absolute, isDir = False): + res = [ (absolute, isDir) ] + res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 200, 20, 0, RT_HALIGN_LEFT ,name)) + if isDir: + 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 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): + GUIComponent.__init__(self) + self.l = eListboxPythonMultiContent() + + self.showDirectories = showDirectories + self.showFiles = showFiles + self.changeDir(directory) + + self.l.setFont(0, gFont("Regular", 18)) + + def getSelection(self): + return self.l.getCurrentSelection()[0] + + def changeDir(self, directory): + self.list = [] + + directories = os.listdir(directory) + + if directory != "/" and self.showDirectories: + self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True)) + for x in directories: + if os.path.isdir(directory + x): + if self.showDirectories: + self.list.append(FileEntryComponent(name = x, absolute = directory + x + "/" , isDir = True)) + elif self.showFiles: + self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False)) + self.l.setList(self.list) + + def GUIcreate(self, parent): + self.instance = eListbox(parent) + self.instance.setContent(self.l) + self.instance.setItemHeight(23)
\ No newline at end of file |
