[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Widgets/XUL - IXULWidget.py:1.2 TextWidget.py:1.2 XULWidget.py:1.2 __init__.py:1.2 xul.zcml:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:28:20 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Widgets/XUL
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/Formulator/Widgets/XUL
Added Files:
IXULWidget.py TextWidget.py XULWidget.py __init__.py xul.zcml
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/IXULWidget.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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$
+"""
+
+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.
+ """
+
=== Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/TextWidget.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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$
+"""
+
+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.context.id,
+ value = self._getValueToInsert(REQUEST),
+ cssClass = self.getValue('cssClass'),
+ maxlength = displayMaxWidth,
+ extra = self.getValue('extra'))
+ else:
+ return renderElement(self.getValue('tag'),
+ id = self.context.id,
+ value = self._getValueToInsert(REQUEST),
+ cssClass = self.getValue('cssClass'),
+ extra = self.getValue('extra'))
=== Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/XULWidget.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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$
+"""
+
+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.context.id, None)
+
+
+ def _getValueToInsert(self, REQUEST):
+ """ """
+ field = self.context
+ if REQUEST and (('field_'+field.id) in REQUEST):
+ 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.context.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.context.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 'cssClass' in kw:
+ if kw['cssClass'] != "":
+ attr_list.append('class="%s"' % kw['cssClass'])
+ del kw['cssClass']
+
+ # special case handling for extra 'raw' code
+ if 'extra' in kw:
+ 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 'contents' in kw:
+ contents = kw['contents']
+ del kw['contents']
+ return "%s>%s</%s>" % (apply(renderTag, (tag,), kw), contents, tag)
+ else:
+ return apply(renderTag, (tag,), kw) + " />"
=== Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
=== Zope3/lib/python/Zope/App/Formulator/Widgets/XUL/xul.zcml 1.1 => 1.2 ===
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:security='http://namespaces.zope.org/security'
+>
+
+ <content class=".TextWidget.">
+ <security:require
+ permission="Zope.ManageContent"
+ attributes="render getContext" />
+ </content>
+</zopeConfigure>