[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - widget.py:1.29.4.7

Fred L. Drake, Jr. fred@zope.com
Mon, 12 May 2003 13:08:24 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv7420

Modified Files:
      Tag: schema-vocabulary-branch
	widget.py 
Log Message:
Loading these from ZCML requires the factory functions to be classes
(since dynamic mixing is used); using classes that override __new__()
allows us to do what's needed without lots of changes in the
machinery.


=== Zope3/src/zope/app/browser/form/widget.py 1.29.4.6 => 1.29.4.7 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.29.4.6	Tue May  6 12:17:19 2003
+++ Zope3/src/zope/app/browser/form/widget.py	Mon May 12 13:08:24 2003
@@ -695,31 +695,38 @@
                               checked = None) + text
 
 
-# These widget factories delegate to 
+# These widget factories delegate to the vocabulary on the field.
+# These are required to be classes by the painful implementation of the
+# browser:page ZCML directive; we use __new__() so we can do the right
+# thing.
 
-def VocabularyFieldDisplayWidget(field, request):
-    """Return a display widget based on a vocabulary field."""
-    view = getView(field.vocabulary, "field-display-widget", request)
-    view.setField(field)
-    return view
+class VocabularyFieldDisplayWidget:
+    def __new__(cls, field, request):
+        """Return a display widget based on a vocabulary field."""
+        view = getView(field.vocabulary, "field-display-widget", request)
+        view.setField(field)
+        return view
 
-def VocabularyFieldEditWidget(field, request):
-    """Return a value-selection widget based on a vocabulary field."""
-    view = getView(field.vocabulary, "field-edit-widget", request)
-    view.setField(field)
-    return view
+class VocabularyFieldEditWidget:
+    def __new__(cls, field, request):
+        """Return a value-selection widget based on a vocabulary field."""
+        view = getView(field.vocabulary, "field-edit-widget", request)
+        view.setField(field)
+        return view
 
-def VocabularyMultiFieldDisplayWidget(field, request):
-    """Return a display widget based on a vocabulary field."""
-    view = getView(field.vocabulary, "field-display-multi-widget", request)
-    view.setField(field)
-    return view
+class VocabularyMultiFieldDisplayWidget:
+    def __new__(cls, field, request):
+        """Return a display widget based on a vocabulary field."""
+        view = getView(field.vocabulary, "field-display-multi-widget", request)
+        view.setField(field)
+        return view
 
-def VocabularyMultiFieldEditWidget(field, request):
-    """Return a value-selection widget based on a vocabulary field."""
-    view = getView(field.vocabulary, "field-edit-multi-widget", request)
-    view.setField(field)
-    return view
+class VocabularyMultiFieldEditWidget:
+    def __new__(cls, field, request):
+        """Return a value-selection widget based on a vocabulary field."""
+        view = getView(field.vocabulary, "field-edit-multi-widget", request)
+        view.setField(field)
+        return view
 
 
 class VocabularyWidgetBase(BrowserWidget):