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 | |
| parent | 7319cb85c7a9a6304ac92a7854a5d79c9d9f115b (diff) | |
| download | enigma2-f458abcfbe30c3e3062a41b88d3244147bdc0607.tar.gz enigma2-f458abcfbe30c3e3062a41b88d3244147bdc0607.zip | |
add FileList component for browsing files and directories
Diffstat (limited to 'lib/python')
| -rw-r--r-- | lib/python/Components/FileList.py | 64 | ||||
| -rw-r--r-- | lib/python/Components/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/python/Components/__init__.py | 3 | ||||
| -rw-r--r-- | lib/python/Plugins/test/plugin.py | 22 |
4 files changed, 82 insertions, 9 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 diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index 7416ea35..14eb23c5 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -12,5 +12,5 @@ install_PYTHON = \ EpgList.py ScrollLabel.py Timezones.py Language.py HelpMenuList.py \ BlinkingPixmap.py Pixmap.py ConditionalWidget.py Slider.py LanguageList.py \ PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \ - FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py + FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py diff --git a/lib/python/Components/__init__.py b/lib/python/Components/__init__.py index 38be156e..c006cba2 100644 --- a/lib/python/Components/__init__.py +++ b/lib/python/Components/__init__.py @@ -6,4 +6,5 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo", "components", "config", "TimerList", "TimeInput", "MovieList", "InputDevice", "ServicePosition", "IPAddress", "VariableIP", "IPGateway", "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry", - "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck"] + "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck", + "FileList" ] diff --git a/lib/python/Plugins/test/plugin.py b/lib/python/Plugins/test/plugin.py index 1500dd8d..0a375335 100644 --- a/lib/python/Plugins/test/plugin.py +++ b/lib/python/Plugins/test/plugin.py @@ -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.FileList import FileEntryComponent, FileList from Plugins.Plugin import PluginDescriptor import os @@ -12,21 +13,23 @@ import os class Test(Screen): skin = """ <screen position="100,100" size="550,400" title="Test" > - <widget name="text" position="0,0" size="550,25" font="Regular;20" /> + <!--widget name="text" position="0,0" size="550,25" font="Regular;20" /--> + <widget name="list" position="10,0" size="190,250" scrollbarMode="showOnDemand" /> </screen>""" - def __init__(self, session, args = None): self.skin = Test.skin Screen.__init__(self, session) - self["text"] = Input("1234", maxSize=True, type=Input.NUMBER) + self["list"] = FileList("/") + + #self["text"] = Input("1234", maxSize=True, type=Input.NUMBER) - self["actions"] = NumberActionMap(["WizardActions", "InputActions"], + self["actions"] = NumberActionMap(["WizardActions", "InputActions"], { - "ok": self.close, + "ok": self.ok, "back": self.close, - "left": self.keyLeft, - "right": self.keyRight, +# "left": self.keyLeft, +# "right": self.keyRight, "1": self.keyNumberGlobal, "2": self.keyNumberGlobal, "3": self.keyNumberGlobal, @@ -45,6 +48,11 @@ class Test(Screen): def keyRight(self): self["text"].right() + def ok(self): + selection = self["list"].getSelection() + if selection[1] == True: # isDir + self["list"].changeDir(selection[0]) + def keyNumberGlobal(self, number): print "pressed", number self["text"].number(number) |
