[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Widgets/Browser - BrowserWidget.py:1.1.2.1 BrowserWidget.pyc:1.1.2.1 CheckBoxWidget.py:1.1.2.1 DateTimeWidget.py:1.1.2.1 FileWidget.py:1.1.2.1 IBrowserWidget.py:1.1.2.1 IBrowserWidget.pyc:1.1.2.1 ItemsWidget.py:1.1.2.1 LinesTextAreaWidget.py:1.1.2.1 ListTextAreaWidget.py:1.1.2.1 ListWidget.py:1.1.2.1 MultiItemsWidget.py:1.1.2.1 MultiListWidget.py:1.1.2.1 MultipleCheckBoxWidget.py:1.1.2.1 PasswordWidget.py:1.1.2.1 RadioWidget.py:1.1.2.1 SingleItemsWidget.py:1.1.2.1 TextAreaWidget.py:1.1.2.1 TextAreaWidget.pyc:1.1.2.1 TextWidget.py:1.1.2.1 TextWidget.pyc:1.1.2.1 __init__.py:1.1.2.1 __init__.pyc:1.1.2.1

Stephan Richter srichter@cbu.edu
Fri, 25 Jan 2002 09:11:13 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser
In directory cvs.zope.org:/tmp/cvs-serv20682/Formulator/Widgets/Browser

Added Files:
      Tag: Zope-3x-branch
	BrowserWidget.py BrowserWidget.pyc CheckBoxWidget.py 
	DateTimeWidget.py FileWidget.py IBrowserWidget.py 
	IBrowserWidget.pyc ItemsWidget.py LinesTextAreaWidget.py 
	ListTextAreaWidget.py ListWidget.py MultiItemsWidget.py 
	MultiListWidget.py MultipleCheckBoxWidget.py PasswordWidget.py 
	RadioWidget.py SingleItemsWidget.py TextAreaWidget.py 
	TextAreaWidget.pyc TextWidget.py TextWidget.pyc __init__.py 
	__init__.pyc 
Log Message:
- Initial check-in of the Formulator code
- Even though not everything works (specifically the widgets are in bad 
  shape), I am checking that stuff in, so that Jim, Martijn F. and I can
  better work together.
- The FileEdit screen (which will be checked in in a minute) uses already
  formulator.
- The validators are closed to finished.
- I think we have to rethink some of the design, simply because it is too
  hard right now to create a field and a view for a property, even though
  I provided already some handy methods. However Formulator does not 
  depend on Property-driven content objects.
- Please contact me (srichter@cbu.edu) or the Zope3 mailining list to 
  discuss issues and design.


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: BrowserWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from IBrowserWidget import IBrowserWidget
from Zope.App.Formulator.Widgets.Widget import Widget


class BrowserWidget(Widget):
    """A field widget that knows how to display itself as HTML.
    """

    __implements__ = IBrowserWidget

    propertyNames = Widget.propertyNames + \
                    ['tag', 'type', 'cssClass', 'hidden', 'extra']
    
    tag = 'input'
    type = 'text'
    cssClass = ''
    hidden = 0
    extra = ''

    def __init__(self, field):
        ''' '''
        self._field = field


    def getValueFromRequest(self, REQUEST):
        """ """
        return REQUEST.get('field_'+self.getContext().id, None)


    def _getValueToInsert(self, REQUEST):
        """ """
        field = self.getContext()
        if REQUEST and REQUEST.has_key('field_'+field.id):
            return REQUEST['field_'+field.id]
        else:
            return self.getContext().getPropertyInContext()
            

    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        return renderElement(self.getValue('tag'),
                             type = self.getValue('type'),
                             name = self.getContext().id,
                             value = self._getValueToInsert(REQUEST),
                             cssClass = self.getValue('cssClass'),
                             extra = self.getValue('extra'))

        
    def render_hidden(self, REQUEST=None):
        """Renders this widget as a hidden field.
        """
        return renderElement(self.getValue('tag'),
                             type = 'hidden',
                             name = self.getContext().id,
                             value = self._getValueToInsert(REQUEST),
                             cssClass = self.getValue('cssClass'),
                             extra = self.getValue('extra'))



def renderTag(tag, **kw):
    """Render the tag. Well, not all of it, as we may want to / it.
    """
    attr_list = []

    kw['name'] = 'field_' + kw['name']

    # special case handling for css_class
    if kw.has_key('cssClass'):
        if kw['cssClass'] != "":
            attr_list.append('class="%s"' % kw['cssClass'])
        del kw['cssClass']

    # special case handling for extra 'raw' code
    if kw.has_key('extra'):
        extra = kw['extra'] # could be empty string but we don't care
        del kw['extra']
    else:
        extra = ""

    # handle other attributes
    for key, value in kw.items():
        if value == None:
            value = key
        attr_list.append('%s="%s"' % (key, str(value)))
            
    attr_str = " ".join(attr_list)
    return "<%s %s %s" % (tag, attr_str, extra)


def renderElement(tag, **kw):
    if kw.has_key('contents'):
        contents = kw['contents']
        del kw['contents']
        return "%s>%s</%s>" % (apply(renderTag, (tag,), kw), contents, tag)
    else:
        return apply(renderTag, (tag,), kw) + " />"
    








=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pyc ===
-í
 aQ<c       sa     d  Z    d k l Z  d k l Z  d e f d „  ƒ  YZ O d „  Z m d „  Z d S(   s   

Revision information: $Id: BrowserWidget.pyc,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
(   s   IBrowserWidget(   s   Widgets
   BrowserWidgetc      s¥    d  Z    e Z  e i d d d d d g Z  d Z   d Z ! d Z " d	 Z # d Z	 % d
 „  Z
 * d „  Z / d „  Z 8 e
 d
 „ Z C e
 d „ Z RS(   s=   A field widget that knows how to display itself as HTML.
    s   tags   types   cssClasss   hiddens   extras   inputs   texts    i    c    s   % & ' | |  _ d S(   s    N(   s   fields   selfs   _field(   s   selfs   field(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys   __init__% s   c    s*   * + , | i d |  i ƒ  i t ƒ Sd S(   s    s   field_N(   s   REQUESTs   gets   selfs
   getContexts   ids   None(   s   selfs   REQUEST(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys   getValueFromRequest* s   c    sc   / 0 1 |  i ƒ  } 2 | o | i d | i ƒ o 3 | d | i Sn 5 |  i ƒ  i ƒ  Sd S(   s    s   field_N(   s   selfs
   getContexts   fields   REQUESTs   has_keys   ids   getPropertyInContext(   s   selfs   REQUESTs   field(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys   _getValueToInsert/ s
   !c  
  sz   8 : ; t  |  i d ƒ < d |  i d ƒ = d |  i ƒ  i > d |  i | ƒ ? d |  i d ƒ @ d |  i d ƒ ƒSd S(   sD   Renders this widget as HTML using property values in field.
        s   tags   types   names   values   cssClasss   extraN(   s
   renderElements   selfs   getValues
   getContexts   ids   _getValueToInserts   REQUEST(   s   selfs   REQUEST(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys   render8 s   c  
  sq   C E F t  |  i d ƒ G d d H d |  i ƒ  i I d |  i | ƒ J d |  i d ƒ K d |  i d ƒ ƒSd S(	   s/   Renders this widget as a hidden field.
        s   tags   types   hiddens   names   values   cssClasss   extraN(   s
   renderElements   selfs   getValues
   getContexts   ids   _getValueToInserts   REQUEST(   s   selfs   REQUEST(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys
   render_hiddenC s   	(   s   __doc__s   IBrowserWidgets   __implements__s   Widgets
   propertyNamess   tags   types   cssClasss   hiddens   extras   __init__s   getValueFromRequests   _getValueToInserts   Nones   renders
   render_hidden(    (    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys
   BrowserWidget s   								c    s6  O Q R g  } T d | d | d <W | i d ƒ o> X | d d j o Y | i d | d ƒ n Z | d =n ] | i d ƒ o ^ | d } _ | d =n
 a d } d xZ | i ƒ  Dd ]I \ } } e | t j o
 f | } n g | i d | t	 | ƒ f ƒ q¼ Wi d i
 | ƒ } j d	 |  | | f Sd
 S(   sA   Render the tag. Well, not all of it, as we may want to / it.
    s   field_s   names   cssClasss    s
   class="%s"s   extras   %s="%s"s    s	   <%s %s %sN(
   s	   attr_lists   kws   has_keys   appends   extras   itemss   keys   values   Nones   strs   joins   attr_strs   tag(   s   tags   kws   keys   extras   attr_strs	   attr_lists   value(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys	   renderTagO s$   	
	 
$c    sr   m n | i d ƒ o> o | d } p | d =q d t t |  f | ƒ | |  f Sn s t t |  f | ƒ d Sd  S(   Ns   contentss
   %s>%s</%s>s    />(   s   kws   has_keys   contentss   applys	   renderTags   tag(   s   tags   kws   contents(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys
   renderElementm s
   

'N(   s   __doc__s   IBrowserWidgets"   Zope.App.Formulator.Widgets.Widgets   Widgets
   BrowserWidgets	   renderTags
   renderElement(   s
   BrowserWidgets   Widgets   IBrowserWidgets
   renderElements	   renderTag(    (    sJ   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.pys   ? s
   9

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/CheckBoxWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: CheckBoxWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class CheckBoxWidget(BrowserWidget):
    """Text widget
    """

    __implements__ = BrowserWidget.__implements__

    propertyNames = BrowserWidget.propertyNames + \
                     ['extra', 'default']

    type = 'checkbox'
    default = 0
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        if self._getValueToInsert(REQUEST):
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 checked = None,
                                 cssClass = self.getValue('cssClass'),
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 extra = self.getValue('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/DateTimeWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: DateTimeWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Widget import Widget
from DateTime import DateTime



class DateTimeWidget(Widget):
    property_names = Widget.property_names +\
                     ['defaultNow', 'dateSeparator', 'timeSeparator',
                      'inputStyle', 'inputOrder',
                      'dateOnly']

    default = None
    defaultNow = 0                      
    dateSeparator = '/'
    timeSeparator = ':'
    inputStyle = "text"
    inputOrder = "ymd"
    dateOnly = 0

    # FIXME: do we want to handle 'extra'?
    
    def render(self, REQUEST=None):
        # FIXME: backwards compatibility hack:
        if not hasattr(field, 'sub_form'):
            from StandardFields import create_datetime_text_sub_form
            field.sub_form = create_datetime_text_sub_form()

        if value is None and field.get_value('default_now'):
            value = DateTime()

        if value is None:
            year = None
            month = None
            day = None
            hour = None
            minute = None
        else:
            year = "%04d" % value.year()
            month = "%02d" % value.month()
            day = "%02d" % value.day()
            hour = "%02d" % value.hour()
            minute = "%02d" % value.minute()
        
        input_order = field.get_value('input_order')
        if input_order == 'ymd':
            order = [('year', year),
                     ('month', month),
                     ('day', day)]
        elif input_order == 'dmy':
            order = [('day', day),
                     ('month', month),
                     ('year', year)]
        elif input_order == 'mdy':
            order = [('month', month),
                     ('day', day),
                     ('year', year)]
        result = []
        for sub_field_name, sub_field_value in order:
            result.append(field.render_sub_field(sub_field_name,
                                                 sub_field_value, REQUEST))
        date_result = string.join(result, field.get_value('date_separator'))
        if not field.get_value('date_only'):
            time_result = (field.render_sub_field('hour', hour, REQUEST) +
                           field.get_value('time_separator') +
                           field.render_sub_field('minute', minute, REQUEST))
            return date_result + '&nbsp;&nbsp;&nbsp;' + time_result
        else:
            return date_result
                       
DateTimeWidgetInstance = DateTimeWidget()


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/FileWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: FileWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from TextWidget import TextWidget


class FileWidget(TextWidget):

    __implements__ = TextWidget.__implements__

    type = 'file'


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: IBrowserWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Interface import Interface


class IBrowserWidget(Interface):
    """A field widget contains all the properties that are required
       to represent a field. Properties include css_sheet, 
       default value and so on.

    """


    def render(field, key, value, REQUEST):
        """Renders this widget as HTML using property values in field.
        """

        
    def render_hidden(field, key, value, REQUEST):
        """Renders this widget as a hidden field.
        """
        


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.pyc ===
-í
aQ<c       s9     d  Z    d k l Z  d e f d „  ƒ  YZ d S(   s   

Revision information: $Id: IBrowserWidget.pyc,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
(   s	   Interfaces   IBrowserWidgetc      s&    d  Z    d „  Z " d „  Z RS(   sž   A field widget contains all the properties that are required
       to represent a field. Properties include css_sheet, 
       default value and so on.

    c    s
     d S(   sD   Renders this widget as HTML using property values in field.
        N(    (   s   fields   keys   values   REQUEST(    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.pys   render s   c    s
   " $ d S(   s/   Renders this widget as a hidden field.
        N(    (   s   fields   keys   values   REQUEST(    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.pys
   render_hidden" s   (   s   __doc__s   renders
   render_hidden(    (    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.pys   IBrowserWidget s   	N(   s   __doc__s	   Interfaces   IBrowserWidget(   s	   Interfaces   IBrowserWidget(    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: ItemsWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Widget import Widget

class ItemsWidget(Widget):
    """A widget that has a number of items in it.
    """
    
    items = []



=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/LinesTextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: LinesTextAreaWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from TextAreaWidget import TextAreaWidget


class LinesTextAreaWidget(TextAreaWidget):

    default = []

    def render(self, REQUEST=None):
        value = string.join(value, "\n")
        return TextAreaWidget.render(self, REQUEST)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ListTextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: ListTextAreaWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.TextAreaWidget import TextAreaWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class ListTextAreaWidget(TextAreaWidget):
    """ListTextArea widget
    """

    __implements__ = TextAreaWidget.__implements__

    propertyNames = TextAreaWidget.propertyNames + \
                     ['extra', 'default']

    default = []
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        lines = []
        for element_text, element_value in value:
            lines.append("%s | %s" % (element_text, element_value))
        return Widget.TextAreaWidget.render(self, field, key,
                                            string.join(lines, '\n'),
                                            REQUEST)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ListWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: ListWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from SingleItemsWidget import SingleItemsWidget


class ListWidget(SingleItemsWidget):
    """List widget.
    """
    __implements__ = SingleItemsWidget.__implements__

    property_names = Widget.property_names +\
                     ['firstItem', 'items', 'size', 'extra']
    size = 5

    def render(self, REQUEST=None):

        renderedItems = self.renderItems(field, key, value, REQUEST)

        return render_element('select',
                              name='',
                              cssClass=field.get_value('cssClass'),
                              size=field.get_value('size'),
                              contents=string.join(renderedItems, "\n"),
                              extra=field.get_value('extra'))

    
    def renderItem(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value)


    def renderSelectedItem(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value,
                              selected=None)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultiItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: MultiItemsWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from ItemsWidget import ItemsWidget

        
class MultiItemsWidget(ItemsWidget):
    """A widget with a number of items that has multiple selectable
    items.
    """
    default = []
        
    def render_items(self, field, key, value, REQUEST):
        # need to deal with single item selects
        if type(value) is not type([]):
            value = [value]
        items = field.get_value('items')
        css_class = field.get_value('css_class')
        rendered_items = []
        for item in items:
            try:
                item_text, item_value = item
            except ValueError:
                item_text = item
                item_value = item

            if item_value in value:
                rendered_item = self.render_selected_item(item_text,
                                                          item_value,
                                                          key,
                                                          css_class)
            else:
                rendered_item = self.render_item(item_text,
                                                 item_value,
                                                 key,
                                                 css_class)

            rendered_items.append(rendered_item)

        return rendered_items


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultiListWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: MultiListWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from MultiItemsWidget import MultiItemsWidget


class MultiListWidget(MultiItemsWidget):
    """List widget with multiple select.
    """
    property_names = Widget.property_names +\
                     ['items', 'size', 'extra']
    
    size = 5

    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)

        return render_element('select',
                              name=key,
                              multiple=None,
                              css_class=field.get_value('css_class'),
                              size=field.get_value('size'),
                              contents=string.join(rendered_items, "\n"),
                              extra=field.get_value('extra'))
    
    def render_item(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value)

    def render_selected_item(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value,
                              selected=None)
    
MultiListWidgetInstance = MultiListWidget()


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultipleCheckBoxWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: MultipleCheckBoxWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from MultiItemsWidget import MultiItemsWidget


class MultiCheckBoxWidget(MultiItemsWidget):
    """multiple checkbox widget.
    """
    property_names = Widget.property_names +\
                     ['items', 'orientation']
    
    orientation = "vertical"
                                   
    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)
        orientation = field.get_value('orientation')
        if orientation == 'horizontal':
            return string.join(rendered_items, "&nbsp;&nbsp;")
        else:
            return string.join(rendered_items, "<br />")

        
    def render_item(self, text, value, key, css_class):
        return render_element('input',
                              type="checkbox",
                              css_class=css_class,
                              name=key,
                              value=value) + text
    

    def render_selected_item(self, text, value, key, css_class):
        return render_element('input',
                              type="checkbox",
                              css_class=css_class,
                              name=key,
                              value=value,
                              checked=None) + text


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/PasswordWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: PasswordWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from TextWidget import TextWidget


class PasswordWidget(TextWidget):
    
    def render(self, REQUEST=None):
        """Render password input field.
        """
        display_maxwidth = field.get_value('display_maxwidth') or 0
        if display_maxwidth > 0:
            return render_element("input",
                                  type="password",
                                  name=key,
                                  css_class=field.get_value('css_class'),
                                  value=value,
                                  size=field.get_value('display_width'),
                                  maxlength=display_maxwidth,
                                  extra=field.get_value('extra'))
        else:
            return render_element("input",
                                  type="password",
                                  name=key,
                                  css_class=field.get_value('css_class'),
                                  value=value,
                                  size=field.get_value('display_width'),
                                  extra=field.get_value('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/RadioWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: RadioWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from SingleItemsWidget import SingleItemsWidget


class RadioWidget(SingleItemsWidget):
    """radio buttons widget.
    """
    property_names = Widget.property_names +\
                     ['first_item', 'items', 'orientation']
    
    orientation = "vertical"
                                   
    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)
        orientation = field.get_value('orientation')
        if orientation == 'horizontal':
            return string.join(rendered_items, "&nbsp;&nbsp;")
        else:
            return string.join(rendered_items, "<br />")

        
    def render_item(self, text, value, key, css_class):
        return render_element('input',
                              type="radio",
                              css_class=css_class,
                              name=key,
                              value=value) + text
    

    def render_selected_item(self, text, value, key, css_class):
        return render_element('input',
                              type="radio",
                              css_class=css_class,
                              name=key,
                              value=value,
                              checked=None) + text
       


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/SingleItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: SingleItemsWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from ItemsWidget import ItemsWidget


class SingleItemsWidget(ItemsWidget):
    """A widget with a number of items that has only a single
    selectable item.
    """
    default = ""
    first_item = 0    


    def render_items(self, field, key, value, REQUEST):
        # get items
        items = field.get_value('items')
    
        # check if we want to select first item
        if not value and field.get_value('first_item') and len(items) > 0:
            try:
                text, value = items[0]
            except ValueError:
                value = items[0]
                
        css_class = field.get_value('css_class')
        
        # FIXME: what if we run into multiple items with same value?
        rendered_items = []
        for item in items:
            try:
                item_text, item_value = item
            except ValueError:
                item_text = item
                item_value = item

            if item_value == value:
                rendered_item = self.render_selected_item(item_text,
                                                          item_value,
                                                          key,
                                                          css_class)
            else:
                rendered_item = self.render_item(item_text,
                                                 item_value,
                                                 key,
                                                 css_class)

            rendered_items.append(rendered_item)

        return rendered_items


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: TextAreaWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class TextAreaWidget(BrowserWidget):
    """Textarea widget
    """
    propertyNames = BrowserWidget.propertyNames +\
                     ['width', 'height', 'extra']
    
    default = ""
    width = 30
    height = 6
    extra=""
    
    def render(self, REQUEST=None):
        return renderElement("textarea",
                             name=self.getContext().id,
                             css_class=self.getValue('cssClass'),
                             cols=self.getValue('width'),
                             rows=self.getValue('height'),
                             contents=self._getValueToInsert(REQUEST),
                             extra=self.getValue('extra'))



=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.pyc ===
-í
-kQ<c       sI     d  Z    d k l Z  d k l Z  d e f d „  ƒ  YZ d S(   s   

Revision information: $Id: TextAreaWidget.pyc,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
(   s
   BrowserWidget(   s
   renderElements   TextAreaWidgetc      sZ    d  Z    e i d d d g Z  d Z  d Z  d Z  d Z ! e d „ Z RS(   s   Textarea widget
    s   widths   heights   extras    i   i   c    s€   ! " t  d # d |  i ƒ  i $ d |  i d ƒ % d |  i d ƒ & d |  i d ƒ ' d	 |  i | ƒ ( d
 |  i d
 ƒ ƒSd  S(   Ns   textareas   names	   css_classs   cssClasss   colss   widths   rowss   heights   contentss   extra(   s
   renderElements   selfs
   getContexts   ids   getValues   _getValueToInserts   REQUEST(   s   selfs   REQUEST(    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.pys   render! s   	(	   s   __doc__s
   BrowserWidgets
   propertyNamess   defaults   widths   heights   extras   Nones   render(    (    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.pys   TextAreaWidget s   					N(   s   __doc__s1   Zope.App.Formulator.Widgets.Browser.BrowserWidgets
   BrowserWidgets
   renderElements   TextAreaWidget(   s
   BrowserWidgets   TextAreaWidgets
   renderElement(    (    sK   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: TextWidget.py,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class TextWidget(BrowserWidget):
    """Text widget
    """

    __implements__ = BrowserWidget.__implements__

    propertyNames = BrowserWidget.propertyNames + \
                     ['displayWidth', 'displayMaxWidth', 'extra', 'default']

    default = ''
    displayWidth = 20
    displayMaxWidth = ''
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        displayMaxWidth = self.getValue('displayMaxWidth') or 0
        if displayMaxWidth > 0:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 maxlength = displayMaxWidth,
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 extra = self.getValue('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.pyc ===
-í
Q<c       sI     d  Z    d k l Z  d k l Z  d e f d „  ƒ  YZ d S(   s   

Revision information: $Id: TextWidget.pyc,v 1.1.2.1 2002/01/25 14:11:10 srichter Exp $
(   s
   BrowserWidget(   s
   renderElements
   TextWidgetc      si    d  Z    e i Z  e i d d d d g Z  d Z   d Z ! d Z " d Z % e d „ Z	 RS(   s   Text widget
    s   displayWidths   displayMaxWidths   extras   defaults    i   c    sD  % ' ( |  i d ƒ p d } ) | d j o * t |  i d ƒ + d |  i d ƒ , d |  i ƒ  i - d |  i | ƒ . d |  i d ƒ / d |  i d	 ƒ 0 d
 | 1 d |  i d ƒ ƒSnƒ 3 t |  i d ƒ 4 d |  i d ƒ 5 d |  i ƒ  i 6 d |  i | ƒ 7 d |  i d ƒ 8 d |  i d	 ƒ 9 d |  i d ƒ ƒSd S(
   sD   Renders this widget as HTML using property values in field.
        s   displayMaxWidthi    s   tags   types   names   values   cssClasss   sizes   displayWidths	   maxlengths   extraN(   s   selfs   getValues   displayMaxWidths
   renderElements
   getContexts   ids   _getValueToInserts   REQUEST(   s   selfs   REQUESTs   displayMaxWidth(    (    sG   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.pys   render% s$   	(
   s   __doc__s
   BrowserWidgets   __implements__s
   propertyNamess   defaults   displayWidths   displayMaxWidths   extras   Nones   render(    (    (    sG   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.pys
   TextWidget s   					N(   s   __doc__s1   Zope.App.Formulator.Widgets.Browser.BrowserWidgets
   BrowserWidgets
   renderElements
   TextWidget(   s
   BrowserWidgets
   renderElements
   TextWidget(    (    sG   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/__init__.py ===


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/__init__.pyc ===
-í
‹›N<c       s     d  S(   N(    (    (    (    sE   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/__init__.pys   ?  s