diff options
author | hut <hut@lepus.uberspace.de> | 2015-09-19 21:26:13 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-09-19 21:26:13 +0200 |
commit | 5ea0f609b93a3954e4e26b8387f7adab8fddc94b (patch) | |
tree | 79374d887d27809641e3c242415aaa2869ab440e /ranger | |
parent | 3fbb0f737b632bf2c116091eb73362d37583f746 (diff) | |
parent | 40bd7bc111775ae10ea547bc4d281830eb95757a (diff) | |
download | ranger-5ea0f609b93a3954e4e26b8387f7adab8fddc94b.tar.gz |
Merge branch 'universal_scope_sh' of https://github.com/GermainZ/ranger
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/file.py | 2 | ||||
-rw-r--r-- | ranger/core/actions.py | 30 | ||||
-rwxr-xr-x | ranger/data/scope.sh | 30 | ||||
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 18 | ||||
-rw-r--r-- | ranger/gui/widgets/browserview.py | 7 |
5 files changed, 50 insertions, 37 deletions
diff --git a/ranger/container/file.py b/ranger/container/file.py index 6be60f85..a3db63a5 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -76,8 +76,6 @@ class File(FileSystemObject): if self.fm.settings.preview_script and \ self.fm.settings.use_preview_script: return True - if self.image and self.fm.settings.preview_images: - return True if self.container: return False if PREVIEW_WHITELIST.search(self.basename): diff --git a/ranger/core/actions.py b/ranger/core/actions.py index e3dba313..8167dbcf 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -799,14 +799,11 @@ class Actions(FileManagerAware, SettingsAware): return pager = self.ui.open_pager() - if self.settings.preview_images and self.thisfile.image: - pager.set_image(self.thisfile.realpath) + f = self.thisfile.get_preview_source(pager.wid, pager.hei) + if self.thisfile.is_image_preview(): + pager.set_image(f) else: - f = self.thisfile.get_preview_source(pager.wid, pager.hei) - if self.thisfile.is_image_preview(): - pager.set_image(f) - else: - pager.set_source(f) + pager.set_source(f) # -------------------------- # -- Previews @@ -835,10 +832,6 @@ class Actions(FileManagerAware, SettingsAware): if not path or not os.path.exists(path): return None - if self.settings.preview_images and file.image: - pager.set_image(path) - return None - if self.settings.preview_script and self.settings.use_preview_script: # self.previews is a 2 dimensional dict: # self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..." @@ -874,6 +867,13 @@ class Actions(FileManagerAware, SettingsAware): data['loading'] = True + if 'directimagepreview' in data: + data['foundpreview'] = True + data['imagepreview'] = True + pager.set_image(path) + data['loading'] = False + return path + cacheimg = os.path.join(ranger.CACHEDIR, self.sha1_encode(path)) if (os.path.isfile(cacheimg) and os.path.getmtime(cacheimg) > os.path.getmtime(path)): data['foundpreview'] = True @@ -883,7 +883,8 @@ class Actions(FileManagerAware, SettingsAware): return cacheimg loadable = CommandLoader(args=[self.settings.preview_script, - path, str(width), str(height), cacheimg], read=True, + path, str(width), str(height), cacheimg, + str(self.settings.preview_images)], read=True, silent=True, descr="Getting preview of %s" % path) def on_after(signal): exit = signal.process.poll() @@ -899,6 +900,8 @@ class Actions(FileManagerAware, SettingsAware): data[(-1, -1)] = content elif exit == 6: data['imagepreview'] = True + elif exit == 7: + data['directimagepreview'] = True elif exit == 1: data[(-1, -1)] = None data['foundpreview'] = False @@ -922,6 +925,9 @@ class Actions(FileManagerAware, SettingsAware): if 'imagepreview' in data: pager.set_image(cacheimg) return cacheimg + elif 'directimagepreview' in data: + pager.set_image(path) + return path else: pager.set_source(self.thisfile.get_preview_source( pager.wid, pager.hei)) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 3611c961..19404019 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -17,12 +17,14 @@ # 4 | fix height | success. Don't reload when height changes # 5 | fix both | success. Don't ever reload # 6 | image | success. display the image $cached points to as an image preview +# 7 | image | success. display the file directly as an image # Meaningful aliases for arguments: -path="$1" # Full path of the selected file -width="$2" # Width of the preview pane (number of fitting characters) -height="$3" # Height of the preview pane (number of fitting characters) -cached="$4" # Path that should be used to cache image previews +path="$1" # Full path of the selected file +width="$2" # Width of the preview pane (number of fitting characters) +height="$3" # Height of the preview pane (number of fitting characters) +cached="$4" # Path that should be used to cache image previews +preview_images="$5" # "True" if image previews are enabled, "False" otherwise. maxln=200 # Stop after $maxln lines. Can be used like ls | head -n $maxln @@ -44,6 +46,23 @@ trim() { head -n "$maxln"; } # wraps highlight to treat exit code 141 (killed by SIGPIPE) as success highlight() { command highlight "$@"; test $? = 0 -o $? = 141; } +# Image previews, if enabled in ranger. +if [ "$preview_images" = "True" ]; then + case "$mimetype" in + # Image previews for SVG files, disabled by default. + ###image/svg+xml) + ### convert "$path" "$cached" && exit 6 || exit 1;; + # Image previews for image files. w3mimgdisplay will be called for all + # image files (unless overriden as above), but might fail for + # unsupported types. + image/*) + exit 7;; + # Image preview for video, disabled by default.: + ###video/*) + ### ffmpegthumbnailer -i "$path" -o "$cached" -s 0 && exit 6 || exit 1;; + esac +fi + case "$extension" in # Archive extensions: 7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ @@ -76,9 +95,6 @@ case "$mimetype" in # Ascii-previews of images: image/*) img2txt --gamma=0.6 --width="$width" "$path" && exit 4 || exit 1;; - # Image preview for videos, disabled by default: - # video/*) - # ffmpegthumbnailer -i "$path" -o "$cached" -s 0 && exit 6 || exit 1;; # Display information about media files: video/* | audio/*) exiftool "$path" && exit 5 diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 5d055a0b..b38d0b5b 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -180,19 +180,15 @@ class BrowserColumn(Pager): Pager.close(self) return - if self.fm.settings.preview_images and self.target.image: - self.set_image(self.target.realpath) - Pager.draw(self) + f = self.target.get_preview_source(self.wid, self.hei) + if f is None: + Pager.close(self) else: - f = self.target.get_preview_source(self.wid, self.hei) - if f is None: - Pager.close(self) + if self.target.is_image_preview(): + self.set_image(f) else: - if self.target.is_image_preview(): - self.set_image(f) - else: - self.set_source(f) - Pager.draw(self) + self.set_source(f) + Pager.draw(self) def _draw_directory(self): """Draw the contents of a directory""" diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py index eb99369b..e9640208 100644 --- a/ranger/gui/widgets/browserview.py +++ b/ranger/gui/widgets/browserview.py @@ -258,9 +258,7 @@ class BrowserView(Widget, DisplayableContainer): result = not self.columns[-1].has_preview() target = self.columns[-1].target if not result and target and target.is_file: - if target.image and self.fm.settings.preview_images: - result = False # don't collapse when drawing images - elif self.fm.settings.preview_script and \ + if self.fm.settings.preview_script and \ self.fm.settings.use_preview_script: try: result = not self.fm.previews[target.realpath]['foundpreview'] @@ -355,8 +353,7 @@ class BrowserView(Widget, DisplayableContainer): self.columns[-1].visible = True if self.preview and self.is_collapsed != self._collapse(): - if (self.fm.settings.preview_images and - self.fm.settings.preview_files): + if self.fm.settings.preview_files: # force clearing the image when resizing preview column self.columns[-1].clear_image(force=True) self.resize(self.y, self.x, self.hei, self.wid) |