[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Widgets/XUL - IXULWidget.py:1.1.2.1 IXULWidget.pyc:1.1.2.1 TextWidget.py:1.1.2.1 TextWidget.pyc:1.1.2.1 XULWidget.py:1.1.2.1 XULWidget.pyc:1.1.2.1 __init__.py:1.1.2.1 __init__.pyc:1.1.2.1 xul.zcml:1.1.2.1

Stephan Richter srichter@cbu.edu
Fri, 1 Mar 2002 02:04:39 -0500


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

Added Files:
      Tag: srichter-OFS_Formulator-branch
	IXULWidget.py IXULWidget.pyc TextWidget.py TextWidget.pyc 
	XULWidget.py XULWidget.pyc __init__.py __init__.pyc xul.zcml 
Log Message:
Checkin for new Formualtor layout. Much has changed since the initial
checkin:


- Both classes and instances of fields can be used as factory when creating
  views.


- Field: This object is simply a meta-data container for a piece of 
  information; for content objects these are usually its properties.


  Note: It is planned to have a CompositeField for more complex inputs, 
        such as dates.


- FieldViews are virtual objects; they are basically realized Widgets (or 
  Widgets in context)


- Validator: An object that validates data. Note that this object is 
  totally input/protocol-agnostic. Therefore the old concept of some of the
  Zope 2 Formulator validators is not applicable anymore.


- Widget: This is a generic component that is concerned about the 
  presentation of a field in a particular protocol. A difference to the 
  Zope 2 Formulator version is that the widget is also responsible of
  converting possible input-specific representation to a standard one. This
  is not yet fully implemented though.


- Form: A protocol-specific object that is concerned with the overall 
  representation of a form and its action.


- There is a Validator and Field Registry, since Fields and Validators can
  also be used independent of Formulator's goals. Fields should really 
  become the standard way to provide meta-data for properties.


Todo: (too much)


- I need to write a proper metaConfigure.py.


- Make a CompositeField.


- Create XUL Widgets.


- Clean up files.


- Finishing the conversion to the Zope 3 Formulator model.


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.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
# 
##############################################################################
"""

$Id: IXULWidget.py,v 1.1.2.1 2002/03/01 07:04:37 srichter Exp $
"""

from Interface import Interface


class IXULWidget(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/XUL/IXULWidget.pyc ===
-í
[e~<c       s9     d  Z    d k l Z  d e f d „  ƒ  YZ d S(   sE   

$Id: IXULWidget.pyc,v 1.1.2.1 2002/03/01 07:04:37 srichter Exp $
(   s	   Interfaces
   IXULWidgetc      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(    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.pys   render s   c    s
   " $ d S(   s/   Renders this widget as a hidden field.
        N(    (   s   fields   keys   values   REQUEST(    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.pys
   render_hidden" s   (   s   __doc__s   renders
   render_hidden(    (    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.pys
   IXULWidget s   	N(   s   __doc__s	   Interfaces
   IXULWidget(   s	   Interfaces
   IXULWidget(    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/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
# 
##############################################################################
"""

$Id: TextWidget.py,v 1.1.2.1 2002/03/01 07:04:37 srichter Exp $
"""

from Zope.App.Formulator.Widgets.XUL.XULWidget import XULWidget
from Zope.App.Formulator.Widgets.XUL.XULWidget import renderElement


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

    __implements__ = XULWidget.__implements__

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

    tag = 'textbox'
    default = ''
    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'),
                                 id = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 maxlength = displayMaxWidth,
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 id = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 extra = self.getValue('extra'))


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

$Id: TextWidget.pyc,v 1.1.2.1 2002/03/01 07:04:37 srichter Exp $
(   s	   XULWidget(   s
   renderElements
   TextWidgetc      sf    d  Z    e i Z  e i d d d g Z  d Z   d Z ! d Z " d Z % e d „ Z	 RS(   s   Text widget
    s   displayMaxWidths   extras   defaults   textboxs    c  
  sü   % ' ( |  i d ƒ p d } ) | d j ok * t |  i d ƒ + d |  i ƒ  i , d |  i | ƒ - d |  i d ƒ . d | / d |  i d ƒ ƒSn_ 1 t |  i d ƒ 2 d |  i ƒ  i 3 d |  i | ƒ 4 d |  i d ƒ 5 d |  i d ƒ ƒSd	 S(
   sD   Renders this widget as HTML using property values in field.
        s   displayMaxWidthi    s   tags   ids   values   cssClasss	   maxlengths   extraN(   s   selfs   getValues   displayMaxWidths
   renderElements
   getContexts   ids   _getValueToInserts   REQUEST(   s   selfs   REQUESTs   displayMaxWidth(    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/TextWidget.pys   render% s   	(
   s   __doc__s	   XULWidgets   __implements__s
   propertyNamess   tags   defaults   displayMaxWidths   extras   Nones   render(    (    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/TextWidget.pys
   TextWidget s   					N(   s   __doc__s)   Zope.App.Formulator.Widgets.XUL.XULWidgets	   XULWidgets
   renderElements
   TextWidget(   s	   XULWidgets
   renderElements
   TextWidget(    (    sC   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/TextWidget.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/XULWidget.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
# 
##############################################################################
"""

$Id: XULWidget.py,v 1.1.2.1 2002/03/01 07:04:37 srichter Exp $
"""

from IXULWidget import IXULWidget
from Zope.App.Formulator.Widget import Widget
from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
from Zope.ComponentArchitecture import getAdapter


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

    __implements__ = IXULWidget

    propertyNames = Widget.propertyNames + \
                    ['tag', 'type', 'cssClass', 'hidden', 'extra']
    
    tag = ''
    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 getAdapter(field, IPropertyFieldAdapter).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['id'] = 'field_' + kw['id']

    # 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/XUL/XULWidget.pyc ===
  <Binary-ish file>

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


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/__init__.pyc ===
-í
[e~<c       s     d  S(   N(    (    (    (    sA   /opt/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/__init__.pys   ?  s    

=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/xul.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security'
>

  <security:protectClass 
    name="Zope.App.Formulator.Widgets.XUL.TextWidget."
    permission_id="Zope.ManageContent" 
    methods="render, getContext" />

</zopeConfigure>