Remove ActionLoader and replace it with a standard
authorfabien@tzone.org
Mon, 05 Jan 2009 18:11:38 -0500
changeset 76 147eddb3826c
parent 75 4f6b7b48322f
child 77 52b13b0616b8
Remove ActionLoader and replace it with a standard dict of new Action objects. Fixes a bad behavior with default action.
lib/actions.py
--- a/lib/actions.py	Wed Dec 31 16:26:22 2008 -0500
+++ b/lib/actions.py	Mon Jan 05 18:11:38 2009 -0500
@@ -3,32 +3,26 @@
 import os
 
 
-class ActionsLoader:
-	def __init__(self):
-		self._actions = {}
-	def keys(self):
-		return self._actions.keys()
-	def _getmodule(self, name):
+class Action:
+	def __init__(self, mname, fname):
+		self.mname = mname
+		self.fname = fname
+	def _getmodule(self):
 		modpath = os.path.join(os.path.dirname(__file__), 'actions')
-		fp, pathname, description = imp.find_module(name, [modpath])
+		fp, pathname, description = imp.find_module(self.mname, [modpath])
 		try:
-			return imp.load_module(name, fp, pathname, description)
+			return imp.load_module(self.mname, fp, pathname, description)
 		finally:
 			if fp:
 				fp.close()
-	def __getitem__(self, item):
-		mname, fname = self._actions[item]
-		return self._getmodule(mname).__dict__[fname]
-	def __setitem__(self, key, value):
-		self._actions[key] = value
+	def __call__(self, *args):
+		apply(self._getmodule().__dict__[self.fname],args)
 		
-
-actions = ActionsLoader()
-actions['index'] = ('index', 'do_it')
-actions['import'] = ('imp_xbel', 'do_it')
-actions['bookmark'] = ('bookmark', 'do_it')
-actions['keywords'] = ('editkw', 'do_it')
-actions['prefs'] = ('edit_prefs', 'do_it')
-actions['folder'] = ('folder', 'do_it')
-
+actions = {}
+actions['index'] = Action('index', 'do_it')
+actions['import'] = Action('imp_xbel', 'do_it')
+actions['bookmark'] = Action('bookmark', 'do_it')
+actions['keywords'] = Action('editkw', 'do_it')
+actions['prefs'] = Action('edit_prefs', 'do_it')
+actions['folder'] = Action('folder', 'do_it')
 actions['default'] = actions['index']