summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-14 13:32:27 +0100
committerhut <hut@lavabit.com>2009-12-14 13:32:27 +0100
commitd621586ed4b11b059d0de42c9af340bc94db9944 (patch)
tree0587936d73fbc02a8f22e53b0b018acd363e1913
parent733dbb9dbb608e8a0dec0e836c07b1dd7feb4d17 (diff)
downloadranger-d621586ed4b11b059d0de42c9af340bc94db9944.tar.gz
"poke" widgets, expand last column if there's no preview
-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)