From a9bd6171c682f5c2235f435d539998770aeaddaf Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 10 Feb 2013 21:22:46 +0100 Subject: ext.img_display: disable preview_images when unsupported --- ranger/ext/img_display.py | 5 ++++- ranger/gui/widgets/pager.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index a89f6d8b..307c7b75 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -15,6 +15,9 @@ from subprocess import Popen, PIPE W3MIMGDISPLAY_PATH = '/usr/lib/w3m/w3mimgdisplay' W3MIMGDISPLAY_OPTIONS = [] +class ImgDisplayUnsupportedException(Exception): + pass + def _get_font_dimensions(): """ Get the height and width of a character displayed in the terminal in @@ -49,7 +52,7 @@ def draw(path, start_x, start_y, max_width, max_height): """ fontw, fonth = _get_font_dimensions() if fontw == 0 or fonth == 0: - return + raise ImgDisplayUnsupportedException() max_width_pixels = max_width * fontw max_height_pixels = max_height * fonth diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index e9ce8b5c..4e8161a5 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -84,6 +84,8 @@ class Pager(Widget): self.need_redraw_image = False try: img_display.draw(self.image, self.x, self.y, self.wid, self.hei) + except img_display.ImgDisplayUnsupportedException: + self.fm.settings.preview_images = False except Exception as e: self.fm.notify(e, bad=True) -- cgit 1.4.1-2-gfad0