diff options
| author | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2006-02-21 18:50:23 +0000 |
|---|---|---|
| committer | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2006-02-21 18:50:23 +0000 |
| commit | f458abcfbe30c3e3062a41b88d3244147bdc0607 (patch) | |
| tree | 43b878a27855eccecc1cf3f35820a234afcc375a /lib/python/Components/FileList.py | |
| parent | 7319cb85c7a9a6304ac92a7854a5d79c9d9f115b (diff) | |
| download | enigma2-f458abcfbe30c3e3062a41b88d3244147bdc0607.tar.gz enigma2-f458abcfbe30c3e3062a41b88d3244147bdc0607.zip | |
add FileList component for browsing files and directories
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 |
