[kupfer] Implement "Last Result" proxy object



commit 61ebbed29253b07804c10c05ec4b186ac3004478
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 29 17:59:25 2010 +0200

    Implement "Last Result" proxy object

 kupfer/plugin/core/internal.py |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/core/internal.py b/kupfer/plugin/core/internal.py
index 3d51e3b..5a02063 100644
--- a/kupfer/plugin/core/internal.py
+++ b/kupfer/plugin/core/internal.py
@@ -1,5 +1,5 @@
 
-from kupfer.objects import Source
+from kupfer.objects import Source, Leaf
 from kupfer.objects import RunnableLeaf
 from kupfer import commandexec
 
@@ -30,6 +30,30 @@ class KupferInterals (Source):
 	def provides(self):
 		yield LastCommand
 
+class LastResultObject (Leaf):
+	"dummy superclass"
+
+def _make_first_result_object(leaf):
+	global LastResultObject
+	class LastResultObject (LastResultObject):
+		qf_id = "lastresult"
+		def __init__(self, leaf):
+			Leaf.__init__(self, leaf.object, _("Last Result"))
+			vars(self).update(vars(leaf))
+			self.name = _("Last Result")
+			self.__orignal_leaf = leaf
+			self.__class__.__bases__ = (leaf.__class__, Leaf)
+
+		def get_gicon(self):
+			return None
+		def get_icon_name(self):
+			return Leaf.get_icon_name(self)
+		def get_description(self):
+			return unicode(self.__orignal_leaf)
+
+	return LastResultObject(leaf)
+
+
 class CommandResults (Source):
 	def __init__(self):
 		Source.__init__(self, _("Command Results"))
@@ -39,5 +63,12 @@ class CommandResults (Source):
 		ctx = commandexec.DefaultActionExecutionContext()
 		for x in reversed(ctx.last_results):
 			yield x
+		try:
+			leaf = ctx.last_results[-1]
+		except IndexError:
+			return
+		yield _make_first_result_object(leaf)
+
 	def provides(self):
-		return ()
+		yield Leaf
+		yield LastResultObject



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