[kupfer] commandexec: More utility functions for action execution
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] commandexec: More utility functions for action execution
- Date: Tue, 12 Jan 2010 15:50:01 +0000 (UTC)
commit 7173fc44ca073b7db32139f038960d8560c888dd
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Tue Jan 12 16:08:30 2010 +0100
commandexec: More utility functions for action execution
kupfer/commandexec.py | 42 +++++++++++++++++++++++++++---------------
1 files changed, 27 insertions(+), 15 deletions(-)
---
diff --git a/kupfer/commandexec.py b/kupfer/commandexec.py
index 46a9dbd..25934d9 100644
--- a/kupfer/commandexec.py
+++ b/kupfer/commandexec.py
@@ -19,6 +19,30 @@ def DefaultActionExecutionContext():
class ActionExecutionError (Exception):
pass
+def activate_action(obj, action, iobj):
+ """ Activate @action in simplest manner """
+ if action.requires_object():
+ ret = action.activate(obj, iobj)
+ else:
+ ret = action.activate(obj)
+ return ret
+
+def parse_action_result(action, ret):
+ """Return result type for @action and return value @ret"""
+ def valid_result(ret):
+ return ret and (not hasattr(ret, "is_valid") or ret.is_valid())
+
+ # handle actions returning "new contexts"
+ res = RESULT_NONE
+ if action.is_factory() and valid_result(ret):
+ res = RESULT_SOURCE
+ if action.has_result() and valid_result(ret):
+ res = RESULT_OBJECT
+ elif action.is_async():
+ res = RESULT_ASYNC
+ return res
+
+
class ActionExecutionContext (gobject.GObject):
"""
command-result (result_type, result)
@@ -62,10 +86,7 @@ class ActionExecutionContext (gobject.GObject):
raise ActionExecutionError("%s requires indirect object" % action)
with self._nesting():
- if action.requires_object():
- ret = action.activate(obj, iobj)
- else:
- ret = action.activate(obj)
+ ret = activate_action(obj, action, iobj)
# remember last command, but not delegated commands.
if not delegate:
@@ -77,18 +98,9 @@ class ActionExecutionContext (gobject.GObject):
res, ret = ret
return self._return_result(res, ret)
- def valid_result(ret):
- return ret and (not hasattr(ret, "is_valid") or ret.is_valid())
-
- # handle actions returning "new contexts"
- res = RESULT_NONE
- if action.is_factory() and valid_result(ret):
- res = RESULT_SOURCE
- if action.has_result() and valid_result(ret):
- res = RESULT_OBJECT
- elif action.is_async():
+ res = parse_action_result(action, ret)
+ if res == RESULT_ASYNC:
self.task_runner.add_task(ret)
- res = RESULT_ASYNC
# Delegated command execution was requested: we pass
# through the result of the action to the parent execution context
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]