summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorGermainZ <germanosz@gmail.com>2015-09-14 19:31:02 +0300
committerGermainZ <germanosz@gmail.com>2015-09-14 19:38:26 +0300
commit40bd7bc111775ae10ea547bc4d281830eb95757a (patch)
tree4a58f45288ca1c285805961543e97c45afb14803 /ranger
parent2344714fcbaa3697f77dd0cb4477a8f8019c7dc4 (diff)
downloadranger-40bd7bc111775ae10ea547bc4d281830eb95757a.tar.gz
Use scope.sh for all the previews
… instead of calling w3mimgdisplay for (potentially non-supported, e.g.
SVG files) images, which also has the side effect of making custom
previews for images impossible.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/container/file.py2
-rw-r--r--ranger/core/actions.py30
-rwxr-xr-xranger/data/scope.sh30
-rw-r--r--ranger/gui/widgets/browsercolumn.py18
-rw-r--r--ranger/gui/widgets/browserview.py7
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 ce9ee574..97844073 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)
0700 committer Kartik Agaram <vc@akkartik.com> 2018-07-08 22:33:15 -0700 4327' href='/akkartik/mu/commit/subx/010core.cc?h=main&id=665a4d70406a201bb8481fde0c9fbbead3477f00'>665a4d70 ^
b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^


b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^

b0832f66 ^
665a4d70 ^
f8831a02 ^


f8831a02 ^
f8831a02 ^


95e5511a ^
c1100182 ^
2af68cc8 ^
a893d3b6 ^


f8831a02 ^


e307a807 ^
f8831a02 ^
a7b2a5de ^
6602c82f ^
f8831a02 ^




e307a807 ^
f8831a02 ^

e307a807 ^
f8831a02 ^
a7b2a5de ^
6602c82f ^
f8831a02 ^



a7b2a5de ^
6602c82f ^
f8831a02 ^


f8831a02 ^
a7b2a5de ^
6602c82f ^
f8831a02 ^



2af68cc8 ^
665a4d70 ^
f8831a02 ^

f8831a02 ^



a7b2a5de ^

edd2253b ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175