summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-10-08 21:59:43 +0200
committerhut <hut@lavabit.com>2010-10-08 22:11:02 +0200
commitc1f3125c53152b4eaa554a5e4d3a2ee2dbd6dfd8 (patch)
tree0c0ddc2ae0d3f9e9b8429390c55b172a3b1c3250
parentd538bd40182a00d4b6e6327d091a9e0943ee2976 (diff)
downloadranger-c1f3125c53152b4eaa554a5e4d3a2ee2dbd6dfd8.tar.gz
fsobject.file: reload pager when preview finished loading
-rw-r--r--ranger/core/actions.py2
-rw-r--r--ranger/core/loader.py2
-rw-r--r--ranger/fsobject/file.py19
-rw-r--r--ranger/gui/widgets/browsercolumn.py3
4 files changed, 15 insertions, 11 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index e290db58..59eef2be 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -569,7 +569,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 			return
 
 		pager = self.ui.open_embedded_pager()
-		pager.set_source(self.env.cf.get_preview_source(pager))
+		pager.set_source(self.env.cf.get_preview_source(pager.wid, pager.hei))
 
 	# --------------------------
 	# -- Tabs
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index 66f7017c..c03ecc29 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -74,7 +74,7 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
 						self.fm.notify(error, bad=True)
 			except select.error:
 				pass
-			sleep(0.02)
+#			sleep(0.02)
 			yield
 		self.finished = True
 		self.signal_emit('after', process=process)
diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py
index 5458b8b1..2701537c 100644
--- a/ranger/fsobject/file.py
+++ b/ranger/fsobject/file.py
@@ -56,6 +56,7 @@ class File(FileSystemObject):
 	is_file = True
 	preview_data = None
 	preview_known = False
+	preview_loading = False
 
 	@property
 	def firstbytes(self):
@@ -94,22 +95,24 @@ class File(FileSystemObject):
 			return False
 		return True
 
-	def update_preview(self, signal):
+	def _update_preview(self, signal):
 		self.preview_known = True
 		self.preview_data = None
 		if not signal.process.poll():
 			self.preview_data = signal.process.stdout.read()
-			self.fm.ui.pager.need_redraw = True
-			self.fm.ui.redraw()
+		if self.fm.env.cf.path == self.path:
+			self.fm.ui.browser.pager.need_redraw = True
+			self.fm.ui.browser.need_redraw = True
 
-	def get_preview_source(self, widget):
+	def get_preview_source(self, width, height):
 		if self.fm.settings.preview_script:
-			if self.preview_known:
+			if self.preview_known or self.preview_loading:
 				return self.preview_data
+			self.preview_loading = True
 			loadable = CommandLoader(args=[self.fm.settings.preview_script,
-				self.path, str(widget.wid), str(widget.hei)],
+				self.path, str(width), str(height)],
 				descr="Getting preview of %s" % self.path)
-			loadable.signal_bind('after', self.update_preview, weak=True)
+			loadable.signal_bind('after', self._update_preview, weak=True)
 			self.fm.loader.add(loadable)
-			return "loading..."
+			return None
 		return open(self.path, 'r')
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 63323f65..eb898e2a 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -156,8 +156,9 @@ class BrowserColumn(Pager):
 			return
 
 		try:
-			f = self.target.get_preview_source(self)
+			f = self.target.get_preview_source(self.wid, self.hei)
 		except:
+			raise # XXX
 			Pager.close(self)
 		else:
 			if f is None: