Mercurial > urwid-satext
comparison urwid_satext/files_management.py @ 66:287ff3e1edd1
removed trailing spaces
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 21 Dec 2013 16:51:14 +0100 |
parents | 5cef69971f23 |
children | eddb8369ba06 |
comparison
equal
deleted
inserted
replaced
65:090f3e0754d3 | 66:287ff3e1edd1 |
---|---|
27 import gettext | 27 import gettext |
28 gettext.install('urwid_satext', unicode=True) | 28 gettext.install('urwid_satext', unicode=True) |
29 | 29 |
30 class PathEdit(sat_widgets.AdvancedEdit): | 30 class PathEdit(sat_widgets.AdvancedEdit): |
31 """AdvancedEdit with manage file paths""" | 31 """AdvancedEdit with manage file paths""" |
32 | 32 |
33 def keypress(self, size, key): | 33 def keypress(self, size, key): |
34 if key == '~' and self.edit_pos==0: | 34 if key == '~' and self.edit_pos==0: |
35 expanded = os.path.expanduser('~') | 35 expanded = os.path.expanduser('~') |
36 self.set_edit_text(os.path.normpath(expanded+'/'+self.edit_text)) | 36 self.set_edit_text(os.path.normpath(expanded+'/'+self.edit_text)) |
37 self.set_edit_pos(len(expanded)+1) | 37 self.set_edit_pos(len(expanded)+1) |
42 pos = (before[:-1] if before.endswith('/') else before).rfind("/")+1 | 42 pos = (before[:-1] if before.endswith('/') else before).rfind("/")+1 |
43 self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:]) | 43 self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:]) |
44 self.set_edit_pos(pos) | 44 self.set_edit_pos(pos) |
45 return | 45 return |
46 else: | 46 else: |
47 return super(PathEdit, self).keypress(size, key) | 47 return super(PathEdit, self).keypress(size, key) |
48 | 48 |
49 class FilesViewer(urwid.WidgetWrap): | 49 class FilesViewer(urwid.WidgetWrap): |
50 """List specialised for files""" | 50 """List specialised for files""" |
51 | 51 |
52 def __init__(self, onPreviousDir, onDirClick, onFileClick = None): | 52 def __init__(self, onPreviousDir, onDirClick, onFileClick = None): |
55 self.key_time = time() | 55 self.key_time = time() |
56 self.onPreviousDir = onPreviousDir | 56 self.onPreviousDir = onPreviousDir |
57 self.onDirClick = onDirClick | 57 self.onDirClick = onDirClick |
58 self.onFileClick = onFileClick | 58 self.onFileClick = onFileClick |
59 self.files_list = urwid.SimpleListWalker([]) | 59 self.files_list = urwid.SimpleListWalker([]) |
60 self.show_hidden = True | 60 self.show_hidden = True |
61 listbox = urwid.ListBox(self.files_list) | 61 listbox = urwid.ListBox(self.files_list) |
62 urwid.WidgetWrap.__init__(self, listbox) | 62 urwid.WidgetWrap.__init__(self, listbox) |
63 | 63 |
64 def keypress(self, size, key): | 64 def keypress(self, size, key): |
65 if key=='meta h': | 65 if key=='meta h': |
100 if os.path.isdir(fullpath): | 100 if os.path.isdir(fullpath): |
101 directories.append(filename) | 101 directories.append(filename) |
102 else: | 102 else: |
103 files.append(filename) | 103 files.append(filename) |
104 except OSError: | 104 except OSError: |
105 self.files_list.append(urwid.Text(("warning",_("Impossible to list directory")),'center')) | 105 self.files_list.append(urwid.Text(("warning",_("Impossible to list directory")),'center')) |
106 directories.sort() | 106 directories.sort() |
107 files.sort() | 107 files.sort() |
108 if os.path.abspath(path)!='/' and os.path.abspath(path) != '//': | 108 if os.path.abspath(path)!='/' and os.path.abspath(path) != '//': |
109 previous_wid = sat_widgets.ClickableText(('directory','..')) | 109 previous_wid = sat_widgets.ClickableText(('directory','..')) |
110 urwid.connect_signal(previous_wid,'click',self.onPreviousDir) | 110 urwid.connect_signal(previous_wid,'click',self.onPreviousDir) |
190 start_idx = 0 | 190 start_idx = 0 |
191 for idx in range(start_idx,len(filenames)) + range(0,start_idx): | 191 for idx in range(start_idx,len(filenames)) + range(0,start_idx): |
192 full_path = os.path.join(head,filenames[idx]) | 192 full_path = os.path.join(head,filenames[idx]) |
193 if filenames[idx].lower().startswith(dir_start.lower()) and os.path.isdir(full_path): | 193 if filenames[idx].lower().startswith(dir_start.lower()) and os.path.isdir(full_path): |
194 completion_data['last_dir'] = filenames[idx] | 194 completion_data['last_dir'] = filenames[idx] |
195 return full_path | 195 return full_path |
196 except OSError: | 196 except OSError: |
197 pass | 197 pass |
198 return path | 198 return path |
199 | 199 |
200 def getBookmarks(self): | 200 def getBookmarks(self): |
207 if bm.startswith("file:///"): | 207 if bm.startswith("file:///"): |
208 bookmarks.add(bm[7:].replace('\n','')) | 208 bookmarks.add(bm[7:].replace('\n','')) |
209 except IOError: | 209 except IOError: |
210 info(_('No GTK bookmarks file found')) | 210 info(_('No GTK bookmarks file found')) |
211 pass | 211 pass |
212 | 212 |
213 try: | 213 try: |
214 dom = minidom.parse(kde_bookm) | 214 dom = minidom.parse(kde_bookm) |
215 for elem in dom.getElementsByTagName('bookmark'): | 215 for elem in dom.getElementsByTagName('bookmark'): |
216 bm = elem.getAttribute("href") | 216 bm = elem.getAttribute("href") |
217 if bm.startswith("file:///"): | 217 if bm.startswith("file:///"): |
218 bookmarks.add(bm[7:]) | 218 bookmarks.add(bm[7:]) |
219 except IOError: | 219 except IOError: |
220 info(_('No KDE bookmarks file found')) | 220 info(_('No KDE bookmarks file found')) |
221 pass | 221 pass |
222 | 222 |
223 return bookmarks | 223 return bookmarks |
224 | 224 |
225 def onBookmarkSelected(self, button): | 225 def onBookmarkSelected(self, button): |
226 self.path_wid.set_edit_text(os.path.expanduser(button.get_text())) | 226 self.path_wid.set_edit_text(os.path.expanduser(button.get_text())) |
227 | 227 |
238 def onDirClick(self, wid): | 238 def onDirClick(self, wid): |
239 path = os.path.abspath(self.path_wid.get_edit_text()) | 239 path = os.path.abspath(self.path_wid.get_edit_text()) |
240 if not os.path.isdir(path): | 240 if not os.path.isdir(path): |
241 path = dirname(path) | 241 path = dirname(path) |
242 self.path_wid.set_edit_text(os.path.join(path,wid.get_text())) | 242 self.path_wid.set_edit_text(os.path.join(path,wid.get_text())) |
243 | 243 |
244 def onFileClick(self, wid): | 244 def onFileClick(self, wid): |
245 self.ok_cb(os.path.abspath(os.path.join(self.files_wid.path,wid.get_text()))) | 245 self.ok_cb(os.path.abspath(os.path.join(self.files_wid.path,wid.get_text()))) |