summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-12 17:18:52 +0200
committerhut <hut@lavabit.com>2012-08-12 17:18:52 +0200
commit44712346bbfd019c09471134c0921c8968273ebf (patch)
treeabe3f2e48b024e4dcabb23d53ebf752725f7093c /ranger
parent7cf6dfd2cb194a445fababe30946028931f3971c (diff)
downloadranger-44712346bbfd019c09471134c0921c8968273ebf.tar.gz
widgets.statusbar: draw an averaging progress bar
Diffstat (limited to 'ranger')
-rw-r--r--ranger/colorschemes/default.py2
-rw-r--r--ranger/config/options.py4
-rw-r--r--ranger/container/settingobject.py1
-rw-r--r--ranger/core/loader.py9
-rw-r--r--ranger/fsobject/directory.py1
-rw-r--r--ranger/gui/widgets/statusbar.py13
-rw-r--r--ranger/gui/widgets/taskview.py6
7 files changed, 32 insertions, 4 deletions
diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py
index aed6812a..db9dd2bb 100644
--- a/ranger/colorschemes/default.py
+++ b/ranger/colorschemes/default.py
@@ -90,6 +90,8 @@ class Default(ColorScheme):
 				if context.bad:
 					attr |= bold
 					fg = red
+			if context.loaded:
+				bg = green
 
 		if context.text:
 			if context.highlight:
diff --git a/ranger/config/options.py b/ranger/config/options.py
index 681feabc..a401abc5 100644
--- a/ranger/config/options.py
+++ b/ranger/config/options.py
@@ -54,6 +54,10 @@ collapse_preview = True
 # Save the console history on exit?
 save_console_history = True
 
+# Draw a progress bar in the status bar which displays the average state of all
+# currently running tasks which support progress bars?
+draw_progress_bar_in_status_bar = True
+
 # Draw borders around columns?
 draw_borders = False
 draw_bookmark_borders = True
diff --git a/ranger/container/settingobject.py b/ranger/container/settingobject.py
index cbc56278..f70361b5 100644
--- a/ranger/container/settingobject.py
+++ b/ranger/container/settingobject.py
@@ -18,6 +18,7 @@ ALLOWED_SETTINGS = {
 	'display_tags_in_all_columns': bool,
 	'draw_bookmark_borders': bool,
 	'draw_borders': bool,
+	'draw_progress_bar_in_status_bar': bool,
 	'flushinput': bool,
 	'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'),
 	'init_function': (type(None), type(lambda:0)),
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index 7bbd2abf..6e64e535 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -17,10 +17,11 @@ except:
 
 class Loadable(object):
 	paused = False
+	progressbar_supported = False
 	def __init__(self, gen, descr):
 		self.load_generator = gen
 		self.description = descr
-		self.percent = -1
+		self.percent = 0
 
 	def get_description(self):
 		return self.description
@@ -207,6 +208,8 @@ class Loader(FileManagerAware):
 				item.unload()
 			item.destroy()
 			del self.queue[index]
+			if item.progressbar_supported:
+				self.fm.ui.status.request_redraw()
 
 	def pause(self, state):
 		"""
@@ -261,9 +264,13 @@ class Loader(FileManagerAware):
 		try:
 			while time() < end_time:
 				next(item.load_generator)
+			if item.progressbar_supported:
+				self.fm.ui.status.request_redraw()
 		except StopIteration:
 			item.load_generator = None
 			self.queue.remove(item)
+			if item.progressbar_supported:
+				self.fm.ui.status.request_redraw()
 		except Exception as err:
 			self.fm.notify(err)
 
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 823eaeaf..a58201c0 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -52,6 +52,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware):
 	load_generator = None
 	cycle_list = None
 	loading = False
+	progressbar_supported = True
 
 	filenames = None
 	files = None
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index bf5ee641..3c9d0ed8 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -264,7 +264,18 @@ class StatusBar(Widget):
 		for part in result:
 			self.color(*part.lst)
 			self.addstr(str(part))
-		self.color_reset()
+
+		if self.settings.draw_progress_bar_in_status_bar:
+			queue = self.fm.loader.queue
+			states = []
+			for item in queue:
+				if item.progressbar_supported:
+					states.append(item.percent)
+			if states:
+				state = sum(states) / len(states)
+				barwidth = state / 100.0 * self.wid
+				self.color_at(0, 0, int(barwidth), ("in_statusbar", "loaded"))
+				self.color_reset()
 
 def get_free_space(path):
 	stat = os.statvfs(path)
diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py
index 53da5826..e5efc417 100644
--- a/ranger/gui/widgets/taskview.py
+++ b/ranger/gui/widgets/taskview.py
@@ -51,8 +51,10 @@ class TaskView(Widget, Accumulator):
 						clr.append('selected')
 
 					descr = obj.get_description()
-					if obj.percent >= 0 and obj.percent <= 100:
-						self.addstr(y, 0, "%3d%% - %s" % (obj.percent, descr), self.wid)
+					if obj.progressbar_supported and obj.percent >= 0 \
+							and obj.percent <= 100:
+						self.addstr(y, 0, "%3d%% - %s" % \
+								(obj.percent, descr), self.wid)
 						wid = int(self.wid / 100.0 * obj.percent)
 						self.color_at(y, 0, self.wid, tuple(clr))
 						self.color_at(y, 0, wid, tuple(clr), 'loaded')