1 from HTMLComponent import *
2 from GUIComponent import *
5 from MenuList import MenuList
7 from Tools.Directories import *
33 def FileEntryComponent(name, absolute = None, isDir = False):
34 res = [ (absolute, isDir) ]
35 res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name))
37 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
39 extension = name.split('.')
40 extension = extension[-1].lower()
41 if EXTENSIONS.has_key(extension):
42 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png"))
46 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
50 class FileList(MenuList, HTMLComponent, GUIComponent):
51 def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False):
52 GUIComponent.__init__(self)
53 self.l = eListboxPythonMultiContent()
55 self.useServiceRef = useServiceRef
56 self.showDirectories = showDirectories
57 self.showFiles = showFiles
59 # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
60 self.matchingPattern = matchingPattern
61 self.changeDir(directory)
63 self.l.setFont(0, gFont("Regular", 18))
65 def getSelection(self):
66 return self.l.getCurrentSelection()[0]
68 def getFileList(self):
71 def changeDir(self, directory):
77 if self.useServiceRef:
78 root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)
79 serviceHandler = eServiceCenter.getInstance()
80 list = serviceHandler.list(root)
87 if s.flags & s.mustDescent:
88 directories.append(s.getPath())
91 print s.getName(), s.flags
95 files = os.listdir(directory)
99 if os.path.isdir(directory + x):
100 directories.append(directory + x + "/")
103 if directory != "/" and self.showDirectories and not self.isTop:
104 self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
106 if self.showDirectories:
107 for x in directories:
108 name = x.split('/')[-2]
109 self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True))
113 if self.useServiceRef:
115 name = path.split('/')[-1]
120 if self.matchingPattern is not None:
121 if re.compile(self.matchingPattern).search(path):
122 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
124 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
126 self.l.setList(self.list)
128 def canDescent(self):
129 return self.getSelection()[1]
132 self.changeDir(self.getSelection()[0])
134 def getFilename(self):
135 return self.getSelection()[0].getPath()
137 def getServiceRef(self):
138 return self.getSelection()[0]
140 GUI_WIDGET = eListbox
142 def postWidgetCreate(self, instance):
143 instance.setContent(self.l)
144 instance.setItemHeight(23)