summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/fm.py1
-rw-r--r--ranger/gui/displayable.py17
-rw-r--r--ranger/gui/widgets/filelist.py23
-rw-r--r--ranger/gui/widgets/filelistcontainer.py24
4 files changed, 56 insertions, 9 deletions
diff --git a/ranger/fm.py b/ranger/fm.py
index b661efcc..271e4138 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -52,6 +52,7 @@ class FM(Actions):
 			while True:
 				try:
 					self.bookmarks.update_if_outdated()
+					self.ui.poke()
 					self.ui.draw()
 					self.ui.finalize()
 
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index ef0260dc..495c78c7 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -77,10 +77,14 @@ Override this!"""
 		"""Called when a key is pressed and self.focused is True.
 Override this!"""
 		pass
+
+	def poke(self):
+		"""Called before drawing, even if invisible"""
 	
 	def draw(self):
-		"""Draw displayable. Called on every main iteration.
-Override this!"""
+		"""Draw displayable.  Called on every main iteration if the object
+is visible.  Override this!
+"""
 		pass
 
 	def finalize(self):
@@ -129,14 +133,19 @@ class DisplayableContainer(Displayable):
 		Displayable.__init__(self, win)
 		self.container = []
 
-	def draw(self):
+	def poke(self):
 		"""Recursively called on objects in container"""
 		for displayable in self.container:
+			displayable.poke()
+
+	def draw(self):
+		"""Recursively called on visible objects in container"""
+		for displayable in self.container:
 			if displayable.visible:
 				displayable.draw()
 
 	def finalize(self):
-		"""Recursively called on objects in container"""
+		"""Recursively called on visible objects in container"""
 		for displayable in self.container:
 			if displayable.visible:
 				displayable.finalize()
diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py
index 60c3e2f9..4f9a7149 100644
--- a/ranger/gui/widgets/filelist.py
+++ b/ranger/gui/widgets/filelist.py
@@ -5,6 +5,7 @@ class FileList(Widget):
 	main_display = False
 	display_infostring = False
 	scroll_begin = 0
+	target = None
 
 	def __init__(self, win, level):
 		Widget.__init__(self, win)
@@ -42,21 +43,35 @@ class FileList(Widget):
 
 		return True
 
-	def draw(self):
-		"""Call either draw_file() or draw_directory()"""
+	def has_preview(self):
 		from ranger.fsobject.file import File
 		from ranger.fsobject.directory import Directory
 
+		if self.target is None:
+			return False
+
+		if isinstance(self.target, File):
+			if not self.settings.preview_files:
+				return False
+
+		return True
+
+	def poke(self):
 		self.target = self.env.at_level(self.level)
 
+	def draw(self):
+		"""Call either draw_file() or draw_directory()"""
+		from ranger.fsobject.file import File
+		from ranger.fsobject.directory import Directory
+
 		if self.target is None:
 			pass
 		elif type(self.target) == File:
 			self.draw_file()
 		elif type(self.target) == Directory:
 			self.draw_directory()
-		else:
-			self.win.addnstr(self.y, self.x, "unknown type.", self.wid)
+#		else:
+#			self.win.addnstr(self.y, self.x, "unknown type.", self.wid)
 
 	def draw_file(self):
 		"""Draw a preview of the file, if the settings allow it"""
diff --git a/ranger/gui/widgets/filelistcontainer.py b/ranger/gui/widgets/filelistcontainer.py
index 9d95b389..594d0530 100644
--- a/ranger/gui/widgets/filelistcontainer.py
+++ b/ranger/gui/widgets/filelistcontainer.py
@@ -2,15 +2,19 @@
 from . import Widget
 from .filelist import FileList
 from ..displayable import DisplayableContainer
+from ranger import log
 
 class FileListContainer(Widget, DisplayableContainer):
 	ratios = None
 	preview = True
+	preview_available = True
 
 	def __init__(self, win, ratios, preview = True):
 		DisplayableContainer.__init__(self, win)
 		from functools import reduce
 		self.ratios = ratios
+		self.preview = preview
+
 		# normalize ratios:
 		ratio_sum = float(reduce(lambda x,y: x + y, ratios))
 		self.ratios = tuple(map(lambda x: x / ratio_sum, ratios))
@@ -34,10 +38,28 @@ class FileListContainer(Widget, DisplayableContainer):
 		"""Resize all the filelists according to the given ratio"""
 		DisplayableContainer.resize(self, y, x, hei, wid)
 		left = self.x
-		for ratio, i in zip(self.ratios, range(len(self.ratios))):
+
+		cut_off_last = self.preview and not self.preview_available
+
+		if cut_off_last:
+			generator = zip(self.ratios[:-1], range(len(self.ratios)-1))
+		else:
+			generator = zip(self.ratios, range(len(self.ratios)))
+
+		for ratio, i in generator:
 			wid = int(ratio * self.wid)
+			if cut_off_last and i == len(self.ratios) - 2:
+				wid += int(self.ratios[-1] * self.wid)
 			try:
 				self.container[i].resize(self.y, left, hei, max(1, wid-1))
 			except KeyError:
 				pass
 			left += wid
+	
+	def poke(self):
+		DisplayableContainer.poke(self)
+		if self.preview:
+			has_preview = self.container[-1].has_preview()
+			if self.preview_available != has_preview:
+				self.preview_available = has_preview
+				self.resize(self.y, self.x, self.hei, self.wid)
49 +0100 updated pydoc documentation' href='/akspecs/ranger/commit/doc/pydoc/ranger.actions.html?h=v1.9.0b6&id=4c13e1f2d85483e026d79ab05da9f1e8e4b45293'>4c13e1f2 ^
f07bb12f ^





4c13e1f2 ^
f07bb12f ^


4c13e1f2 ^



f07bb12f ^

4c13e1f2 ^


f07bb12f ^





4c13e1f2 ^





f07bb12f ^












b3556b21 ^
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