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

Garrett Smith garrett at mojave-corp.com
Sat Feb 7 21:12:27 EST 2004


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

Modified Files:
      Tag: ozzope-widgets-branch
	widget.py 
Log Message:

Created branch for widget work at ozzope sprint.


=== Zope3/src/zope/app/form/widget.py 1.10 => 1.10.4.1 ===
--- Zope3/src/zope/app/form/widget.py:1.10	Fri Jan 16 08:09:07 2004
+++ Zope3/src/zope/app/form/widget.py	Sat Feb  7 21:11:52 2004
@@ -16,35 +16,56 @@
 """
 import traceback
 from warnings import warn
+from zope.app import zapi
 from zope.app.interfaces.form import IWidget
 from zope.component.interfaces import IViewFactory
 from zope.interface import implements
 from zope.app.services.servicenames import Translation
-from zope.component import getService
 
 __metaclass__ = type
 
 class Widget:
-    """Mix-in class providing some functionality common accross view types
-    """
+    """Mixin class providing functionality common accross view types."""
+    
     implements(IWidget)
 
     _prefix = 'field.'
-    _data_marker = object()
-    _data = _data_marker
+    _data = None
+    
+    visible = True
+    propertyNames = []
 
     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):
+        ts = zapi.queryService(self.context, Translation)
+        if ts is not None:
+            # The domain is not that important here, since the title is most 
+            # likely a message id carrying the domain.
+            return (ts.translate(text, "zope", context=self.request) or text)
+        else:
+            return text
 
-    # See IWidget
-    propertyNames = []
-
+    # XXX OZ might be able to delete this
     def getValue(self, name):
-        'See IWidget'
         if name in self.propertyNames:
             return getattr(self, name, None)
+            
+    # XXX OZ might be able to delete this
+    def getProperty(self, name):
+        if traceback.extract_stack()[-2][2] != 'getProperty':
+            warn("getValue is deprecated - use getProperty",
+                DeprecationWarning, 2)
+        return self.getValue(name)
 
     def setPrefix(self, prefix):
         if not prefix.endswith("."):
@@ -52,52 +73,9 @@
         self._prefix = prefix
         self.name = prefix + self.context.__name__
 
-    def setData(self, value):
-        if traceback.extract_stack()[-2][2] != 'setRenderedValue':
-            warn("setData is deprecated - use setRenderedValue",
-                DeprecationWarning, 2)
-
-        # XXX - move this implementation to setRenderedValue when
-        # deprecation is removed
-
-        self._data = value
-
     def setRenderedValue(self, value):
-        self.setData(value)
-
-    def hasInput(self):
-        raise TypeError("hasInput has not been implemented")
-
-    def hasValidInput(self):
-        raise TypeError("hasValidInput has not been implemented")
-
-    def getInputValue(self):
-        raise TypeError("getInputValue has not been implemented")
-
-    def validate(self):
-        raise TypeError("validate has not been implemented")
-
-    def applyChanges(self, content):
-        raise TypeError("applyChanges has not been implemented")
-
-    def title(self):
-        ts = getService(self.context, Translation)
-        # Note that the domain is not that important here, since the title
-        # is most likely a message id carrying the domain anyways.
-        context_title = self.context.title
-        return (ts.translate(context_title, "zope", context=self.request)
-                or context_title)
-    title = property(title)
-
-    def description(self):
-        ts = getService(self.context, Translation)
-        # hopefully the description is a message id with domain (?).
-        context_desc = self.context.description
-        return (ts.translate(context_desc, "zope", context=self.request)
-                or context_desc)
-    description = property(description)
-
-    required = property(lambda self: self.context.required)
+        self._data = value
+        
 
 class CustomWidgetFactory:
     """Custom Widget Factory.




More information about the Zope3-Checkins mailing list