[kupfer: 2/11] compose: Add composition action Run After Delay...



commit 105c6f1c0ce6397ee7ead9a4a1f83da8006f19e8
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Dec 13 21:29:22 2009 +0100

    compose: Add composition action Run After Delay...
    
    This is something that is directly inspired from Quicksilver.

 kupfer/objects.py |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index dc795c6..695287e 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -1130,6 +1130,35 @@ class ProxyDo (Action):
 	def is_async(self):
 		return self.action.is_async()
 
+class TimedDo (Do):
+	"""A timed proxy version of Do
+
+	Proxy factory/result/async from a delegate action
+	Delay action by a couple of seconds
+	"""
+	def __init__(self):
+		Action.__init__(self, _("Run After Delay..."))
+
+	def _run(self, leaf):
+		leaf.run()
+
+	def activate(self, leaf, iobj=None):
+		from kupfer import scheduler
+		# make a timer that will fire when Kupfer exits
+		timer = scheduler.Timer(True)
+		timer.set(int(iobj.object), self._run, leaf)
+
+	def requires_object(self):
+		return True
+	def object_types(self):
+		yield TextLeaf
+
+	def valid_object(self, iobj, for_item=None):
+		try:
+			return int(iobj.object) > 0
+		except ValueError:
+			return False
+
 class ComposedLeaf (RunnableLeaf):
 	def __init__(self, obj, action, iobj=None):
 		object_ = (obj, action, iobj)
@@ -1137,7 +1166,10 @@ class ComposedLeaf (RunnableLeaf):
 		RunnableLeaf.__init__(self, object_, name)
 
 	def get_actions(self):
-		yield ProxyDo(self.object[1])
+		action = self.object[1]
+		yield ProxyDo(action)
+		if not action.is_factory():
+			yield TimedDo()
 
 	def run(self):
 		obj, action, iobj = self.object



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]