Ignore:
Timestamp:
01/25/13 17:42:19 (15 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/registry/__init__.py

    r11098 r11285  
    4040 
    4141from .base import WidgetRegistry, VERSION_HEX 
     42from . import discovery 
    4243 
    4344log = logging.getLogger(__name__) 
    4445 
    4546 
    46 __GLOBAL_REGISTRY = None 
     47__GLOBAL_REGISTRY = {} 
    4748 
    4849 
    49 def global_registry(): 
    50     """Return a global WidgetRegistry instance. 
     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 
    5158    """ 
    5259    global __GLOBAL_REGISTRY 
    5360    # TODO: lock 
    54     if __GLOBAL_REGISTRY is None: 
     61    if __GLOBAL_REGISTRY.get(entry_point_group) is None: 
    5562        log.debug("'global_registry()' - running widget discovery.") 
    56         from . import 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 
    5768        reg = WidgetRegistry() 
    5869        disc = discovery.WidgetDiscovery(reg) 
    59         disc.run() 
     70        disc.run(entry_points_iter) 
    6071        log.info("'global_registry()' discovery finished.") 
    61         __GLOBAL_REGISTRY = reg 
     72        __GLOBAL_REGISTRY[entry_point_group] = reg 
    6273 
    63     return __GLOBAL_REGISTRY 
     74    return __GLOBAL_REGISTRY[entry_point_group] 
    6475 
    6576 
    66 def set_global_registry(registry): 
     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    """ 
    6784    global __GLOBAL_REGISTRY 
    6885    log.debug("'set_global_registry()' - setting registry.") 
    69     __GLOBAL_REGISTRY = registry 
     86    __GLOBAL_REGISTRY[entry_point_group] = registry 
Note: See TracChangeset for help on using the changeset viewer.