source: orange/Orange/OrangeCanvas/registry/__init__.py @ 11418:6abbcdf4ff7c

Revision 11418:6abbcdf4ff7c, 2.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 13 months ago (diff)

Widget registry documentation fixup.

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