On Thu, 20 Apr 2006 09:55:39 -0400, Gary Poster wrote: 
> Go for it.

The following code works at least for for SourceDropdownWidget and
SourceOrderedMultiSelectWidget. I don't have contributor
privileges so I can't check it in. Happy to do so if someone wants to give
my the access, otherwise someone else can do it.

Cheers,
Sam.
----

# Input widgets for IIterableSource.

# These widgets reuse the old-style vocabulary widgets via the class
# IterableSourceVocabulary that adapts a source (and its ITerms object) 
# into a vocabulary. When/if vocabularies go away, these classes
# should be updated into full implementations.


class IterableSourceVocabulary(object):
    """Adapts an iterable source into a vocabulary.
    
    There must be an ITerms implementation registered to obtain
    the terms."""
    
    zope.interface.implements(IVocabularyTokenized)
    
    def __init__(self, source, request):
        self.source = source
        self.terms = zapi.getMultiAdapter(
            (source, request), zope.app.form.browser.interfaces.ITerms)
    
    def getTerm(self, value):
        return self.terms.getTerm(value)
        
    def getTermByToken(self, token):
        value = self.terms.getValue(token)
        return self.getTerm(value)
        
    def __iter__(self):
        return imap(
            lambda value: self.getTerm(value), self.source.__iter__())
            
    def __len__(self):
        return self.source.__len__()
        
    def __contains__(self, value):
        return self.source.__contains__(value)


class SourceSelectWidget(SelectWidget):
    """Provide a selection list for the item."""
    
    def __init__(self, field, source, request):
        super(SourceSelectWidget, self).__init__(
            field, IterableSourceVocabulary(source, request), request)

class SourceDropdownWidget(SourceSelectWidget):
    """Variation of the SourceSelectWidget that uses a drop-down list."""
    
    size = 1

class SourceRadioWidget(RadioWidget):
    """Radio widget for single item choices."""
    
    def __init__(self, field, source, request):
        super(SourceRadioWidget, self).__init__(
            field, IterableSourceVocabulary(source, request), request)

class SourceMultiSelectSetWidget(MultiSelectWidget):
    """Provide a selection list for the set to be selected."""
    
    def __init__(self, field, source, request):
        super(MultiSelectSetWidget, self).__init__(
            field, IterableSourceVocabulary(source, request), request)
    
class SourceOrderedMultiSelectWidget(OrderedMultiSelectWidget):
    """A multi-selection widget with ordering support."""
    
    def __init__(self, field, source, request):
        super(SourceOrderedMultiSelectWidget, self).__init__(
            field, IterableSourceVocabulary(source, request), request)
            
class SourceMultiCheckBoxWidget(MultiCheckBoxWidget):
    """Provide a list of checkboxes that provide the choice for the list."""
    
    def __init__(self, field, source, request):
        super(SourceMultiCheckBoxWidget, self).__init__(
            field, IterableSourceVocabulary(source, request), request)


_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to