summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-04-02 23:27:41 +0200
committerhut <hut@lavabit.com>2012-04-02 23:27:41 +0200
commite8bbfe62969f11d2c30ef73f9c1c2aaabe3648e0 (patch)
treeb07eb15fd02e1184ae5ba14c16d93b24b71c0ad8
parent85dd70190c70113f6e37ada4512539ae6533aa61 (diff)
downloadranger-e8bbfe62969f11d2c30ef73f9c1c2aaabe3648e0.tar.gz
core.loader: added pause()
-rw-r--r--ranger/core/actions.py3
-rw-r--r--ranger/core/fm.py2
-rw-r--r--ranger/core/loader.py39
3 files changed, 39 insertions, 5 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 76a9088a..1fae51b2 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -454,6 +454,9 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def taskview_move(self, narg=None, **kw):
 		self.ui.taskview.move(narg=narg, **kw)
 
+	def pause_tasks(self):
+		self.loader.pause(-1)
+
 	def pager_close(self):
 		if self.ui.pager.visible:
 			self.ui.close_pager()
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index f2366613..50c22067 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -189,7 +189,7 @@ class FM(Actions, SignalDispatcher):
 
 				ui.redraw()
 
-				ui.set_load_mode(loader.has_work())
+				ui.set_load_mode(not loader.paused and loader.has_work())
 
 				ui.handle_input()
 
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index fca9b5b8..777ce0f2 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -111,8 +111,8 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
 				self.process.send_signal(20)
 			except:
 				pass
-		Loadable.pause(self)
-		self.signal_emit('pause', process=self.process, loader=self)
+			Loadable.pause(self)
+			self.signal_emit('pause', process=self.process, loader=self)
 
 	def unpause(self):
 		if not self.finished and self.paused:
@@ -120,8 +120,8 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
 				self.process.send_signal(18)
 			except:
 				pass
-		Loadable.unpause(self)
-		self.signal_emit('unpause', process=self.process, loader=self)
+			Loadable.unpause(self)
+			self.signal_emit('unpause', process=self.process, loader=self)
 
 	def destroy(self):
 		self.signal_emit('destroy', process=self.process, loader=self)
@@ -142,6 +142,8 @@ def safeDecode(string):
 class Loader(FileManagerAware):
 	seconds_of_work_time = 0.03
 	throbber_chars = r'/-\|'
+	throbber_paused = '#'
+	paused = False
 
 	def __init__(self):
 		self.queue = deque()
@@ -166,6 +168,10 @@ class Loader(FileManagerAware):
 		while obj in self.queue:
 			self.queue.remove(obj)
 		self.queue.appendleft(obj)
+		if self.paused:
+			obj.pause()
+		else:
+			obj.unpause()
 
 	def move(self, _from, to):
 		try:
@@ -201,11 +207,34 @@ class Loader(FileManagerAware):
 			item.destroy()
 			del self.queue[index]
 
+	def pause(self, state):
+		"""
+		Change the pause-state to 1 (pause), 0 (no pause) or -1 (toggle)
+		"""
+		if state == -1:
+			state = not self.paused
+		elif state == self.paused:
+			return
+
+		self.paused = state
+
+		if not self.queue:
+			return
+
+		if state:
+			self.queue[0].pause()
+		else:
+			self.queue[0].unpause()
+
 	def work(self):
 		"""
 		Load items from the queue if there are any.
 		Stop after approximately self.seconds_of_work_time.
 		"""
+		if self.paused:
+			self.status = self.throbber_paused
+			return
+
 		while True:
 			# get the first item with a proper load_generator
 			try:
@@ -217,6 +246,8 @@ class Loader(FileManagerAware):
 			except IndexError:
 				return
 
+		item.unpause()
+
 		self.rotate()
 		if item != self.old_item:
 			if self.old_item: