X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/b0c7d04b1afa4e8ab184b8826bb592bef253f1b3..2a8ecd871020fdd668cf5500460e5a6e7851b4b0:/lib/python/Components/FileList.py diff --git a/lib/python/Components/FileList.py b/lib/python/Components/FileList.py index 0c8a8814..e6e072cd 100644 --- a/lib/python/Components/FileList.py +++ b/lib/python/Components/FileList.py @@ -1,22 +1,14 @@ -from HTMLComponent import * -from GUIComponent import * import re +from os import path as os_path, listdir from MenuList import MenuList from Components.Harddisk import harddiskmanager -from Tools.Directories import * +from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename -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 +from enigma import RT_HALIGN_LEFT, eListbox, eListboxPythonMultiContent, \ + eServiceReference, eServiceCenter, gFont +from Tools.LoadPixmap import LoadPixmap EXTENSIONS = { "mp3": "music", @@ -25,6 +17,7 @@ EXTENSIONS = { "jpg": "picture", "jpeg": "picture", "png": "picture", + "bmp": "picture", "ts": "movie", "avi": "movie", "mpg": "movie", @@ -35,12 +28,12 @@ def FileEntryComponent(name, absolute = None, isDir = False): res = [ (absolute, isDir) ] res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name)) if isDir: - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png")) + png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png")) else: extension = name.split('.') extension = extension[-1].lower() if EXTENSIONS.has_key(extension): - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png")) + png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png")) else: png = None if png is not None: @@ -48,11 +41,9 @@ def FileEntryComponent(name, absolute = None, isDir = False): return res -class FileList(MenuList, HTMLComponent, GUIComponent): - def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False): - GUIComponent.__init__(self) - self.l = eListboxPythonMultiContent() - +class FileList(MenuList): + def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False, enableWrapAround = False): + MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent) self.mount_point = None self.current_directory = None self.useServiceRef = useServiceRef @@ -64,36 +55,61 @@ class FileList(MenuList, HTMLComponent, GUIComponent): self.changeDir(directory) self.l.setFont(0, gFont("Regular", 18)) - + self.l.setItemHeight(23) + self.serviceHandler = eServiceCenter.getInstance() + def getSelection(self): if self.l.getCurrentSelection() is None: return None return self.l.getCurrentSelection()[0] - + + def getCurrentEvent(self): + l = self.l.getCurrentSelection() + if not l or l[0][1] == True: + return None + else: + return self.serviceHandler.info(l[0][0]).getEvent(l[0][0]) + def getFileList(self): return self.list - + def changeDir(self, directory, select = None): self.list = [] - + # if we are just entering from the list of mount points: if self.current_directory is None: - self.mount_point = directory + if directory is None: + self.mount_point = None + else: + # Sort Mountpoints by length (longest first) + sortedp = harddiskmanager.getMountedPartitions() + sortedp.sort(key=lambda p: 0 - len(p.mountpoint)) + + # Search for the longest matching mp (should at least match /) + for p in sortedp: + if directory.startswith(p.mountpoint): + self.mount_point = p.mountpoint + if p.mountpoint != "/": + self.mount_point += "/" + break self.current_directory = directory directories = [] files = [] - + if directory is None: # present available mountpoints print "listing partitions:" for p in harddiskmanager.getMountedPartitions(): - self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint, isDir = True)) + if p.mountpoint == "/": + self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint, isDir = True)) + else: + self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint + "/", isDir = True)) files = [ ] directories = [ ] elif self.useServiceRef: root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory) serviceHandler = eServiceCenter.getInstance() list = serviceHandler.list(root) - + while 1: s = list.getNext() if not s.valid(): @@ -107,14 +123,14 @@ class FileList(MenuList, HTMLComponent, GUIComponent): directories.sort() files.sort() else: - files = os.listdir(directory) + files = listdir(directory) files.sort() tmpfiles = files[:] for x in tmpfiles: - if os.path.isdir(directory + x): + if os_path.isdir(directory + x): directories.append(directory + x + "/") files.remove(x) - + if directory is not None and self.showDirectories and not self.isTop: if directory == self.mount_point: self.list.append(FileEntryComponent(name = ".. (" +_("List of Storage Devices") + ")", absolute = None, isDir = True)) @@ -134,7 +150,7 @@ class FileList(MenuList, HTMLComponent, GUIComponent): else: path = directory + x name = x - + if self.matchingPattern is not None: if re.compile(self.matchingPattern).search(path): self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False)) @@ -142,7 +158,7 @@ class FileList(MenuList, HTMLComponent, GUIComponent): self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False)) self.l.setList(self.list) - + if select is not None: i = 0 self.moveToIndex(0) @@ -163,12 +179,12 @@ class FileList(MenuList, HTMLComponent, GUIComponent): if self.getSelection() is None: return False return self.getSelection()[1] - + def descent(self): if self.getSelection() is None: return self.changeDir(self.getSelection()[0], select = self.current_directory) - + def getFilename(self): if self.getSelection() is None: return None @@ -185,8 +201,15 @@ class FileList(MenuList, HTMLComponent, GUIComponent): return x return None - GUI_WIDGET = eListbox + def execBegin(self): + harddiskmanager.on_partition_list_change.append(self.partitionListChanged) - def postWidgetCreate(self, instance): - instance.setContent(self.l) - instance.setItemHeight(23) + def execEnd(self): + harddiskmanager.on_partition_list_change.remove(self.partitionListChanged) + + def refresh(self): + self.changeDir(self.current_directory, self.getFilename()) + + def partitionListChanged(self, action, device): + if self.current_directory is None: + self.refresh()