1 from HTMLComponent import *
2 from GUIComponent import *
5 from os import path as os_path, listdir
6 from MenuList import MenuList
7 from Components.Harddisk import harddiskmanager
9 from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
11 from enigma import RT_HALIGN_LEFT, loadPNG, eListbox, eListboxPythonMultiContent, \
12 eServiceReference, eServiceCenter, gFont
28 def FileEntryComponent(name, absolute = None, isDir = False):
29 res = [ (absolute, isDir) ]
30 res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name))
32 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
34 extension = name.split('.')
35 extension = extension[-1].lower()
36 if EXTENSIONS.has_key(extension):
37 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png"))
41 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
45 class FileList(MenuList, HTMLComponent, GUIComponent):
46 def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False):
47 GUIComponent.__init__(self)
48 self.l = eListboxPythonMultiContent()
50 self.mount_point = None
51 self.current_directory = None
52 self.useServiceRef = useServiceRef
53 self.showDirectories = showDirectories
54 self.showFiles = showFiles
56 # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
57 self.matchingPattern = matchingPattern
58 self.changeDir(directory)
60 self.l.setFont(0, gFont("Regular", 18))
62 def getSelection(self):
63 if self.l.getCurrentSelection() is None:
65 return self.l.getCurrentSelection()[0]
67 def getFileList(self):
70 def changeDir(self, directory, select = None):
73 # if we are just entering from the list of mount points:
74 if self.current_directory is None:
75 self.mount_point = directory
76 self.current_directory = directory
80 if directory is None: # present available mountpoints
81 print "listing partitions:"
82 for p in harddiskmanager.getMountedPartitions():
83 if p.mountpoint == "/":
84 self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint, isDir = True))
86 self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint + "/", isDir = True))
89 elif self.useServiceRef:
90 root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)
91 serviceHandler = eServiceCenter.getInstance()
92 list = serviceHandler.list(root)
99 if s.flags & s.mustDescent:
100 directories.append(s.getPath())
103 print s.getName(), s.flags
107 files = listdir(directory)
111 if os_path.isdir(directory + x):
112 directories.append(directory + x + "/")
115 if directory is not None and self.showDirectories and not self.isTop:
116 if directory == self.mount_point:
117 self.list.append(FileEntryComponent(name = ".. (" +_("List of Storage Devices") + ")", absolute = None, isDir = True))
119 self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
121 if self.showDirectories:
122 for x in directories:
123 name = x.split('/')[-2]
124 self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True))
128 if self.useServiceRef:
130 name = path.split('/')[-1]
135 if self.matchingPattern is not None:
136 if re.compile(self.matchingPattern).search(path):
137 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
139 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
141 self.l.setList(self.list)
143 if select is not None:
149 if isinstance(p, eServiceReference):
156 def getCurrentDirectory(self):
157 return self.current_directory
159 def canDescent(self):
160 if self.getSelection() is None:
162 return self.getSelection()[1]
165 if self.getSelection() is None:
167 self.changeDir(self.getSelection()[0], select = self.current_directory)
169 def getFilename(self):
170 if self.getSelection() is None:
172 x = self.getSelection()[0]
173 if isinstance(x, eServiceReference):
177 def getServiceRef(self):
178 if self.getSelection() is None:
180 x = self.getSelection()[0]
181 if isinstance(x, eServiceReference):
185 GUI_WIDGET = eListbox
187 def postWidgetCreate(self, instance):
188 instance.setContent(self.l)
189 instance.setItemHeight(23)