about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/commands.py2
-rwxr-xr-xranger/config/commands.py8
-rw-r--r--ranger/config/commands_sample.py2
-rw-r--r--ranger/container/directory.py8
-rw-r--r--ranger/container/fsobject.py4
-rw-r--r--ranger/container/settings.py4
-rw-r--r--ranger/core/actions.py14
-rw-r--r--ranger/core/loader.py12
-rw-r--r--ranger/core/main.py14
-rw-r--r--ranger/core/runner.py4
-rw-r--r--ranger/core/tab.py2
-rw-r--r--ranger/ext/img_display.py18
-rw-r--r--ranger/ext/keybinding_parser.py2
-rw-r--r--ranger/ext/shell_escape.py2
-rw-r--r--ranger/gui/ansi.py2
-rw-r--r--ranger/gui/context.py4
-rw-r--r--ranger/gui/ui.py14
-rw-r--r--ranger/gui/widgets/console.py2
18 files changed, 62 insertions, 56 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index 1d6a2cdf..7021ed7c 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -142,7 +142,7 @@ class Command(FileManagerAware):
 
     def start(self, n):
         """Returns everything until (inclusively) arg(n)"""
-        return ' '.join(self.args[:n]) + " " # XXX
+        return ' '.join(self.args[:n]) + " "  # XXX
 
     def shift(self):
         del self.args[0]
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 1c0f065f..1bb688cb 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -243,10 +243,10 @@ class open_with(Command):
     def execute(self):
         app, flags, mode = self._get_app_flags_mode(self.rest(1))
         self.fm.execute_file(
-                files = [f for f in self.fm.thistab.get_selection()],
-                app = app,
-                flags = flags,
-                mode = mode)
+                files=[f for f in self.fm.thistab.get_selection()],
+                app=app,
+                flags=flags,
+                mode=mode)
 
     def tab(self, tabnum):
         return self._tab_through_executables()
diff --git a/ranger/config/commands_sample.py b/ranger/config/commands_sample.py
index ea74b7d6..1386e84e 100644
--- a/ranger/config/commands_sample.py
+++ b/ranger/config/commands_sample.py
@@ -8,7 +8,7 @@
 from ranger.api.commands import *
 
 # A simple command for demonstration purposes follows.
-#------------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
 
 # You can import any python module as needed.
 import os
diff --git a/ranger/container/directory.py b/ranger/container/directory.py
index 5f1b2910..923821a0 100644
--- a/ranger/container/directory.py
+++ b/ranger/container/directory.py
@@ -174,7 +174,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
     def mark_item(self, item, val):
         item._mark(val)
         if val:
-            if item in self.files and not item in self.marked_items:
+            if item in self.files and item not in self.marked_items:
                 self.marked_items.append(item)
         else:
             while True:
@@ -224,7 +224,7 @@ class Directory(FileSystemObject, Accumulator, Loadable):
 
     def refilter(self):
         if self.files_all is None:
-            return # propably not loaded yet
+            return  # propably not loaded yet
 
         self.last_update_time = time()
 
@@ -460,13 +460,13 @@ class Directory(FileSystemObject, Accumulator, Loadable):
             elif sort_func in (sort_by_basename, sort_by_basename_icase):
                 sort_func = sort_unicode_wrapper_string(sort_func)
 
-        self.files_all.sort(key = sort_func)
+        self.files_all.sort(key=sort_func)
 
         if self.settings.sort_reverse:
             self.files_all.reverse()
 
         if self.settings.sort_directories_first:
-            self.files_all.sort(key = sort_by_directory)
+            self.files_all.sort(key=sort_by_directory)
 
         self.refilter()
 
diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py
index fa8e4484..b6c0c9ec 100644
--- a/ranger/container/fsobject.py
+++ b/ranger/container/fsobject.py
@@ -91,7 +91,7 @@ class FileSystemObject(FileManagerAware, SettingsAware):
             path = abspath(path)
         self.path = path
         self.basename = basename(path)
-        if basename_is_rel_to == None:
+        if basename_is_rel_to is None:
             self.relative_path = self.basename
         else:
             self.relative_path = relpath(path, basename_is_rel_to)
@@ -175,7 +175,7 @@ class FileSystemObject(FileManagerAware, SettingsAware):
         """Used in garbage-collecting.  Override in Directory"""
 
     def look_up_cumulative_size(self):
-        pass # normal files have no cumulative size
+        pass  # normal files have no cumulative size
 
     def set_mimetype(self):
         """assign attributes such as self.video according to the mimetype"""
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 725bbfc3..18a16b98 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -219,7 +219,7 @@ class Settings(SignalDispatcher, FileManagerAware):
 
     def _raw_set(self, name, value, path=None, tags=None):
         if path:
-            if not path in self._localsettings:
+            if path not in self._localsettings:
                 try:
                     regex = re.compile(path)
                 except:
@@ -231,7 +231,7 @@ class Settings(SignalDispatcher, FileManagerAware):
 
             # make sure name is in _settings, so __iter__ runs through
             # local settings too.
-            if not name in self._settings:
+            if name not in self._settings:
                 type_ = self.types_of(name)[0]
                 value = DEFAULT_VALUES[type_]
                 self._settings[name] = value
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index f722ffc9..2c8371a0 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -121,7 +121,7 @@ class Actions(FileManagerAware, SettingsAware):
         """
         if self.mode == 'normal':
             self._visual_reverse = reverse
-            if narg != None:
+            if narg is not None:
                 self.mark_files(val=not reverse, narg=narg)
             self.change_mode('visual')
         else:
@@ -149,7 +149,7 @@ class Actions(FileManagerAware, SettingsAware):
             if ranger.arg.debug:
                 raise
             bad = True
-        elif bad == True and ranger.arg.debug:
+        elif bad is True and ranger.arg.debug:
             raise Exception(str(text))
         text = str(text)
         self.log.appendleft(text)
@@ -515,7 +515,7 @@ class Actions(FileManagerAware, SettingsAware):
         # csh variable is lowercase
         cdpath = os.environ.get('CDPATH', None) or os.environ.get('cdpath', None)
         result = self.thistab.enter_dir(path, history=history)
-        if result == False and cdpath:
+        if result is False and cdpath:
             for p in cdpath.split(':'):
                 curpath = os.path.join(p, path)
                 if os.path.isdir(curpath):
@@ -645,7 +645,7 @@ class Actions(FileManagerAware, SettingsAware):
         if val is None and toggle is False:
             return
 
-        if narg == None:
+        if narg is None:
             narg = 1
         else:
             all = False
@@ -932,7 +932,7 @@ class Actions(FileManagerAware, SettingsAware):
 
             found = data.get((-1, -1), data.get((width, -1),
                 data.get((-1, height), data.get((width, height), False))))
-            if found == False:
+            if found is False:
                 try:
                     stat_ = os.stat(self.settings.preview_script)
                 except:
@@ -1082,7 +1082,7 @@ class Actions(FileManagerAware, SettingsAware):
         if self.restorable_tabs:
             tab = self.restorable_tabs.pop()
             for name in range(1, len(self.tabs) + 2):
-                if not name in self.tabs:
+                if name not in self.tabs:
                     self.current_tab = name
                     self.tabs[name] = tab
                     tab.enter_dir(tab.path, history=False)
@@ -1106,7 +1106,7 @@ class Actions(FileManagerAware, SettingsAware):
         if narg:
             return self.tab_open(narg, path)
         for i in range(1, 10):
-            if not i in self.tabs:
+            if i not in self.tabs:
                 return self.tab_open(i, path)
 
     def tab_switch(self, path, create_directory=False):
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index a8744001..bae0e54d 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -211,10 +211,10 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
                 except select.error:
                     sleep(0.03)
             if not self.silent:
-                for l in process.stderr.readlines():
+                for line in process.stderr:
                     if py3:
-                        l = safeDecode(l)
-                    self.fm.notify(l, bad=True)
+                        line = safeDecode(line)
+                    self.fm.notify(line, bad=True)
             if self.read:
                 read = process.stdout.read()
                 if py3:
@@ -271,6 +271,9 @@ def safeDecode(string):
 
 
 class Loader(FileManagerAware):
+    """
+    The Manager of 'Loadable' objects, referenced as fm.loader
+    """
     seconds_of_work_time = 0.03
     throbber_chars = r'/-\|'
     throbber_paused = '#'
@@ -305,6 +308,7 @@ class Loader(FileManagerAware):
             self.queue.append(obj)
         else:
             self.queue.appendleft(obj)
+        self.fm.signal_emit("loader.before", loadable=obj, fm=self.fm)
         if self.paused:
             obj.pause()
         else:
@@ -341,6 +345,7 @@ class Loader(FileManagerAware):
                 item = self.queue[index]
             if hasattr(item, 'unload'):
                 item.unload()
+            self.fm.signal_emit("loader.destroy", loadable=item, fm=self.fm)
             item.destroy()
             del self.queue[index]
             if item.progressbar_supported:
@@ -408,6 +413,7 @@ class Loader(FileManagerAware):
     def _remove_current_process(self, item):
         item.load_generator = None
         self.queue.remove(item)
+        self.fm.signal_emit("loader.after", loadable=item, fm=self.fm)
         if item.progressbar_supported:
             self.fm.ui.status.request_redraw()
 
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 8ad9acb0..77e06861 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -29,14 +29,14 @@ def main():
     else:
         os.environ[level] = '1'
 
-    if not 'SHELL' in os.environ:
+    if 'SHELL' not in os.environ:
         os.environ['SHELL'] = 'sh'
 
     ranger.arg = arg = parse_arguments()
     if arg.copy_config is not None:
         fm = FM()
         fm.copy_config_files(arg.copy_config)
-        return 1 if arg.fail_unless_cd else 0 # COMPAT
+        return 1 if arg.fail_unless_cd else 0  # COMPAT
     if arg.list_tagged_files:
         fm = FM()
         try:
@@ -53,7 +53,7 @@ def main():
                         sys.stdout.write(line[2:])
                 elif len(line) > 0 and '*' in arg.list_tagged_files:
                     sys.stdout.write(line)
-        return 1 if arg.fail_unless_cd else 0 # COMPAT
+        return 1 if arg.fail_unless_cd else 0  # COMPAT
 
     SettingsAware._setup(Settings())
 
@@ -85,7 +85,7 @@ def main():
             rifle = Rifle(rifleconf)
             rifle.reload_config()
             rifle.execute(targets, number=ranger.arg.mode, flags=ranger.arg.flags)
-            return 1 if arg.fail_unless_cd else 0 # COMPAT
+            return 1 if arg.fail_unless_cd else 0  # COMPAT
 
     crash_traceback = None
     try:
@@ -104,7 +104,7 @@ def main():
             for key in range(33, 127):
                 if key not in maps:
                     print(chr(key))
-            return 1 if arg.fail_unless_cd else 0 # COMPAT
+            return 1 if arg.fail_unless_cd else 0  # COMPAT
 
         if not sys.stdin.isatty():
             sys.stderr.write("Error: Must run ranger from terminal\n")
@@ -241,7 +241,7 @@ def parse_arguments():
     arg.confdir = expanduser(arg.confdir)
     arg.cachedir = expanduser(default_cachedir)
 
-    if arg.fail_unless_cd: # COMPAT
+    if arg.fail_unless_cd:  # COMPAT
         sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n"
             "It was used to faciliate using ranger as a file launcher.\n"
             "Now, please use the standalone file launcher 'rifle' instead.\n")
@@ -354,7 +354,7 @@ def allow_access_to_confdir(confdir, allow):
                 print("To run ranger without the need for configuration")
                 print("files, use the --clean option.")
                 raise SystemExit()
-        if not confdir in sys.path:
+        if confdir not in sys.path:
             sys.path[0:0] = [confdir]
     else:
         if sys.path[0] == confdir:
diff --git a/ranger/core/runner.py b/ranger/core/runner.py
index 0ae227a6..62da3ff7 100644
--- a/ranger/core/runner.py
+++ b/ranger/core/runner.py
@@ -146,7 +146,7 @@ class Runner(object):
         # Set default shell for Popen
         if popen_kws['shell']:
             # This doesn't work with fish, see #300
-            if not 'fish' in os.environ['SHELL']:
+            if 'fish' not in os.environ['SHELL']:
                 popen_kws['executable'] = os.environ['SHELL']
 
         if 'stdout' not in popen_kws:
@@ -174,7 +174,7 @@ class Runner(object):
             toggle_ui = False
             context.wait = False
         if 'w' in context.flags:
-            if not pipe_output and context.wait: # <-- sanity check
+            if not pipe_output and context.wait:  # <-- sanity check
                 wait_for_enter = True
         if 'r' in context.flags:
             # TODO: make 'r' flag work with pipes
diff --git a/ranger/core/tab.py b/ranger/core/tab.py
index dc76568b..2faf4b0c 100644
--- a/ranger/core/tab.py
+++ b/ranger/core/tab.py
@@ -103,7 +103,7 @@ class Tab(FileManagerAware, SettingsAware):
     def inherit_history(self, other_history):
         self.history.rebase(other_history)
 
-    def enter_dir(self, path, history = True):
+    def enter_dir(self, path, history=True):
         """Enter given path"""
         # TODO: Ensure that there is always a self.thisdir
         if path is None: return
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index 61967b02..1ee421d7 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -114,11 +114,11 @@ class W3MImageDisplayer(ImageDisplayer):
         fontw, fonth = self._get_font_dimensions()
 
         cmd = "6;{x};{y};{w};{h}\n4;\n3;\n".format(
-                x = int((start_x - 0.2) * fontw),
-                y = start_y * fonth,
+                x=int((start_x - 0.2) * fontw),
+                y=start_y * fonth,
                 # y = int((start_y + 1) * fonth), # (for tmux top status bar)
-                w = int((width + 0.4) * fontw),
-                h = height * fonth + 1)
+                w=int((width + 0.4) * fontw),
+                h=height * fonth + 1)
                 # h = (height - 1) * fonth + 1) # (for tmux top status bar)
 
         try:
@@ -168,12 +168,12 @@ class W3MImageDisplayer(ImageDisplayer):
             height = max_height_pixels
 
         return "0;1;{x};{y};{w};{h};;;;;{filename}\n4;\n3;\n".format(
-                x = int((start_x - 0.2) * fontw),
-                y = start_y * fonth,
+                x=int((start_x - 0.2) * fontw),
+                y=start_y * fonth,
                 # y = (start_y + 1) * fonth, # (for tmux top status bar)
-                w = width,
-                h = height,
-                filename = path)
+                w=width,
+                h=height,
+                filename=path)
 
     def quit(self):
         if self.is_initialized and self.process and self.process.poll() is None:
diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py
index 4e9375bf..84a4a068 100644
--- a/ranger/ext/keybinding_parser.py
+++ b/ranger/ext/keybinding_parser.py
@@ -235,7 +235,7 @@ class KeyBuffer(object):
         if not self.finished_parsing_quantifier and key in digits:
             if self.quantifier is None:
                 self.quantifier = 0
-            self.quantifier = self.quantifier * 10 + key - 48 # (48 = ord(0))
+            self.quantifier = self.quantifier * 10 + key - 48  # (48 = ord(0))
         else:
             self.finished_parsing_quantifier = True
 
diff --git a/ranger/ext/shell_escape.py b/ranger/ext/shell_escape.py
index cf9aa867..fe542084 100644
--- a/ranger/ext/shell_escape.py
+++ b/ranger/ext/shell_escape.py
@@ -20,7 +20,7 @@ def shell_escape(arg):
     arg = str(arg)
     if UNESCAPABLE & set(arg):
         return shell_quote(arg)
-    arg = arg.replace('\\', '\\\\') # make sure this comes at the start
+    arg = arg.replace('\\', '\\\\')  # make sure this comes at the start
     for k, v in META_DICT.items():
         arg = arg.replace(k, v)
     return arg
diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py
index 57a69442..ffa9425c 100644
--- a/ranger/gui/ansi.py
+++ b/ranger/gui/ansi.py
@@ -149,7 +149,7 @@ def char_slice(ansi_text, start, length):
         old_pos = pos
         pos += len(chunk)
         if pos <= start:
-            pass # seek
+            pass  # seek
         elif old_pos < start and pos >= start:
             chunks.append(last_color)
             chunks.append(chunk[start-old_pos:start-old_pos+length])
diff --git a/ranger/gui/context.py b/ranger/gui/context.py
index d5352a0a..e577d2be 100644
--- a/ranger/gui/context.py
+++ b/ranger/gui/context.py
@@ -13,8 +13,8 @@ CONTEXT_KEYS = ['reset', 'error', 'badinfo',
         'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
         'scroll', 'all', 'bot', 'top', 'percentage', 'filter',
         'flat', 'marked', 'tagged', 'tag_marker', 'cut', 'copied',
-        'help_markup', # COMPAT
-        'seperator', 'key', 'special', 'border', # COMPAT
+        'help_markup',  # COMPAT
+        'seperator', 'key', 'special', 'border',  # COMPAT
         'title', 'text', 'highlight', 'bars', 'quotes', 'tab', 'loaded',
         'keybuffer',
         'infostring',
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 200f3625..7e873f4c 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -27,12 +27,12 @@ def _setup_mouse(signal):
         curses.mousemask(MOUSEMASK)
         curses.mouseinterval(0)
 
-        ## this line solves this problem:
-        ## If a mouse click triggers an action that disables curses and
-        ## starts curses again, (e.g. running a ## file by clicking on its
-        ## preview) and the next key is another mouse click, the bstate of this
-        ## mouse event will be invalid.  (atm, invalid bstates are recognized
-        ## as scroll-down, so this avoids an errorneous scroll-down action)
+        # This line solves this problem:
+        # If a mouse click triggers an action that disables curses and
+        # starts curses again, (e.g. running a ## file by clicking on its
+        # preview) and the next key is another mouse click, the bstate of this
+        # mouse event will be invalid.  (atm, invalid bstates are recognized
+        # as scroll-down, so this avoids an errorneous scroll-down action)
         curses.ungetmouse(0, 0, 0, 0, 0)
     else:
         curses.mousemask(0)
@@ -93,7 +93,7 @@ class UI(DisplayableContainer):
             self.setup()
             self.win.addstr("loading...")
             self.win.refresh()
-            self._draw_title = curses.tigetflag('hs') # has_status_line
+            self._draw_title = curses.tigetflag('hs')  # has_status_line
 
         self.update_size()
         self.is_on = True
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 64474ac7..8bb37937 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -469,7 +469,7 @@ class Console(Widget):
                 self.pos = len(tab_result)
                 self.on_line_change()
 
-            elif tab_result == None:
+            elif tab_result is None:
                 pass
 
             elif hasattr(tab_result, '__iter__'):