source: orange/Orange/OrangeCanvas/registry/__init__.py @ 11368:7de87de13b64

Revision 11368:7de87de13b64, 2.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 14 months ago (diff)

Added rst documentation for the registry package.

Fixing docstrings in the process.

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