[Zope3-checkins] SVN: Zope3/trunk/ - added ISkinChangedEvent to allow applications to notice when the skin of a

Christian Theune ct at gocept.com
Mon Oct 23 17:06:11 EDT 2006


Log message for revision 70896:
   - added ISkinChangedEvent to allow applications to notice when the skin of a
     request was changed
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/publisher/browser.py
  U   Zope3/trunk/src/zope/publisher/interfaces/browser.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-10-23 20:36:53 UTC (rev 70895)
+++ Zope3/trunk/doc/CHANGES.txt	2006-10-23 21:06:10 UTC (rev 70896)
@@ -10,6 +10,9 @@
 
     New features
 
+      - Added ISkinChangedEvent to applySkin() function. This event is
+        triggered whenever the skin of a request is changed.
+
       - Make the `label` and `hint` properties of the base Widget class
         read/write, and document in the interface that the implementation
         may or may not allow updating these properties.

Modified: Zope3/trunk/src/zope/publisher/browser.py
===================================================================
--- Zope3/trunk/src/zope/publisher/browser.py	2006-10-23 20:36:53 UTC (rev 70895)
+++ Zope3/trunk/src/zope/publisher/browser.py	2006-10-23 21:06:10 UTC (rev 70896)
@@ -39,6 +39,7 @@
 from zope.publisher.interfaces.browser import IBrowserView
 from zope.publisher.interfaces.browser import IBrowserPage
 from zope.publisher.interfaces.browser import IBrowserSkinType
+from zope.publisher.interfaces.browser import ISkinChangedEvent
 from zope.publisher.interfaces.http import IHTTPRequest
 from zope.publisher.http import HTTPRequest, HTTPResponse
 
@@ -977,6 +978,22 @@
     >>> pprint.pprint(list(providedBy(req).interfaces()))
     [<InterfaceClass zope.publisher.browser.SkinB>,
      <InterfaceClass zope.publisher.browser.IRequest>]
+
+    Changing the skin on a request triggers the ISkinChanged event:
+
+    >>> import zope.component
+    >>> from zope.publisher.interfaces.browser import ISkinChangedEvent
+    >>> def receiveSkinEvent(event):
+    ...     print event.request
+    >>> zope.component.provideHandler(receiveSkinEvent, (ISkinChangedEvent,))
+    >>> applySkin(req, SkinA)   # doctest: +ELLIPSIS
+    <zope.publisher.browser.Request object at 0x...>
+
+    Make sure our registrations go away again.
+
+    >>> from zope.testing.cleanup import cleanUp
+    >>> cleanUp()
+
     """
     # Remove all existing skin declarations (commonly the default skin).
     ifaces = [iface for iface in directlyProvidedBy(request)
@@ -984,3 +1001,11 @@
     # Add the new skin.
     ifaces.append(skin)
     directlyProvides(request, *ifaces)
+    zope.event.notify(SkinChangedEvent(request))
+
+class SkinChangedEvent(object):
+
+    zope.interface.implements(ISkinChangedEvent)
+
+    def __init__(self, request):
+        self.request = request

Modified: Zope3/trunk/src/zope/publisher/interfaces/browser.py
===================================================================
--- Zope3/trunk/src/zope/publisher/interfaces/browser.py	2006-10-23 20:36:53 UTC (rev 70895)
+++ Zope3/trunk/src/zope/publisher/interfaces/browser.py	2006-10-23 21:06:10 UTC (rev 70896)
@@ -145,3 +145,8 @@
     This is a marker interface, so that we can register the default skin as an
     adapter from the presentation type to `IDefaultSkin`.
     """
+
+class ISkinChangedEvent(Interface):
+    """Event that gets triggered when the skin of a request is changed."""
+
+    request = Attribute("The request for which the skin was changed.")



More information about the Zope3-Checkins mailing list