Archived:File Selection in PySymbian
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
Below is the code for class to select a file in a directory tree in PySymbian:
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()


25 Sep
2009