Ignore:
Timestamp:
23 Apr 2011, 01:46:57 (14 years ago)
Author:
uli
Message:

Replace themes source by themes vocabulary. It looks like this is much easier to handle in the long run.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/theming.py

    r5963 r5968  
    2626from zope.component import getUtilitiesFor
    2727from zope.interface import Interface
    28 from waeup.sirp.interfaces import IThemesProvider
     28from zope.schema.interfaces import IVocabularyFactory
     29from waeup.sirp.interfaces import SimpleWAeUPVocabulary
    2930from waeup.sirp.browser.interfaces import ITheme
    3031from waeup.sirp.browser.resources import waeuptheme_red1, waeuptheme_gray1
     
    5859        yield name, theme
    5960
    60 class ThemesProvider(grok.GlobalUtility):
    61     """A global utility providing all themes available.
     61class ThemesVocabulary(grok.GlobalUtility):
     62    """A vocabulary that provides all themes available.
     63
     64    A named global utility implementing
     65
     66      :class:`zope.schema.interfaces.IVocabularyFactory
     67
     68    and registered under the name
     69
     70      'waeup.sirp.browser.theming.ThemesVocabulary'
     71   
     72    Interface fields that wish to provide a list of available themes
     73    can require a 'named vocabulary', i.e. set:
     74
     75      vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary'
     76
     77    and the vocabulary will deliver themes and their descriptive text
     78    for instance in select boxes of forms.
     79
     80    The name is chosen so that the location of this vocabulary can be
     81    found easily when used in an interface definition.
    6282    """
    63     grok.implements(IThemesProvider)
    64     grok.name('default')
     83    grok.implements(IVocabularyFactory)
     84    grok.name('waeup.sirp.browser.theming.ThemesVocabulary')
     85   
     86    def __call__(self, context):
     87        """Deliver a vocabulary of available themes.
    6588
    66     def __call__(self):
    67         return get_all_themes()
     89        The `description`s of available themes are used as 'title' and
     90        the utility names delivering the different themes as 'value'
     91        and 'token'.
     92        """
     93        terms = [(theme.description, name)
     94                 for name, theme in get_all_themes()]
     95        vocab = SimpleWAeUPVocabulary(*terms)
     96        return vocab
Note: See TracChangeset for help on using the changeset viewer.