source: orange/Orange/OrangeCanvas/registry/__init__.py @ 11440:cb2508213612

Revision 11440:cb2508213612, 2.6 KB checked in by Ales Erjavec <ales.erjavec@…>, 13 months ago (diff)

Fixed default colors for nodes in the canvas.

RevLine 
[11098]1"""
[11418]2========
3Registry
4========
5
[11368]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]).
[11098]10
[11368]11The :class:`WidgetDiscovery` can be used to populate the registry.
12
[11098]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
[11440]42# default color when the category does not provide it
43DEFAULT_COLOR = "light-yellow"
44
45
[11098]46from .description import (
47    WidgetDescription, CategoryDescription,
48    InputSignal, OutputSignal
49)
50
51from .base import WidgetRegistry, VERSION_HEX
[11285]52from . import discovery
[11368]53from .discovery import WidgetDiscovery
[11098]54
55log = logging.getLogger(__name__)
56
57
[11285]58__GLOBAL_REGISTRY = {}
[11098]59
60
[11285]61def global_registry(entry_point_group="_default"):
62    """
63    Return a global WidgetRegistry instance for the entry point group.
64    If none exists then it will be created.
65
66    .. note:: This will be deprecated when a proper replacement for it's
67              uses can be found.
68
[11098]69    """
70    global __GLOBAL_REGISTRY
71    # TODO: lock
[11285]72    if __GLOBAL_REGISTRY.get(entry_point_group) is None:
[11098]73        log.debug("'global_registry()' - running widget discovery.")
[11285]74        if entry_point_group == "_default":
75            from ..config import widgets_entry_points
76            entry_points_iter = widgets_entry_points()
77        else:
78            entry_points_iter = entry_point_group
[11098]79        reg = WidgetRegistry()
80        disc = discovery.WidgetDiscovery(reg)
[11285]81        disc.run(entry_points_iter)
[11098]82        log.info("'global_registry()' discovery finished.")
[11285]83        __GLOBAL_REGISTRY[entry_point_group] = reg
[11098]84
[11285]85    return __GLOBAL_REGISTRY[entry_point_group]
[11098]86
87
[11285]88def set_global_registry(registry, entry_point_group="_default"):
89    """
90    Set the global WidgetRegistry instance for the entry point group.
91
92    .. note:: Overrides previous registry.
93
94    """
[11098]95    global __GLOBAL_REGISTRY
96    log.debug("'set_global_registry()' - setting registry.")
[11285]97    __GLOBAL_REGISTRY[entry_point_group] = registry
Note: See TracBrowser for help on using the repository browser.