Log errors when instantiation fails in hooke.util.pluggable.construct_*().
[hooke.git] / hooke / ui / gui / handler / __init__.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 from ....util.pluggable import IsSubclass, construct_graph
20
21
22 HANDLER_MODULES = [
23     'boolean',
24     'float',
25 #    'int'
26 #    'point',
27     'selection',
28     'string'
29     ]
30 """List of handler modules.  TODO: autodiscovery
31 """
32
33 class Handler (object):
34     """Base class for :class:`~hooke.interaction.Request` handlers.
35     
36     :attr:`name` identifies the request type and should match the
37     module name.
38     """
39     def __init__(self, name):
40         self.name = name
41
42     def run(self, hooke_frame, msg):
43         raise NotImplemented
44
45     def _cancel(self, *args, **kwargs):
46         # TODO: somehow abort the running command
47
48
49 HANDLERS = construct_odict(
50     this_modname=__name__,
51     submodnames=USER_INTERFACE_MODULES,
52     class_selector=IsSubclass(UserInterface, blacklist=[UserInterface]))
53 """:class:`hooke.compat.odict.odict` of :class:`Handler`
54 instances keyed by `.name`.
55 """