[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/Browser - InterfaceWidget.py:1.2 __init__.py:1.2 configure.zcml:1.2

Jim Fulton jim@zope.com
Wed, 4 Dec 2002 04:54:37 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture/Browser
In directory cvs.zope.org:/tmp/cvs-serv13028/Browser

Added Files:
	InterfaceWidget.py __init__.py configure.zcml 
Log Message:
Added interface fields and widgets for keeping track of interfaces
(e.g. for adapter configurations).


=== Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/InterfaceWidget.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec  4 04:54:36 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/InterfaceWidget.py	Wed Dec  4 04:54:05 2002
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 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.
+# 
+##############################################################################
+"""These are the interfaces for the common fields.
+
+$Id$
+"""
+
+from Zope.App.Forms.Views.Browser.IBrowserWidget import IBrowserWidget
+from Zope.App.Forms.Views.Browser.Widget import BrowserWidget
+from Zope.ComponentArchitecture import getService
+from Zope.Exceptions import NotFoundError
+from Zope.Schema.Exceptions import ValidationError
+
+class SingleInterfaceWidget(BrowserWidget):    
+
+    def _convert(self, name):
+        service = getService(self.context.context, "Interfaces")
+        return service.getInterface(name)
+
+    def _unconvert(self, interface):
+        if interface is None:
+            return interface
+        return interface.__module__ + '.' + interface.__name__
+
+    def __call__(self):
+        search_name = self.name + ".search"
+        search_string = self.request.form.get(search_name, '')
+
+        service = getService(self.context.context, "Interfaces")
+        interfaces = list(service.searchInterface(search_string))
+        interfaces.sort()
+        interfaces = map(self._unconvert, interfaces)
+
+        select_name = self.name
+        selected = self._showData()
+        
+        options = ['<option value=\"\">---select interface---</option>']
+        for interface in interfaces:
+            options.append('<option value="%s"%s>%s</option>'
+                           % (interface,
+                              interface == selected and ' selected' or '',
+                              interface)
+                           )
+            
+
+        search_field = '<input type="text" name="%s" value=\"%s\">' % (
+            search_name, search_string)
+        select_field = '<select name="%s">%s</select>'  % (
+            select_name, ''.join(options))
+        
+        HTML = search_field + select_field
+        return HTML


=== Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec  4 04:54:37 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/__init__.py	Wed Dec  4 04:54:05 2002
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 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.
+# 
+##############################################################################
+"""These are the interfaces for the common fields.
+
+$Id$
+"""


=== Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec  4 04:54:37 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/Browser/configure.zcml	Wed Dec  4 04:54:05 2002
@@ -0,0 +1,14 @@
+<zopeConfigure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:browser="http://namespaces.zope.org/browser"
+>
+
+<browser:view 
+	factory = ".InterfaceWidget.SingleInterfaceWidget"
+	for = "Zope.App.ComponentArchitecture.InterfaceField.IInterfaceField"
+	name = "single"
+/>
+
+<browser:defaultView for="Zope.App.ComponentArchitecture.InterfaceField.IInterfaceField" name="single" />
+
+</zopeConfigure>