[Zope3-checkins] CVS: Zope3/src/zope/app/form - __init__.py:1.3
widget.py:NONE
Philipp von Weitershausen
philikon at philikon.de
Thu Mar 18 12:01:41 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/form
In directory cvs.zope.org:/tmp/cvs-serv22177/src/zope/app/form
Modified Files:
__init__.py
Removed Files:
widget.py
Log Message:
The zope.app.form.widget module becomes zope.app.form. This makes sense
since widgets is really the only thing this package contains and it
shortens import paths.
=== Zope3/src/zope/app/form/__init__.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/form/__init__.py:1.2 Wed Dec 25 09:12:52 2002
+++ Zope3/src/zope/app/form/__init__.py Thu Mar 18 12:01:09 2004
@@ -1,2 +1,85 @@
+##############################################################################
#
-# This file is necessary to make this directory a package.
+# 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$
+"""
+import traceback
+from warnings import warn
+from zope.app import zapi
+from zope.app.form.interfaces import IWidget
+from zope.component.interfaces import IViewFactory
+from zope.interface import implements
+from zope.i18n import translate
+
+class Widget(object):
+ """Mixin class providing functionality common accross view types."""
+
+ implements(IWidget)
+
+ _prefix = 'field.'
+ _data_marker = object()
+ _data = _data_marker
+
+ visible = True
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+ self.name = self._prefix + context.__name__
+
+ title = property(lambda self: self._translate(
+ self.context.title))
+
+ description = property(lambda self: self._translate(
+ self.context.description))
+
+ def _translate(self, text):
+ return translate(self.context, text, "zope",
+ context=self.request, default=text)
+
+ def _renderedValueSet(self):
+ """Returns True if the the widget's rendered value has been set.
+
+ This is a convenience method that widgets can use to check whether
+ or not setRenderedValue was called.
+ """
+ return self._data is not self._data_marker
+
+ def setPrefix(self, prefix):
+ if not prefix.endswith("."):
+ prefix += '.'
+ self._prefix = prefix
+ self.name = prefix + self.context.__name__
+
+ def setRenderedValue(self, value):
+ self._data = value
+
+class CustomWidgetFactory(object):
+ """Custom Widget Factory."""
+ implements(IViewFactory)
+
+ def __init__(self, *args, **kw):
+ self._widget_factory = args[0]
+ if len(args) > 1:
+ self.args = args[1:]
+ else:
+ self.args = ()
+ self.kw = kw
+
+ def __call__(self, context, request):
+ args = (context, request) + self.args
+ instance = self._widget_factory(*args)
+ for item in self.kw.items():
+ setattr(instance, item[0], item[1])
+ return instance
=== Removed File Zope3/src/zope/app/form/widget.py ===
More information about the Zope3-Checkins
mailing list