comparison engine/extensions/filebrowser.py @ 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 51cc05d862f2
children a0068e00f076
comparison
equal deleted inserted replaced
257:f2195628947b 258:0b1992a3dfe7
1 # coding: utf-8 1 # coding: utf-8
2 2
3 import pychan 3 import pychan
4 import pychan.widgets as widgets 4 import pychan.widgets as widgets
5 import sys
5 6
6 class FileBrowser(object): 7 class FileBrowser(object):
7 """ 8 """
8 FileBrowser displays directory and file listings from the vfs. 9 FileBrowser displays directory and file listings from the vfs.
9 The fileSelected parameter is a callback invoked when a file selection has been made; its 10 The fileSelected parameter is a callback invoked when a file selection has been made; its
22 23
23 self.guixmlpath = guixmlpath 24 self.guixmlpath = guixmlpath
24 25
25 self.extensions = extensions 26 self.extensions = extensions
26 self.path = './..' 27 self.path = './..'
27 self.dir_list = ('..',) + self.engine.getVFS().listDirectories(self.path) 28 self.dir_list = []
28 self.file_list = self.engine.getVFS().listFiles(self.path) 29 self.file_list = []
29 30
30 def showBrowser(self): 31 def showBrowser(self):
31 if self._widget: 32 if self._widget:
32 self._widget.show() 33 self._widget.show()
33 return 34 return
51 if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.': 52 if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.':
52 lst.pop() 53 lst.pop()
53 else: 54 else:
54 lst.append(new_dir) 55 lst.append(new_dir)
55 self.path = '/'.join(lst) 56 self.path = '/'.join(lst)
57
58
59 def decodeList(list):
60 fs_encoding = sys.getfilesystemencoding()
61 if fs_encoding is None: fs_encoding = "ascii"
62
63 newList = []
64 for i in list:
65 try:
66 newList.append(unicode(i, fs_encoding))
67 except:
68 newList.append("WARNING: This entry could not be decoded!")
69 print "WARNING: Coult not decode an item!"
70 return newList
56 71
57 self.dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path)) 72 self.dir_list = []
58 self.file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path)) 73 self.file_list = []
74
75 dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(str(self.path)))
76 file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(str(self.path)))
77
78 self.dir_list = decodeList(dir_list)
79 self.file_list = decodeList(file_list)
59 self._widget.distributeInitialData({ 80 self._widget.distributeInitialData({
60 'dirList' : self.dir_list, 81 'dirList' : self.dir_list,
61 'fileList' : self.file_list 82 'fileList' : self.file_list
62 }) 83 })
63 84