Mercurial > fife-parpg
comparison engine/python/fife/extensions/filebrowser.py @ 598:36b865a9cde7
- added some documentation to filebrowser module
author | chewie@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 26 Aug 2010 20:26:23 +0000 |
parents | 293e812316c0 |
children |
comparison
equal
deleted
inserted
replaced
597:d90526c3918b | 598:36b865a9cde7 |
---|---|
19 # License along with this library; if not, write to the | 19 # License along with this library; if not, write to the |
20 # Free Software Foundation, Inc., | 20 # Free Software Foundation, Inc., |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 # #################################################################### | 22 # #################################################################### |
23 | 23 |
24 """ a filebrowser implementation for pychan """ | |
25 | |
24 import pychan | 26 import pychan |
25 import pychan.widgets as widgets | 27 import pychan.widgets as widgets |
26 import sys | 28 import sys |
27 | 29 |
28 def u2s(string): | 30 def u2s(string): |
29 return string.encode(sys.getfilesystemencoding()) | 31 return string.encode(sys.getfilesystemencoding()) |
30 | 32 |
31 class FileBrowser(object): | 33 class FileBrowser(object): |
32 """ | 34 """ The B{FileBrowser} displays directory and file listings from the vfs. |
33 FileBrowser displays directory and file listings from the vfs. | 35 |
34 The fileSelected parameter is a callback invoked when a file selection has been made; its | 36 B{The fileSelected} parameter is a callback invoked when a file selection has been made; its |
35 signature must be fileSelected(path,filename). If selectdir is set, fileSelected's | 37 signature must be fileSelected(path,filename). |
36 filename parameter should be optional. | 38 |
37 The savefile option provides a box for supplying a new filename that doesn't exist yet. | 39 B{If selectdir} is set, fileSelected's filename parameter should be optional. |
38 The selectdir option allows directories to be selected as well as files. | 40 |
41 B{The savefile} option provides a box for supplying a new filename that doesn't exist yet. | |
42 | |
43 B{The selectdir} option allows directories to be selected as well as files. | |
39 """ | 44 """ |
40 def __init__(self, engine, fileSelected, savefile=False, selectdir=False, extensions=('xml',), guixmlpath="gui/filebrowser.xml"): | 45 def __init__(self, engine, fileSelected, savefile=False, selectdir=False, extensions=('xml',), guixmlpath="gui/filebrowser.xml"): |
46 """ | |
47 @type engine: object | |
48 @param engine: initiated instance of FIFE | |
49 @type fileSelected: function | |
50 @param fileSelected: callback invoked on file selection | |
51 @type savefile: bool | |
52 @param savefile: flag to provide a gui for an usergiven filename | |
53 @type selectdir: bool | |
54 @param selectdir: flag to fire fileSelected without filename | |
55 @type extensions: tuple | |
56 @param extensions: list of extensions the filebrowser should show (defaults to xml) | |
57 @type guixmlpath: string | |
58 @param guixmlpath: path to the xml guifile defaults to (gui/filebrowser.xml) | |
59 """ | |
41 self.engine = engine | 60 self.engine = engine |
42 self.fileSelected = fileSelected | 61 self.fileSelected = fileSelected |
43 | 62 |
44 self._widget = None | 63 self._widget = None |
45 self.savefile = savefile | 64 self.savefile = savefile |
51 self.path = './..' | 70 self.path = './..' |
52 self.dir_list = [] | 71 self.dir_list = [] |
53 self.file_list = [] | 72 self.file_list = [] |
54 | 73 |
55 def showBrowser(self): | 74 def showBrowser(self): |
75 """ create and / or show the gui """ | |
56 if self._widget: | 76 if self._widget: |
57 self.setDirectory(self.path) | 77 self.setDirectory(self.path) |
58 self._widget.show() | 78 self._widget.show() |
59 return | 79 return |
60 | 80 |
70 | 90 |
71 self.setDirectory(self.path) | 91 self.setDirectory(self.path) |
72 self._widget.show() | 92 self._widget.show() |
73 | 93 |
74 def setDirectory(self, path): | 94 def setDirectory(self, path): |
95 """ sets the current directory according to path """ | |
75 path_copy = self.path | 96 path_copy = self.path |
76 self.path = path | 97 self.path = path |
77 if not self._widget: return | 98 if not self._widget: return |
78 | 99 |
79 def decodeList(list): | 100 def decodeList(list): |
111 }) | 132 }) |
112 | 133 |
113 self._widget.adaptLayout() | 134 self._widget.adaptLayout() |
114 | 135 |
115 def _selectDir(self): | 136 def _selectDir(self): |
137 """ callback for directory ListBox """ | |
116 selection = self._widget.collectData('dirList') | 138 selection = self._widget.collectData('dirList') |
117 if selection >= 0 and selection < len(self.dir_list): | 139 if selection >= 0 and selection < len(self.dir_list): |
118 new_dir = u2s(self.dir_list[selection]) | 140 new_dir = u2s(self.dir_list[selection]) |
119 lst = self.path.split('/') | 141 lst = self.path.split('/') |
120 if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.': | 142 if new_dir == '..' and lst[-1] != '..' and lst[-1] != '.': |
124 | 146 |
125 path = '/'.join(lst) | 147 path = '/'.join(lst) |
126 self.setDirectory(path) | 148 self.setDirectory(path) |
127 | 149 |
128 def _selectFile(self): | 150 def _selectFile(self): |
151 """ callback for selectButton, hides filebrowser """ | |
129 self._widget.hide() | 152 self._widget.hide() |
130 selection = self._widget.collectData('fileList') | 153 selection = self._widget.collectData('fileList') |
131 | 154 |
132 if self.savefile: | 155 if self.savefile: |
133 if self._widget.collectData('saveField'): | 156 if self._widget.collectData('saveField'): |