diff options
author | hut <hut@lavabit.com> | 2010-01-24 23:08:44 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-24 23:08:44 +0100 |
commit | ea87d00524778fd7188180acb1119d0ecb43613e (patch) | |
tree | 29bf4eaf14775b58d92cf107978c01e335c587ee /ranger | |
parent | 8efa96989df84a89c9bb0154137a0d40731c035d (diff) | |
download | ranger-ea87d00524778fd7188180acb1119d0ecb43613e.tar.gz |
cleanups
Diffstat (limited to 'ranger')
34 files changed, 183 insertions, 174 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py index f76437d9..a93e2771 100644 --- a/ranger/__main__.py +++ b/ranger/__main__.py @@ -74,9 +74,9 @@ def main(): if args.cd_after_exit: sys.stderr = sys.__stdout__ - + ranger.debug = args.debug - + SettingsAware._setup() # Initialize objects diff --git a/ranger/actions.py b/ranger/actions.py index 25665f0b..d00997c8 100644 --- a/ranger/actions.py +++ b/ranger/actions.py @@ -110,7 +110,7 @@ class Actions(EnvironmentAware, SettingsAware): if hasattr(self.ui, 'redraw_main_column'): self.ui.redraw_main_column() - + def tag_remove(self, movedown=None): try: remove = self.tags.remove @@ -154,7 +154,7 @@ class Actions(EnvironmentAware, SettingsAware): except: return self.env.enter_dir(directory) - + def move_right(self, mode=0, narg=None): """Enter the current directory or execute the current file""" cf = self.env.cf @@ -170,11 +170,11 @@ class Actions(EnvironmentAware, SettingsAware): def history_go(self, relative): """Move back and forth in the history""" self.env.history_go(relative) - + def handle_mouse(self): """Handle mouse-buttons if one was pressed""" self.ui.handle_mouse() - + def display_command_help(self, console_widget): if not hasattr(self.ui, 'open_pager'): return @@ -197,7 +197,7 @@ class Actions(EnvironmentAware, SettingsAware): pager = self.ui.open_pager() lines = cleandoc(command.__doc__).split('\n') pager.set_source(lines) - + def display_help(self, topic='index', narg=None): if not hasattr(self.ui, 'open_pager'): return @@ -223,7 +223,7 @@ class Actions(EnvironmentAware, SettingsAware): pager.set_source(["Message Log:"] + list(self.log)) else: pager.set_source(["Message Log:", "No messages!"]) - + def display_file(self): if not hasattr(self.ui, 'open_embedded_pager'): return @@ -252,7 +252,7 @@ class Actions(EnvironmentAware, SettingsAware): def execute_command(self, cmd, **kw): return self.run(cmd, **kw) - + def edit_file(self, file=None): """Calls execute_file with the current file and app='editor'""" if file is None: @@ -318,7 +318,7 @@ class Actions(EnvironmentAware, SettingsAware): if func is not None: self.env.settings['sort'] = str(func) - + def force_load_preview(self): cf = self.env.cf if hasattr(cf, 'unload') and hasattr(cf, 'load_content'): @@ -338,7 +338,7 @@ class Actions(EnvironmentAware, SettingsAware): self.env.pwd.filter = fltr except: pass - + def notify(self, text, duration=4, bad=False): if isinstance(text, Exception): if ranger.debug: @@ -348,7 +348,7 @@ class Actions(EnvironmentAware, SettingsAware): self.log.appendleft(text) if hasattr(self.ui, 'notify'): self.ui.notify(text, duration=duration, bad=bad) - + def mark(self, all=False, toggle=False, val=None, movedown=None): """ A wrapper for the directory.mark_xyz functions. @@ -399,11 +399,11 @@ class Actions(EnvironmentAware, SettingsAware): selected = self.env.get_selection() self.env.copy = set(f for f in selected if f in self.env.pwd.files) self.env.cut = False - + def cut(self): self.copy() self.env.cut = True - + def paste_symlink(self): from os import symlink, getcwd from os.path import join @@ -483,14 +483,14 @@ class Actions(EnvironmentAware, SettingsAware): os.remove(f.path) except OSError as err: self.notify(str(err), bad=True) - + def mkdir(self, name): try: os.mkdir(os.path.join(self.env.pwd.path, name)) except OSError as err: self.notify(str(err), bad=True) - + def rename(self, src, dest): if hasattr(src, 'path'): src = src.path diff --git a/ranger/applications.py b/ranger/applications.py index 1847c6d0..c01e13a7 100644 --- a/ranger/applications.py +++ b/ranger/applications.py @@ -49,7 +49,7 @@ class Applications(FileManagerAware): return self.app_mplayer(context) else: return self.app_editor(context) - + def app_pager(self, context): return ('less', ) + tuple(context) @@ -91,7 +91,7 @@ class Applications(FileManagerAware): return getattr(self, 'app_' + app) except AttributeError: return self.app_default - + def apply(self, app, context): if not app: app = 'default' diff --git a/ranger/commands.py b/ranger/commands.py index 3b552a22..c552053f 100644 --- a/ranger/commands.py +++ b/ranger/commands.py @@ -55,7 +55,7 @@ class Command(FileManagerAware): abs_dirname = dirname(abs_dest) rel_basename = basename(rel_dest) rel_dirname = dirname(rel_dest) - + try: # are we after a directory? if rel_dest.endswith('/') or rel_dest == '': @@ -83,7 +83,7 @@ class Command(FileManagerAware): # more than one result. append no slash, so the user can # manually type in the slash to advance into that directory return (line + join(rel_dirname, dirname) for dirname in dirnames) - + def _tab_directory_content(self): from os.path import dirname, basename, expanduser, join, isdir @@ -104,7 +104,7 @@ class Command(FileManagerAware): abs_dirname = dirname(abs_dest) rel_basename = basename(rel_dest) rel_dirname = dirname(rel_dest) - + try: # are we after a directory? if rel_dest.endswith('/') or rel_dest == '': @@ -140,7 +140,7 @@ class Command(FileManagerAware): class cd(Command): """ :cd <dirname> - + The cd command changes the directory. The command 'cd -' is equivalent to typing ``. @@ -162,7 +162,7 @@ class cd(Command): def tab(self): return self._tab_only_directories() - + def quick_open(self): from os.path import isdir, join, normpath line = parse(self.line) @@ -217,7 +217,7 @@ class find(Command): arg = line.rest(1) except IndexError: return False - + deq = deque(pwd.files) deq.rotate(-pwd.pointer) i = 0 @@ -238,7 +238,7 @@ class find(Command): class quit(Command): """ :quit - + Quits the program immediately. """ @@ -380,7 +380,7 @@ class filter(Command): def execute(self): line = parse(self.line) self.fm.set_filter(line.rest(1)) - + class grep(Command): """ diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py index 56671a42..cab23480 100644 --- a/ranger/container/bookmarks.py +++ b/ranger/container/bookmarks.py @@ -77,7 +77,7 @@ class Bookmarks(object): """Bookmarks <value> to the key '""" self["'"] = value if self.autosave: self.save() - + def __iter__(self): return iter(self.dct.items()) @@ -109,7 +109,7 @@ class Bookmarks(object): """Update the bookmarks from the bookmark file. Useful if two instances are running which define different bookmarks. """ - + try: real_dict = self._load_dict() real_dict_copy = real_dict.copy() @@ -122,12 +122,12 @@ class Bookmarks(object): current = self.dct[key] else: current = None - + if key in self.original_dict: original = self.original_dict[key] else: original = None - + if key in real_dict: real = real_dict[key] else: @@ -180,7 +180,7 @@ class Bookmarks(object): return dct else: raise OSError('Cannot read the given path') - + def _set_dict(self, dct, original): if original is None: original = {} @@ -196,6 +196,6 @@ class Bookmarks(object): return os.stat(self.path).st_mtime except OSError: return None - + def _update_mtime(self): self.last_mtime = self._get_mtime() diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py index 95a9c1b6..c236eb55 100644 --- a/ranger/container/commandlist.py +++ b/ranger/container/commandlist.py @@ -38,7 +38,7 @@ class CommandList(object): def __init__(self): self.commandlist = [] self.paths = {} - + def __getitem__(self, key): """Returns the command with the given key combination""" if isinstance(key, str): @@ -75,7 +75,7 @@ class CommandList(object): current = [] all = [] - + for i in range(len(tup) - 1): current.append(tup[i]) all.append(tuple(current)) @@ -102,7 +102,7 @@ class CommandList(object): return (obj, ) else: raise TypeError('need a str, int or tuple for str_to_tuple') - + def bind(self, fnc, *keys): """create a Command object and assign it to the given key combinations.""" if len(keys) == 0: return @@ -114,7 +114,7 @@ class CommandList(object): self.commandlist.append(cmd) for key in cmd.keys: self.paths[key] = cmd - + def hint(self, text, *keys): """create a Hint object and assign it to the given key combinations.""" if len(keys) == 0: return @@ -126,7 +126,7 @@ class CommandList(object): self.commandlist.append(obj) for key in obj.keys: self.paths[key] = obj - + def alias(self, existing, *new): """bind the <new> keys to the command of the <existing> key""" existing = self._str_to_tuple(existing) @@ -156,7 +156,7 @@ class CommandList(object): """remove all bindings""" self.paths.clear() del self.commandlist[:] - + class Command(object): """Command objects store information about a command""" @@ -166,15 +166,13 @@ class Command(object): def __init__(self, fnc, keys): self.keys = set(keys) self.execute = fnc - + def execute(self, *args): """Execute the command""" - + def execute_wrap(self, displayable): self.execute(cmdarg(displayable)) - -# def __str__(self): -# return 'Cmd({0})'.format(str(self.keys)) + class AliasedCommand(Command): def __init__(self, getter, keys): diff --git a/ranger/container/environment.py b/ranger/container/environment.py index 2f15694b..d8e5e7f8 100644 --- a/ranger/container/environment.py +++ b/ranger/container/environment.py @@ -49,7 +49,7 @@ class Environment(SettingsAware): def key_append(self, key): """Append a key to the keybuffer""" - + # special keys: if key == curses.KEY_RESIZE: self.keybuffer.clear() @@ -59,7 +59,7 @@ class Environment(SettingsAware): def key_clear(self): """Clear the keybuffer""" self.keybuffer.clear() - + def at_level(self, level): """Returns the FileSystemObject at the given level. level 1 => preview @@ -86,12 +86,12 @@ class Environment(SettingsAware): if isinstance(value, FileSystemObject): if value.is_older_than(1200): del self.directories[key] - + def get_selection(self): if self.pwd: return self.pwd.get_selection() return set() - + def get_directory(self, path): """Get the directory object at the given path""" path = abspath(path) @@ -101,7 +101,7 @@ class Environment(SettingsAware): obj = Directory(path) self.directories[path] = obj return obj - + def get_free_space(self, path): from os import statvfs stat = statvfs(path) @@ -117,11 +117,10 @@ class Environment(SettingsAware): path.move_to_obj(last_path) last_path = path - + def history_go(self, relative): """Move relative in history""" if self.history: -# self.enter_dir(self.history.move(relative)) self.history.move(relative).go() def enter_dir(self, path, history = True): diff --git a/ranger/container/history.py b/ranger/container/history.py index 8019d6ff..3445f16a 100644 --- a/ranger/container/history.py +++ b/ranger/container/history.py @@ -20,12 +20,12 @@ class History(object): from collections import deque self.history = deque(maxlen = maxlen) self.history_forward = deque(maxlen = maxlen) - + def add(self, item): if len(self.history) == 0 or self.history[-1] != item: self.history.append(item) self.history_forward.clear() - + def modify(self, item): try: self.history[-1] = item diff --git a/ranger/container/keybuffer.py b/ranger/container/keybuffer.py index b8df2fef..171db20f 100644 --- a/ranger/container/keybuffer.py +++ b/ranger/container/keybuffer.py @@ -29,13 +29,13 @@ class KeyBuffer(object): self.number = None self.queue = deque() self.queue_with_numbers = deque() - + def clear(self): """Clear the keybuffer and restore the initial state""" self.number = None self.queue.clear() self.queue_with_numbers.clear() - + def append(self, key): """ Append a key to the keybuffer, or initial numbers to @@ -52,7 +52,7 @@ class KeyBuffer(object): return else: self.queue.append(key) - + def tuple_with_numbers(self): """Get a tuple of ascii codes.""" return tuple(self.queue_with_numbers) diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 8d8c46e5..d190085a 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -22,7 +22,7 @@ class Tags(object): open(self._filename, 'w') self.sync() - + def __contains__(self, item): return item in self.tags @@ -52,7 +52,7 @@ class Tags(object): else: self.tags.add(item) self.dump() - + def sync(self): try: f = open(self._filename, 'r') @@ -61,7 +61,7 @@ class Tags(object): else: self.tags = self._parse(f) f.close() - + def dump(self): try: f = open(self._filename, 'w') @@ -70,7 +70,7 @@ class Tags(object): else: self._compile(f) f.close() - + def _compile(self, f): for line in self.tags: f.write(line + '\n') diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py index 404fc053..9c1ae5c3 100644 --- a/ranger/defaults/apps.py +++ b/ranger/defaults/apps.py @@ -45,7 +45,7 @@ class CustomApplications(Applications): if f.video: c.flags += 'd' return self.either(c, 'mplayer', 'totem') - + if f.image: return self.app_feh(c) @@ -114,7 +114,7 @@ class CustomApplications(Applications): c.flags += 'p' return tup('aunpack', '-l', c.file.path) return tup('aunpack', c.file.path) - + @depends_on('apvlv') def app_apvlv(self, c): c.flags += 'd' @@ -128,15 +128,15 @@ class CustomApplications(Applications): return tup("make", "install") if c.mode is 2: return tup("make", "clear") - + @depends_on('elinks') def app_elinks(self, c): return tup('elinks', *c) - + @depends_on('opera') def app_elinks(self, c): return tup('opera', *c) - + @depends_on('firefox') def app_firefox(self, c): return tup("firefox", *c) @@ -144,7 +144,7 @@ class CustomApplications(Applications): @depends_on('javac') def app_javac(self, c): return tup("javac", *c) - + @depends_on('java') def app_java(self, c): def strip_extensions(file): @@ -153,15 +153,15 @@ class CustomApplications(Applications): return file.path files_without_extensions = map(strip_extensions, c.files) return tup("java", files_without_extensions) - + @depends_on('zsnes') def app_zsnes(self, c): return tup("zsnes", c.file.path) - + @depends_on('evince') def app_evince(self, c): return tup("evince", *c) - + @depends_on('wine') def app_wine(self, c): return tup("wine", c.file.path) diff --git a/ranger/ext/accumulator.py b/ranger/ext/accumulator.py index 95d0f4d0..f3477ab6 100644 --- a/ranger/ext/accumulator.py +++ b/ranger/ext/accumulator.py @@ -47,7 +47,7 @@ class Accumulator(object): self.pointer = i self.correct_pointer() return self.pointer - + def move_to_obj(self, arg, attr=None): if not arg: return @@ -107,7 +107,7 @@ class Accumulator(object): return lst[self.pointer] == self.pointed_obj except (IndexError, KeyError): return False - + def sync_index(self, **kw): self.move_to_obj(self.pointed_obj, **kw) diff --git a/ranger/ext/human_readable.py b/ranger/ext/human_readable.py index 2626792e..6810c47d 100644 --- a/ranger/ext/human_readable.py +++ b/ranger/ext/human_readable.py @@ -24,7 +24,7 @@ def human_readable(byte, seperator=' '): exponent = int(math.log(byte, 2) / 10) flt = float(byte) / (1 << (10 * exponent)) - + if exponent > MAX_EXPONENT: return '>9000' # off scale diff --git a/ranger/ext/mount_path.py b/ranger/ext/mount_path.py index 5758d36d..a475e4e3 100644 --- a/ranger/ext/mount_path.py +++ b/ranger/ext/mount_path.py @@ -1,3 +1,17 @@ +# Copyright (c) 2009, 2010 hut <hut@lavabit.com> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + from os.path import realpath, abspath, dirname, ismount def mount_path(path): diff --git a/ranger/ext/openstruct.py b/ranger/ext/openstruct.py index eb8d49a9..bf471605 100644 --- a/ranger/ext/openstruct.py +++ b/ranger/ext/openstruct.py @@ -21,7 +21,7 @@ class OpenStruct(object): def __getitem__(self, key): return self.__dict__[key] - + def __setitem__(self, key, value): self.__dict__[key] = value return value diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 0741532d..25da0ca6 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -84,10 +84,10 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.old_filter = self.filter self.old_hidden_filter = self.settings.hidden_filter self.old_reverse = self.settings.reverse - + def get_list(self): return self.files - + def mark_item(self, item, val): item._mark(val) if val: @@ -106,7 +106,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): def toggle_all_marks(self): for item in self.files: self.toggle_mark(item) - + def mark_all(self, val): for item in self.files: self.mark_item(item, val) @@ -114,12 +114,12 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): if not val: del self.marked_items[:] self._clear_marked_items() - + def _gc_marked_items(self): for item in list(self.marked_items): if item.path not in self.filenames: self.marked_items.remove(item) - + def _clear_marked_items(self): for item in self.marked_items: item._mark(False) @@ -134,7 +134,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): return [self.pointed_obj] else: return [] - + def load_bit_by_bit(self): """ Returns a generator which load a part of the directory @@ -234,7 +234,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): if not self.loading: self.load_once() - + if schedule is None: schedule = self.size > 30 @@ -280,7 +280,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.old_directories_first = self.settings.directories_first self.old_sort = self.settings.sort self.old_reverse = self.settings.reverse - + def sort_if_outdated(self): """Sort the containing files if they are outdated""" if self.old_directories_first != self.settings.directories_first \ @@ -344,7 +344,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): self.fm.env.cf = self.pointed_obj except: pass - + def load_content_once(self, *a, **k): """Load the contents of the directory if not done yet""" if not self.content_loaded: @@ -395,7 +395,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): """The number of containing files""" if not self.accessible: raise ranger.fsobject.NotLoadedYet() return len(self.files) - + def __eq__(self, other): """Check for equality of the directories paths""" return isinstance(other, Directory) and self.path == other.path @@ -403,6 +403,6 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): def __neq__(self, other): """Check for inequality of the directories paths""" return not self.__eq__(other) - + def __hash__(self): return hash(self.path) diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 2c375a77..5ede5927 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -14,7 +14,7 @@ CONTAINER_EXTENSIONS = 'rar zip tar gz bz bz2 tgz 7z iso cab'.split() DOCUMENT_EXTENSIONS = 'pdf doc ppt odt'.split() -DOCUMENT_BASENAMES = 'README TODO LICENSE'.split() +DOCUMENT_BASENAMES = 'README TODO LICENSE COPYING INSTALL'.split() from . import T_FILE, T_DIRECTORY, T_UNKNOWN, T_NONEXISTANT, BAD_INFO from ranger.shared import MimeTypeAware, FileManagerAware @@ -75,7 +75,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): def get_description(self): return "Loading " + str(self) - + def __str__(self): """returns a string containing the absolute path""" return str(self.path) @@ -84,12 +84,12 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): """mark the filesystem-object as used at the current time""" import time self.last_used = time.time() - + def is_older_than(self, seconds): """returns whether this object wasn't use()d in the last n seconds""" import time return self.last_used + seconds < time.time() - + def set_mimetype(self): """assign attributes such as self.video according to the mimetype""" try: @@ -109,11 +109,11 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): if self.mimetype == '': self.mimetype = None - + def mark(self, boolean): directory = self.env.get_directory(self.dirname) directory.mark_item(self) - + def _mark(self, boolean): """Called by directory.mark_item() and similar functions""" self.marked = bool(boolean) @@ -172,7 +172,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): if self.islink: self.readlink = os.readlink(self.path) - + def get_permission_string(self): if self.permissions is not None: return self.permissions diff --git a/ranger/fsobject/loader.py b/ranger/fsobject/loader.py index 76fe2d79..fcd416c0 100644 --- a/ranger/fsobject/loader.py +++ b/ranger/fsobject/loader.py @@ -44,12 +44,12 @@ class Loader(FileManagerAware): self.status_generator = status_generator() self.rotate() self.old_item = None - + def rotate(self): """Rotate the throbber""" # TODO: move all throbber logic to UI self.status = next(self.status_generator) - + def add(self, obj): """ Add an object to the queue. @@ -58,7 +58,7 @@ class Loader(FileManagerAware): while obj in self.queue: self.queue.remove(obj) self.queue.appendleft(obj) - + def move(self, _from, to): try: item = self.queue[_from] @@ -73,7 +73,7 @@ class Loader(FileManagerAware): self.queue.append(item) else: raise NotImplementedError - + def remove(self, item=None, index=None): if item is not None and index is None: for test, i in zip(self.queue, range(len(self.queue))): @@ -120,7 +120,7 @@ class Loader(FileManagerAware): self.queue.remove(item) except Exception as err: self.fm.notify(str(err), bad=True) - + def has_work(self): """Is there anything to load?""" return bool(self.queue) diff --git a/ranger/gui/bar.py b/ranger/gui/bar.py index 5e298a88..ba72f07a 100644 --- a/ranger/gui/bar.py +++ b/ranger/gui/bar.py @@ -24,10 +24,10 @@ class Bar(object): def add(self, *a, **kw): self.left.add(*a, **kw) - + def addright(self, *a, **kw): self.right.add(*a, **kw) - + def sumsize(self): return self.left.sumsize() + self.right.sumsize() @@ -57,7 +57,7 @@ class Bar(object): if sumsize < wid: self.fill_gap(' ', (wid - sumsize), gapwidth=True) - + def shrink_by_cutting(self, wid): fixedsize = self.fixedsize() if wid < fixedsize: @@ -83,7 +83,7 @@ class Bar(object): if wid > 0: self.gap.add(char * wid, 'space') - + def combine(self): return self.left + self.gap + self.right @@ -97,10 +97,10 @@ class BarSide(list): if 'fixedsize' in kw: cs.fixed = kw['fixedsize'] self.append(cs) - + def add_space(self, n=1): self.add(' ' * n, 'space') - + def sumsize(self): return sum(len(item) for item in self) @@ -112,7 +112,7 @@ class BarSide(list): else: n += 1 return n - + def nonfixed_items(self): return sum(1 for item in self if not item.fixed) @@ -123,14 +123,14 @@ class ColoredString(object): def __init__(self, string, *lst): self.string = string self.lst = lst - + def cut_off(self, n): n = max(n, min(len(self.string), 1)) self.string = self.string[:-n] def cut_off_to(self, n): self.string = self.string[:n] - + def __len__(self): return len(self.string) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 70961e02..9abc0486 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -94,7 +94,7 @@ class ColorScheme(object): def get_attr(self, *keys): """ Returns the curses attribute for the specified keys - + Ready to use for curses.setattr() """ from curses import color_pair diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py index 2bf70da9..0ebfb96d 100644 --- a/ranger/gui/curses_shortcuts.py +++ b/ranger/gui/curses_shortcuts.py @@ -56,7 +56,7 @@ class CursesShortcuts(SettingsAware): self.win.chgat(y, x, wid, attr) except _curses.error: pass - + def color_reset(self): """Change the colors to the default colors""" CursesShortcuts.color(self, 'reset') diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py index 0f089159..064cedc6 100644 --- a/ranger/gui/defaultui.py +++ b/ranger/gui/defaultui.py @@ -65,7 +65,7 @@ class DefaultUI(UI): self.titlebar.resize(0, 0, 1, x) self.status.resize(y - 1, 0, 1, x) self.console.resize(y - 1, 0, 1, x) - + def notify(self, *a, **k): return self.status.notify(*a, **k) @@ -76,7 +76,7 @@ class DefaultUI(UI): self.pager.visible = False self.pager.focused = False self.browser.visible = True - + def open_pager(self): if self.console.focused: self.console.focused = False @@ -92,7 +92,7 @@ class DefaultUI(UI): def close_embedded_pager(self): self.browser.close_pager() - + def open_console(self, mode, string=''): if self.console.open(mode, string): self.status.msg = None @@ -113,7 +113,7 @@ class DefaultUI(UI): self.browser.visible = False self.taskview.visible = True self.taskview.focused = True - + def redraw_main_column(self): self.browser.main_column.need_redraw = True @@ -125,7 +125,7 @@ class DefaultUI(UI): def scroll(self, relative): if self.browser and self.browser.main_column: self.browser.main_column.scroll(relative) - + def throbber(self, string='.', remove=False): if remove: self.titlebar.throbber = type(self.titlebar).throbber diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py index 5c46a0dc..bfd9a2be 100644 --- a/ranger/gui/displayable.py +++ b/ranger/gui/displayable.py @@ -36,7 +36,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): Additionally, there are these methods: __contains__(item) -- is the item (y, x) inside the widget? - + These attributes are set: Modifiable: @@ -45,7 +45,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): need_redraw -- Should the widget be redrawn? This variable may be set at various places in the script and should eventually be handled (and unset) in the draw() method. - + Read-Only: (i.e. reccomended not to change manually) win -- the own curses window object parent -- the parent (DisplayableContainer) object or None @@ -96,7 +96,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): y, x = item except (ValueError, TypeError): return False - + return self.contains_point(y, x) def draw(self): @@ -142,7 +142,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): if not self.visible: self.win.erase() - + def finalize(self): """ Called after every displayable is done drawing. @@ -215,7 +215,7 @@ class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts): if self.parent: self.y += self.parent.y self.x += self.parent.x - + def __str__(self): return self.__class__.__name__ @@ -248,7 +248,7 @@ class DisplayableContainer(Displayable): self.container = [] Displayable.__init__(self, win) - + # ------------------------------------ extended or overidden methods def poke(self): @@ -308,7 +308,7 @@ class DisplayableContainer(Displayable): obj.parent.remove_child(obj) self.container.append(obj) obj.parent = self - + def remove_child(self, obj): """Remove the object from the container.""" try: @@ -317,7 +317,7 @@ class DisplayableContainer(Displayable): pass else: obj.parent = None - + def _get_focused_obj(self): # Finds a focused displayable object in the container. for displayable in self.container: diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py index b500a5c6..d501e813 100644 --- a/ranger/gui/mouse_event.py +++ b/ranger/gui/mouse_event.py @@ -32,7 +32,7 @@ class MouseEvent(object): if self.y < 0: self.y += 0xFF - + def pressed(self, n): """Returns whether the mouse key n is pressed""" try: diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 32ba114e..f362a011 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -56,7 +56,7 @@ class UI(DisplayableContainer): curses.mousemask(self.mousemask) curses.mouseinterval(0) - + ## this line solves this problem: ## If an action, following a mouse click, includes the ## suspension and re-initializion of the ui (e.g. running a @@ -156,7 +156,7 @@ class UI(DisplayableContainer): """Called after an initialize() call. Override this! """ - + def redraw(self): """Redraw all widgets""" self.poke() diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 4aa232b6..5572e8a4 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -55,7 +55,7 @@ class BrowserColumn(Pager, Widget): Pager.__init__(self, win) Widget.__init__(self, win) self.level = level - + def resize(self, y, x, hei, wid): Widget.resize(self, y, x, hei, wid) @@ -159,7 +159,7 @@ class BrowserColumn(Pager, Widget): if not self._preview_this_file(self.target): Pager.close(self) return - + try: f = open(self.target.path, 'r') except: @@ -311,7 +311,7 @@ class BrowserColumn(Pager, Widget): if projected < upper_limit: return max( 0, original - (lower_limit - projected)) - + return original def _set_scroll_begin(self): @@ -332,6 +332,6 @@ class BrowserColumn(Pager, Widget): if self.target.scroll_begin == old_value: self.target.move(relative = relative) self.target.scroll_begin += relative - + def __str__(self): return self.__class__.__name__ + ' at level ' + str(self.level) diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py index 0f467be2..a6da7ae6 100644 --- a/ranger/gui/widgets/browserview.py +++ b/ranger/gui/widgets/browserview.py @@ -38,7 +38,7 @@ class BrowserView(Widget, DisplayableContainer): self.stretch_ratios = self.ratios[:-2] + \ ((self.ratios[-2] + self.ratios[-1] * 0.9), (self.ratios[-1] * 0.1)) - + offset = 1 - len(ratios) if preview: offset += 1 @@ -82,7 +82,7 @@ class BrowserView(Widget, DisplayableContainer): self.fm.ui.win.move(y, x) except: pass - + def _draw_bookmarks(self): self.need_clear = True @@ -102,7 +102,7 @@ class BrowserView(Widget, DisplayableContainer): key, mark = items string = " " + key + ": " + mark.path self.addnstr(line, 0, string.ljust(maxlen), self.wid) - + def resize(self, y, x, hei, wid): """Resize all the columns according to the given ratio""" DisplayableContainer.resize(self, y, x, hei, wid) @@ -133,7 +133,7 @@ class BrowserView(Widget, DisplayableContainer): pass left += wid - + def click(self, event): n = event.ctrl() and 1 or 3 if event.pressed(4): @@ -142,7 +142,7 @@ class BrowserView(Widget, DisplayableContainer): self.main_column.scroll(relative = n) else: DisplayableContainer.click(self, event) - + def open_pager(self): self.pager.visible = True self.pager.focused = True @@ -152,7 +152,7 @@ class BrowserView(Widget, DisplayableContainer): self.container[-3].visible = False except IndexError: pass - + def close_pager(self): self.pager.visible = False self.pager.focused = False @@ -162,7 +162,7 @@ class BrowserView(Widget, DisplayableContainer): self.container[-3].visible = True except IndexError: pass - + def poke(self): DisplayableContainer.poke(self) if self.settings.collapse_preview and self.preview: diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 0b4f76c7..754ca870 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -63,14 +63,14 @@ class Console(Widget): self.histories[SEARCH_HISTORY] = History() self.histories[QUICKOPEN_HISTORY] = History() self.histories[OPEN_HISTORY] = History() - + def init(self): """override this. Called directly after class change""" def draw(self): if self.mode is None: return - + self.win.erase() self.addstr(0, 0, self.prompt) self.addstr(self.line) @@ -112,11 +112,11 @@ class Console(Widget): self.visible = False if hasattr(self, 'on_close'): self.on_close() - + def clear(self): self.pos = 0 self.line = '' - + def press(self, key): from curses.ascii import ctrl, ESC @@ -163,7 +163,7 @@ class Console(Widget): if self.line != current: self.line = self.history.current() self.pos = len(self.line) - + def add_to_history(self): self.history.fast_forward() self.history.modify(self.line) @@ -206,7 +206,7 @@ class Console(Widget): self.line = '' self.pos = 0 self.on_line_change() - + def delete(self, mod): self.tab_deque = None if mod == -1 and len(self.line) == 0: @@ -249,7 +249,7 @@ class ConsoleWithTab(Console): self.line = self.tab_deque[0] self.pos = len(self.line) self.on_line_change() - + def _get_tab(self): """ Override this function in the subclass! @@ -303,7 +303,7 @@ class CommandConsole(ConsoleWithTab): except ValueError as e: self.fm.notify(e) return None - + def _get_tab(self): if ' ' in self.line: cmd = self._get_cmd() @@ -376,7 +376,7 @@ class OpenConsole(ConsoleWithTab): def init(self): self.history = self.histories[OPEN_HISTORY] - + def execute(self): command, flags = self._parse() if command: @@ -411,7 +411,7 @@ class OpenConsole(ConsoleWithTab): for fl in self.fm.env.get_selection()) return _CustomTemplate(command).safe_substitute(dct) - + def _parse(self): if '!' in self.line: flags, cmd = self.line.split('!', 1) diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index 29e96cc3..32ef04af 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -49,20 +49,20 @@ class Pager(Widget): keyfnc = self.settings.keys.initialize_pager_commands keyfnc(self.commandlist) - + def open(self): self.scroll_begin = 0 self.markup = None self.startx = 0 self.need_redraw = True - + def close(self): if self.source and self.source_is_stream: self.source.close() - + def finalize(self): self.fm.ui.win.move(self.y, self.x) - + def draw(self): if self.old_source != self.source: self.old_source = self.source @@ -82,7 +82,7 @@ class Pager(Widget): for line, i in zip(line_gen, range(self.hei)): self._draw_line(i, line) self.need_redraw = False - + def _draw_line(self, i, line): if self.markup is None: self.addstr(i, 0, line) @@ -116,7 +116,7 @@ class Pager(Widget): if TITLE_REGEXP.match(line): self.color_at(i, 0, -1, 'title', *baseclr) - + def move(self, relative=0, absolute=None, pages=None, narg=None): i = self.scroll_begin if isinstance(absolute, int): @@ -146,7 +146,7 @@ class Pager(Widget): i = 0 self.scroll_begin = i - + def move_horizontal(self, relative=0, absolute=None, narg=None): if narg is not None: if absolute is None: @@ -168,7 +168,7 @@ class Pager(Widget): cmd = self.commandlist[tup] else: return - + except KeyError: self.env.key_clear() else: @@ -178,7 +178,7 @@ class Pager(Widget): except Exception as error: self.fm.notify(error) self.env.key_clear() - + def set_source(self, source, strip=False): if self.source and self.source_is_stream: self.source.close() @@ -225,7 +225,7 @@ class Pager(Widget): pass return self._get_line(n, attempt_to_read=False) return "" - + def _generate_lines(self, starty, startx): i = starty if not self.source: diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 2531206f..a2b8dbd6 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -46,10 +46,10 @@ class StatusBar(Widget): def __init__(self, win, column=None): Widget.__init__(self, win) self.column = column - + def notify(self, text, duration=4, bad=False): self.msg = Message(text, duration, bad) - + def draw(self): """Draw the statusbar""" @@ -97,7 +97,7 @@ class StatusBar(Widget): self._calc_bar() self._print_result(self.result) - + def _calc_bar(self): bar = Bar('in_statusbar') self._get_left_part(bar) @@ -105,7 +105,7 @@ class StatusBar(Widget): bar.shrink_by_removing(self.wid) self.result = bar.combine() - + def _draw_message(self): self.win.erase() self.color('in_statusbar', 'message', @@ -130,12 +130,10 @@ class StatusBar(Widget): break space_left -= len(string) starting_point += len(string) -# if starting_point >= self.wid: -# break def _get_left_part(self, bar): left = bar.left - + if self.column is not None: target = self.column.target.pointed_obj else: @@ -165,7 +163,7 @@ class StatusBar(Widget): else: left.add(strftime(self.timeformat, localtime(target.stat.st_mtime)), 'mtime') - + def _get_owner(self, target): uid = target.stat.st_uid @@ -243,6 +241,6 @@ class Message(object): self.text = text self.bad = bad self.elapse = time() + duration - + def is_alive(self): return time() <= self.elapse diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py index 2be61671..acfcea6e 100644 --- a/ranger/gui/widgets/taskview.py +++ b/ranger/gui/widgets/taskview.py @@ -25,7 +25,7 @@ from ranger.container import CommandList class TaskView(Widget, Accumulator): old_lst = None - + def __init__(self, win): Widget.__init__(self, win) Accumulator.__init__(self) @@ -77,7 +77,7 @@ class TaskView(Widget, Accumulator): self.color_at(1, 0, self.wid, base_clr, 'error') self.color_reset() - + def finalize(self): y = self.y + 1 + self.pointer - self.scroll_begin self.fm.ui.win.move(y, self.x) @@ -88,7 +88,7 @@ class TaskView(Widget, Accumulator): i = self.pointer self.fm.loader.remove(index=i) - + def task_move(self, absolute, i=None): if i is None: i = self.pointer @@ -102,7 +102,7 @@ class TaskView(Widget, Accumulator): cmd = self.commandlist[tup] else: return - + except KeyError: self.env.key_clear() else: @@ -112,6 +112,6 @@ class TaskView(Widget, Accumulator): except Exception as error: self.fm.notify(error) self.env.key_clear() - + def get_list(self): return self.fm.loader.queue diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index 6d5c9839..43729947 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -51,7 +51,7 @@ class TitleBar(Widget): except ValueError: bar.shrink_by_removing(self.wid) self.result = bar.combine() - + def _get_left_part(self, bar): import socket, os @@ -60,7 +60,7 @@ class TitleBar(Widget): clr = 'bad' else: clr = 'good' - + bar.add(username, 'hostname', clr, fixedsize=True) bar.add('@', 'hostname', clr, fixedsize=True) bar.add(socket.gethostname(), 'hostname', clr, fixedsize=True) diff --git a/ranger/keyapi.py b/ranger/keyapi.py index 95443b6d..308fab2b 100644 --- a/ranger/keyapi.py +++ b/ranger/keyapi.py @@ -36,7 +36,7 @@ def make_abbreviations(command_list): # is equivalent to: # bind('a', lambda arg: arg.fm.ui.do_stuff()) return lambda fnc: command_list.bind(fnc, *args) - + def hint(*args): command_list.hint(args[-1], *args[:-1]) diff --git a/ranger/runner.py b/ranger/runner.py index 5d450a5b..c61c11a5 100644 --- a/ranger/runner.py +++ b/ranger/runner.py @@ -61,7 +61,7 @@ class Context(object): def __init__(self, **keywords): self.__dict__ = keywords - + @property def filepaths(self): try: @@ -87,7 +87,7 @@ class Runner(object): self.ui = ui self.logfunc = logfunc self.apps = apps - + def _log(self, text): try: self.logfunc(text) @@ -103,7 +103,7 @@ class Runner(object): else: try: self.ui.suspend() except: self._log("Failed to suspend UI") - + def __call__(self, action=None, try_app_first=False, app='default', files=None, mode=0, flags='', wait=True, **popen_kws): @@ -168,7 +168,7 @@ class Runner(object): if 'd' in context.flags: toggle_ui = False context.wait = False - + # Finally, run it if toggle_ui: |