[Checkins] SVN: z3c.form/trunk/ Added widget events.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Jul 6 17:13:42 EDT 2007


Log message for revision 77536:
  Added widget events.
  

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/src/z3c/form/field.py
  U   z3c.form/trunk/src/z3c/form/interfaces.py
  U   z3c.form/trunk/src/z3c/form/widget.py

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2007-07-06 21:12:56 UTC (rev 77535)
+++ z3c.form/trunk/CHANGES.txt	2007-07-06 21:13:41 UTC (rev 77536)
@@ -5,6 +5,9 @@
 Version 1.5.0 (??/??/2007)
 -------------------------
 
+- Feature: Added the concept of widget events and implemented a particular
+  "after widget update" event that is called right after a widget is updated.
+
 - Feature: Restructured the approach to customize button actions, by requiring
   the adapter to provide a new interface ``IButtonAction``. Also, an adapter
   is now provided by default, still allowing cusotmization using the usual

Modified: z3c.form/trunk/src/z3c/form/field.py
===================================================================
--- z3c.form/trunk/src/z3c/form/field.py	2007-07-06 21:12:56 UTC (rev 77535)
+++ z3c.form/trunk/src/z3c/form/field.py	2007-07-06 21:13:41 UTC (rev 77536)
@@ -22,6 +22,7 @@
 import zope.schema.interfaces
 
 from z3c.form import interfaces, util
+from z3c.form.widget import AfterWidgetUpdateEvent
 
 
 def _initkw(keepReadOnly=(), omitReadOnly=False, **defaults):
@@ -253,6 +254,7 @@
             widget.mode = mode
             # Step 8: Update the widget
             widget.update()
+            zope.event.notify(AfterWidgetUpdateEvent(widget))
             # Step 9: Add the widget to the manager
             self._data_keys.append(shortName)
             self._data_values.append(widget)

Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py	2007-07-06 21:12:56 UTC (rev 77535)
+++ z3c.form/trunk/src/z3c/form/interfaces.py	2007-07-06 21:13:41 UTC (rev 77536)
@@ -746,3 +746,18 @@
         description=(u'Initially a collection of group classes, which are '
                      u'converted to group instances when the form is '
                      u'updated.'))
+
+
+# ----[ Events ]--------------------------------------------------------------
+
+
+class IWidgetEvent(zope.interface.Interface):
+    """A simple widget event."""
+
+    widget = zope.schema.Object(
+        title=_('Widget'),
+        description=_('The widget for which the event was created.'),
+        schema=IWidget)
+
+class IAfterWidgetUpdateEvent(IWidgetEvent):
+    """An event sent out after the widget was updated."""

Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py	2007-07-06 21:12:56 UTC (rev 77535)
+++ z3c.form/trunk/src/z3c/form/widget.py	2007-07-06 21:13:41 UTC (rev 77536)
@@ -228,3 +228,16 @@
 
     def __call__(self, context, request, view, field, widget):
         return self.template
+
+
+class WidgetEvent(object):
+    zope.interface.implements(interfaces.IWidgetEvent)
+
+    def __init__(self, widget):
+        self.widget = widget
+
+    def __repr__(self):
+        return '<%s %r>' %(self.__class__.__name__, self.widget)
+
+class AfterWidgetUpdateEvent(WidgetEvent):
+    zope.interface.implementsOnly(interfaces.IAfterWidgetUpdateEvent)



More information about the Checkins mailing list