source: orange/Orange/OrangeCanvas/registry/__init__.py @ 11285:c0fc66213bfd

Revision 11285:c0fc66213bfd, 2.2 KB checked in by Ales Erjavec <ales.erjavec@…>, 15 months ago (diff)

Changed discovery to run from arbitrary entry points iterator/group.

Line 
1"""
2===============
3Widget Registry
4===============
5
6A registry (and discovery) of available widgets.
7
8"""
9
10import logging
11
12# Color names that can be used in widget/category descriptions
13# as background color.
14NAMED_COLORS = \
15    {"light-orange": "#FFD39F",
16     "orange": "#FFA840",
17     "light-red": "#FFB7B1",
18     "red": "#FF7063",
19     "light-pink": "#FAC1D9",
20     "pink": "#F584B4",
21     "light-purple": "#E5BBFB",
22     "purple": "#CB77F7",
23     "light-blue": "#CAE1FC",
24     "blue": "#95C3F9",
25     "light-turquoise": "#C3F3F3",
26     "turquoise": "#87E8E8",
27     "light-green": "#ACE3CE",
28     "green": "#5AC79E",
29     "light-grass": "#DFECB0",
30     "grass": "#C0D962",
31     "light-yellow": "#F7F5A7",
32     "yellow": "#F0EC4F",
33     }
34
35
36from .description import (
37    WidgetDescription, CategoryDescription,
38    InputSignal, OutputSignal
39)
40
41from .base import WidgetRegistry, VERSION_HEX
42from . import discovery
43
44log = logging.getLogger(__name__)
45
46
47__GLOBAL_REGISTRY = {}
48
49
50def global_registry(entry_point_group="_default"):
51    """
52    Return a global WidgetRegistry instance for the entry point group.
53    If none exists then it will be created.
54
55    .. note:: This will be deprecated when a proper replacement for it's
56              uses can be found.
57
58    """
59    global __GLOBAL_REGISTRY
60    # TODO: lock
61    if __GLOBAL_REGISTRY.get(entry_point_group) is None:
62        log.debug("'global_registry()' - running widget discovery.")
63        if entry_point_group == "_default":
64            from ..config import widgets_entry_points
65            entry_points_iter = widgets_entry_points()
66        else:
67            entry_points_iter = entry_point_group
68        reg = WidgetRegistry()
69        disc = discovery.WidgetDiscovery(reg)
70        disc.run(entry_points_iter)
71        log.info("'global_registry()' discovery finished.")
72        __GLOBAL_REGISTRY[entry_point_group] = reg
73
74    return __GLOBAL_REGISTRY[entry_point_group]
75
76
77def set_global_registry(registry, entry_point_group="_default"):
78    """
79    Set the global WidgetRegistry instance for the entry point group.
80
81    .. note:: Overrides previous registry.
82
83    """
84    global __GLOBAL_REGISTRY
85    log.debug("'set_global_registry()' - setting registry.")
86    __GLOBAL_REGISTRY[entry_point_group] = registry
Note: See TracBrowser for help on using the repository browser.