# HG changeset patch # User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1256847548 0 # Node ID dcf6f6091868a1d3b014f539e1e6a451b3e1358e # Parent 54cf58876c3137b1b282ef649b95fcd3b166aa01 Filebrowser: * Created a new function setDirectory. Separated the code from the _selectDir callback * Filebrowser will now refresh current directory after being reopened (Fixes #391) diff -r 54cf58876c31 -r dcf6f6091868 engine/extensions/filebrowser.py --- a/engine/extensions/filebrowser.py Wed Oct 21 16:05:40 2009 +0000 +++ b/engine/extensions/filebrowser.py Thu Oct 29 20:19:08 2009 +0000 @@ -54,31 +54,27 @@ def showBrowser(self): if self._widget: + self.setDirectory(self.path) self._widget.show() return + self._widget = pychan.loadXML(self.guixmlpath) self._widget.mapEvents({ - 'dirList' : self._setDirectory, + 'dirList' : self._selectDir, 'selectButton' : self._selectFile, 'closeButton' : self._widget.hide }) - self._setDirectory() if self.savefile: self._file_entry = widgets.TextField(name='saveField', text=u'') self._widget.findChild(name="fileColumn").addChild(self._file_entry) + + self.setDirectory(self.path) self._widget.show() - - def _setDirectory(self): - selection = self._widget.collectData('dirList') - if not (selection < 0): - new_dir = u2s(self.dir_list[selection]) - lst = self.path.split('/') - if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.': - lst.pop() - else: - lst.append(new_dir) - self.path = '/'.join(lst) - + + def setDirectory(self, path): + self.path = path + if not self._widget: return + def decodeList(list): fs_encoding = sys.getfilesystemencoding() if fs_encoding is None: fs_encoding = "ascii" @@ -90,8 +86,6 @@ newList.append(unicode(i, fs_encoding, 'replace')) print "WARNING: Could not decode item:", i return newList - - self.dir_list = [] self.file_list = [] @@ -105,6 +99,21 @@ 'dirList' : self.dir_list, 'fileList' : self.file_list }) + + self._widget.adaptLayout() + + def _selectDir(self): + selection = self._widget.collectData('dirList') + if selection >= 0 and selection < len(self.dir_list): + new_dir = u2s(self.dir_list[selection]) + lst = self.path.split('/') + if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.': + lst.pop() + else: + lst.append(new_dir) + + path = '/'.join(lst) + self.setDirectory(path) def _selectFile(self): self._widget.hide()