add ability to use regular expressions to filter files to display in the FileList
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Tue, 21 Feb 2006 19:31:56 +0000 (19:31 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Tue, 21 Feb 2006 19:31:56 +0000 (19:31 +0000)
transform the test plugin into an image viewer for png files

lib/python/Components/FileList.py
lib/python/Plugins/test/plugin.py

index a6b5bf2..66270e6 100644 (file)
@@ -1,5 +1,6 @@
 from HTMLComponent import *
 from GUIComponent import *
+import re
 
 from MenuList import MenuList
 
@@ -30,12 +31,14 @@ def FileEntryComponent(name, absolute, isDir = False):
        return res
 
 class FileList(HTMLComponent, GUIComponent, MenuList):
-       def __init__(self, directory, showDirectories = True, showFiles = True):
+       def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None):
                GUIComponent.__init__(self)
                self.l = eListboxPythonMultiContent()
 
                self.showDirectories = showDirectories
                self.showFiles = showFiles
+               # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
+               self.matchingPattern = matchingPattern
                self.changeDir(directory)
 
                self.l.setFont(0, gFont("Regular", 18))
@@ -55,7 +58,12 @@ class FileList(HTMLComponent, GUIComponent, MenuList):
                                if self.showDirectories:
                                        self.list.append(FileEntryComponent(name = x, absolute = directory + x + "/" , isDir = True))
                        elif self.showFiles:
+                               if self.matchingPattern is not None:
+                                       if re.compile(self.matchingPattern).search(x):
+                                               self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
+                               else:
                                        self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False))
+                               
                self.l.setList(self.list)
                                
        def GUIcreate(self, parent):
index 0a37533..668515f 100644 (file)
@@ -5,6 +5,7 @@ from Components.ActionMap import NumberActionMap
 from Components.Label import Label
 from Components.Input import Input
 from Components.GUIComponent import *
+from Components.Pixmap import Pixmap
 from Components.FileList import FileEntryComponent, FileList
 from Plugins.Plugin import PluginDescriptor
 
@@ -15,13 +16,15 @@ class Test(Screen):
                <screen position="100,100" size="550,400" title="Test" >
                        <!--widget name="text" position="0,0" size="550,25" font="Regular;20" /-->
                        <widget name="list" position="10,0" size="190,250" scrollbarMode="showOnDemand" />
+                       <widget name="pixmap" position="200,0" size="190,250" />
                </screen>"""
        def __init__(self, session, args = None):
                self.skin = Test.skin
                Screen.__init__(self, session)
 
-               self["list"] = FileList("/")
-
+               self["list"] = FileList("/", matchingPattern = "^.*\.png")
+               self["pixmap"] = Pixmap()
+               
                #self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
                                
                self["actions"] = NumberActionMap(["WizardActions", "InputActions"],
@@ -52,6 +55,8 @@ class Test(Screen):
                selection = self["list"].getSelection()
                if selection[1] == True: # isDir
                        self["list"].changeDir(selection[0])
+               else:
+                       self["pixmap"].instance.setPixmapFromFile(selection[0])
        
        def keyNumberGlobal(self, number):
                print "pressed", number