[Zope3-checkins] CVS: Zope3/src/zope/app/browser/component - __init__.py:1.2 configure.zcml:1.2 interfacewidget.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:59 -0500


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

Added Files:
	__init__.py configure.zcml interfacewidget.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/browser/component/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/component/__init__.py	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/component/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/component/configure.zcml	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,18 @@
+<zopeConfigure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:browser="http://namespaces.zope.org/browser"
+>
+
+<browser:view 
+	factory = ".interfacewidget.SingleInterfaceWidget"
+	for = "zope.app.interfaces.component.interfacefield.IInterfaceField"
+	name = "edit"
+        />
+
+<browser:view 
+	factory = ".interfacewidget.DisplayWidget"
+	for = "zope.app.interfaces.component.interfacefield.IInterfaceField"
+	name = "display"
+        />
+
+</zopeConfigure>


=== Zope3/src/zope/app/browser/component/interfacewidget.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:59 2002
+++ Zope3/src/zope/app/browser/component/interfacewidget.py	Wed Dec 25 09:12:28 2002
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# 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.interface import Interface
+from zope.app.interfaces.browser.form import IBrowserWidget
+from zope.app.browser.form.widget import BrowserWidget, DisplayWidget
+from zope.component import getService
+from zope.exceptions import NotFoundError
+from zope.schema.interfaces import ValidationError
+
+class BaseWidget:
+
+    def _convert(self, name):
+        if not name:
+            return None
+        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__
+
+class SingleInterfaceWidget(BaseWidget, BrowserWidget):
+
+    def __call__(self):
+        search_name = self.name + ".search"
+        search_string = self.request.form.get(search_name, '')
+
+        field = self.context
+        service = getService(field.context, "Interfaces")
+        base = field.type
+        if base == Interface:
+            base=None
+        interfaces = list(service.searchInterface(search_string, base=base))
+        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
+
+class DisplayWidget(BaseWidget, DisplayWidget):
+    pass