# HG changeset patch # User fabien@tzone.org # Date 1231197098 18000 # Node ID 147eddb3826c7b3459cc76a014853d8bc37bd273 # Parent 4f6b7b48322f101bd8e5ffe40ab3968ba67e0361 Remove ActionLoader and replace it with a standard dict of new Action objects. Fixes a bad behavior with default action. diff -r 4f6b7b48322f -r 147eddb3826c 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']