summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/actions.py241
1 files changed, 123 insertions, 118 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 137e2c1f..2d5f2da0 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -940,136 +940,141 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         if not path or not os.path.exists(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..."
-            # self.previews['/tmp/foo.jpg']['loading'] = False
-            # A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
-            # The key 'foundpreview' is added later. Values in (True, False)
-            # XXX: Previews can break when collapse_preview is on and the
-            # preview column is popping out as you move the cursor on e.g. a
-            # PDF file.
+        if not self.settings.preview_script or not self.settings.use_preview_script:
             try:
-                data = self.previews[path]
-            except KeyError:
-                data = self.previews[path] = {'loading': False}
-            else:
-                if data['loading']:
-                    return None
-
-            found = data.get(
-                (-1, -1), data.get(
-                    (width, -1), data.get(
-                        (-1, height), data.get(
-                            (width, height), False
-                        )
+                return codecs.open(path, 'r', errors='ignore')
+            except OSError:
+                return None
+
+        # self.previews is a 2 dimensional dict:
+        # self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
+        # self.previews['/tmp/foo.jpg']['loading'] = False
+        # A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
+        # The key 'foundpreview' is added later. Values in (True, False)
+        # XXX: Previews can break when collapse_preview is on and the
+        # preview column is popping out as you move the cursor on e.g. a
+        # PDF file.
+        try:
+            data = self.previews[path]
+        except KeyError:
+            data = self.previews[path] = {'loading': False}
+        else:
+            if data['loading']:
+                return None
+
+        found = data.get(
+            (-1, -1), data.get(
+                (width, -1), data.get(
+                    (-1, height), data.get(
+                        (width, height), False
                     )
                 )
             )
-            if found is False:
-                try:
-                    stat_ = os.stat(self.settings.preview_script)
-                except OSError:
-                    self.fm.notify(
-                        "Preview Script `%s' doesn't exist!" % self.settings.preview_script,
-                        bad=True,
-                    )
-                    return None
+        )
+        if found is not False:
+            return found
 
-                if not stat_.st_mode & S_IEXEC:
-                    self.fm.notify(
-                        "Preview Script `%s' is not executable!" % self.settings.preview_script,
-                        bad=True,
-                    )
-                    return None
+        try:
+            stat_ = os.stat(self.settings.preview_script)
+        except OSError:
+            self.fm.notify(
+                "Preview Script `%s' doesn't exist!" % self.settings.preview_script,
+                bad=True,
+            )
+            return None
 
-                data['loading'] = True
+        if not stat_.st_mode & S_IEXEC:
+            self.fm.notify(
+                "Preview Script `%s' is not executable!" % self.settings.preview_script,
+                bad=True,
+            )
+            return None
 
-                if 'directimagepreview' in data:
-                    data['foundpreview'] = True
-                    data['imagepreview'] = True
-                    pager.set_image(path)
-                    data['loading'] = False
-                    return path
+        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.args.cachedir, self.sha1_encode(path))
+        if os.path.isfile(cacheimg) and \
+                os.path.getmtime(cacheimg) > os.path.getmtime(path):
+            data['foundpreview'] = True
+            data['imagepreview'] = True
+            pager.set_image(cacheimg)
+            data['loading'] = False
+            return cacheimg
+
+        def on_after(signal):
+            rcode = signal.process.poll()
+            content = signal.loader.stdout_buffer
+            data['foundpreview'] = True
+
+            if rcode == 0:
+                data[(width, height)] = content
+            elif rcode == 3:
+                data[(-1, height)] = content
+            elif rcode == 4:
+                data[(width, -1)] = content
+            elif rcode == 5:
+                data[(-1, -1)] = content
+            elif rcode == 6:
+                data['imagepreview'] = True
+            elif rcode == 7:
+                data['directimagepreview'] = True
+            elif rcode == 1:
+                data[(-1, -1)] = None
+                data['foundpreview'] = False
+            elif rcode == 2:
+                fobj = codecs.open(path, 'r', errors='ignore')
+                try:
+                    data[(-1, -1)] = fobj.read(1024 * 32)
+                except UnicodeDecodeError:
+                    fobj.close()
+                    fobj = codecs.open(path, 'r', encoding='latin-1', errors='ignore')
+                    data[(-1, -1)] = fobj.read(1024 * 32)
+                fobj.close()
+            else:
+                data[(-1, -1)] = None
 
-                cacheimg = os.path.join(ranger.args.cachedir, self.sha1_encode(path))
-                if os.path.isfile(cacheimg) and \
-                        os.path.getmtime(cacheimg) > os.path.getmtime(path):
-                    data['foundpreview'] = True
-                    data['imagepreview'] = True
+            if self.thisfile and self.thisfile.realpath == path:
+                self.ui.browser.need_redraw = True
+
+            data['loading'] = False
+
+            pager = self.ui.get_pager()
+            if self.thisfile and self.thisfile.is_file:
+                if 'imagepreview' in data:
                     pager.set_image(cacheimg)
-                    data['loading'] = False
                     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))
 
-                loadable = CommandLoader(
-                    args=[self.settings.preview_script, 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):
-                    rcode = signal.process.poll()
-                    content = signal.loader.stdout_buffer
-                    data['foundpreview'] = True
-                    if rcode == 0:
-                        data[(width, height)] = content
-                    elif rcode == 3:
-                        data[(-1, height)] = content
-                    elif rcode == 4:
-                        data[(width, -1)] = content
-                    elif rcode == 5:
-                        data[(-1, -1)] = content
-                    elif rcode == 6:
-                        data['imagepreview'] = True
-                    elif rcode == 7:
-                        data['directimagepreview'] = True
-                    elif rcode == 1:
-                        data[(-1, -1)] = None
-                        data['foundpreview'] = False
-                    elif rcode == 2:
-                        fobj = codecs.open(path, 'r', errors='ignore')
-                        try:
-                            data[(-1, -1)] = fobj.read(1024 * 32)
-                        except UnicodeDecodeError:
-                            fobj.close()
-                            fobj = codecs.open(path, 'r', encoding='latin-1', errors='ignore')
-                            data[(-1, -1)] = fobj.read(1024 * 32)
-                        fobj.close()
-                    else:
-                        data[(-1, -1)] = None
-                    if self.thisfile and self.thisfile.realpath == path:
-                        self.ui.browser.need_redraw = True
-                    data['loading'] = False
-                    pager = self.ui.get_pager()
-                    if self.thisfile and self.thisfile.is_file:
-                        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))
-
-                def on_destroy(signal):  # pylint: disable=unused-argument
-                    try:
-                        del self.previews[path]
-                    except KeyError:
-                        pass
-                loadable.signal_bind('after', on_after)
-                loadable.signal_bind('destroy', on_destroy)
-                self.loader.add(loadable)
-                return None
-            else:
-                return found
-        else:
+        def on_destroy(signal):  # pylint: disable=unused-argument
             try:
-                return codecs.open(path, 'r', errors='ignore')
-            except OSError:
-                return None
+                del self.previews[path]
+            except KeyError:
+                pass
+
+        loadable = CommandLoader(
+            args=[self.settings.preview_script, path, str(width), str(height),
+                  cacheimg, str(self.settings.preview_images)],
+            read=True,
+            silent=True,
+            descr="Getting preview of %s" % path,
+        )
+        loadable.signal_bind('after', on_after)
+        loadable.signal_bind('destroy', on_destroy)
+        self.loader.add(loadable)
+
+        return None
 
     # --------------------------
     # -- Tabs
href='#n561'>561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674

































































































































































































































































































































































































































































































































































































































































































                                                                              
d=0654d6d093f8e78033b9dcafcb52bbdcd92aed0c'>^





f07bb12f ^
34a60763 ^

f07bb12f ^
34a60763 ^





f07bb12f ^






34a60763 ^

f07bb12f ^
34a60763 ^

f07bb12f ^












34a60763 ^
f07bb12f ^


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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202