lib/actions.py
author fabien@tzone.org
Mon, 05 Jan 2009 18:11:38 -0500
changeset 76 147eddb3826c
parent 74 6784c4350b41
permissions -rw-r--r--
Remove ActionLoader and replace it with a standard dict of new Action objects. Fixes a bad behavior with default action.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     1
import imp
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     2
import sys
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     3
import os
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     4
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     5
76
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
     6
class Action:
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
     7
	def __init__(self, mname, fname):
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
     8
		self.mname = mname
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
     9
		self.fname = fname
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    10
	def _getmodule(self):
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    11
		modpath = os.path.join(os.path.dirname(__file__), 'actions')
76
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    12
		fp, pathname, description = imp.find_module(self.mname, [modpath])
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    13
		try:
76
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    14
			return imp.load_module(self.mname, fp, pathname, description)
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    15
		finally:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    16
			if fp:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    17
				fp.close()
76
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    18
	def __call__(self, *args):
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    19
		apply(self._getmodule().__dict__[self.fname],args)
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    20
		
76
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    21
actions = {}
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    22
actions['index'] = Action('index', 'do_it')
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    23
actions['import'] = Action('imp_xbel', 'do_it')
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    24
actions['bookmark'] = Action('bookmark', 'do_it')
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    25
actions['keywords'] = Action('editkw', 'do_it')
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    26
actions['prefs'] = Action('edit_prefs', 'do_it')
147eddb3826c Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents: 74
diff changeset
    27
actions['folder'] = Action('folder', 'do_it')
74
6784c4350b41 Cleanup of old code, fixes some errors with folders view and make it a
fabien@tzone.org
parents: 73
diff changeset
    28
actions['default'] = actions['index']