Mercurial > fife-parpg
changeset 258:0b1992a3dfe7
Proper decoding of file names for filebrowser
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 20:23:02 +0000 |
parents | f2195628947b |
children | d5e251efb310 |
files | engine/extensions/filebrowser.py |
diffstat | 1 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/extensions/filebrowser.py Mon Jun 08 19:56:54 2009 +0000 +++ b/engine/extensions/filebrowser.py Mon Jun 08 20:23:02 2009 +0000 @@ -2,6 +2,7 @@ import pychan import pychan.widgets as widgets +import sys class FileBrowser(object): """ @@ -24,8 +25,8 @@ self.extensions = extensions self.path = './..' - self.dir_list = ('..',) + self.engine.getVFS().listDirectories(self.path) - self.file_list = self.engine.getVFS().listFiles(self.path) + self.dir_list = [] + self.file_list = [] def showBrowser(self): if self._widget: @@ -53,9 +54,29 @@ else: lst.append(new_dir) self.path = '/'.join(lst) + + + def decodeList(list): + fs_encoding = sys.getfilesystemencoding() + if fs_encoding is None: fs_encoding = "ascii" + + newList = [] + for i in list: + try: + newList.append(unicode(i, fs_encoding)) + except: + newList.append("WARNING: This entry could not be decoded!") + print "WARNING: Coult not decode an item!" + return newList - self.dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path)) - self.file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path)) + self.dir_list = [] + self.file_list = [] + + dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(str(self.path))) + file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(str(self.path))) + + self.dir_list = decodeList(dir_list) + self.file_list = decodeList(file_list) self._widget.distributeInitialData({ 'dirList' : self.dir_list, 'fileList' : self.file_list