Categories: S60 | Python | Code Examples | How To
File Selection in Python
From Forum Nokia Wiki
Below is the code for class to select a file in a directory tree in PyS60:
import os class FileSelector: def __init__(self,dir=".",ext='.jpg'): self.dir = dir self.ext = ext self.files = {} def iter(fileselector,dir,files): for file in files: b,e = os.path.splitext(file) if e == fileselector.ext: fileselector.files[u'%s' % b] = os.path.join(dir,file) os.path.walk(self.dir,iter,self) self.sortedkeys = self.files.keys() self.sortedkeys.sort() def GetKeys(self): return self.sortedkeys def GetFile(self,index): return self.files[self.sortedkeys[index]]
How to use this code
A simple example to select an image in a subdirectory:
import appuifw import fileselector def Main(): selector = FileSelector("e:\\images",".jpg") index = appuifw.selection_list(selector.GetKeys()) if index is not None: appuifw.note(u"File %s selected." % selector.GetFile(index), "info") else: appuifw.note(u"No file selected.", "info") Main()
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Access point selection panics | tote_b5 | Python | 29 | 2008-07-04 15:03 |
| Problem with install Python SDK on PC | znakharenko | Python | 9 | 2008-08-14 05:29 |
| how can I extend default python library ? | lb213_2000 | Python | 17 | 2007-11-09 15:36 |
| How to link to PYD? | GonzalezM | Python | 33 | 2008-10-07 00:47 |
| Simple WAP download extension | vyskocil | Python | 4 | 2006-07-14 14:16 |
