Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:File Selection in PySymbian

From Wiki
Jump to: navigation, search

Archived.pngAquivado: 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.

Article Metadata
Article
Created: hurenkam (14 Aug 2008)
Last edited: hamishwillee (31 May 2013)

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()
This page was last modified on 31 May 2013, at 01:08.
46 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×