Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install z3ext.skintool

How to install z3ext.skintool

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3ext.skintool
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.2.0 Available View build log
Windows (64-bit)
1.2.0 Available View build log
Mac OS X (10.5+)
1.2.0 Available View build log
Linux (32-bit)
1.2.0 Available View build log
Linux (64-bit)
1.2.0 Available View build log
Web
 
Author
License
ZPL 2.1
Lastest release
version 1.2.0 on Jan 5th, 2011

Skin tool

Skin tool allow configure skin at runtime for each ISite object.

>>> from z3ext.skintool import interfaces, zcml
>>> from z3ext.skintool.tool import skinToolModified
>>> from zope import interface, component, schema

We need site object and request

>>> from zope.app.component.hooks import getSite
>>> site = getSite()
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()

We register skintool configlet

>>> from zope.configuration import xmlconfig
>>> context = xmlconfig.string("""
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
...    xmlns="http://namespaces.zope.org/zope" i18n_domain="z3ext">
...
...    <include package="z3ext.controlpanel" file="meta.zcml" />
...
...    <z3ext:configlet
...      name="portalskin"
...      title="Portal skin"
...      description="Portal skin configuration."
...      class="z3ext.skintool.tool.SkinTool"
...      schema="z3ext.skintool.interfaces.ISkinTool" />
...
... </configure>""")

Now let's define layer and skin

>>> from zope import interface, schema
>>> class IMySkin(interface.Interface):
...     pass
>>> class IMyLayer(interface.Interface):
...     pass

We define skin schema

>>> class IMySkinSchema(interface.Interface):
...     param1 = schema.TextLine(title=u'Param 1')

Before we can use IMySkin and IMyLayer we should register it in local registry

>>> zcml.skinDirective(IMySkin, u'myskin', u'My skin', '', (), IMySkinSchema)
>>> zcml.layerDirective(IMyLayer, u'mylayer', u'My layer', '')

Now skin and layer should be listed in vocabulary.

>>> from zope.schema.vocabulary import getVocabularyRegistry
>>> from z3ext.skintool.vocabulary import SkinsVocabulary
>>> getVocabularyRegistry().register('z3ext skins', SkinsVocabulary())
>>> voc = SkinsVocabulary()(site)
>>> term = voc.getTerm(IMySkin)
>>> term.value == u'myskin'
True
>>> term.title == 'My skin'
True
>>> term.token == u'myskin'
True
>>> from z3ext.skintool.vocabulary import LayersVocabulary
>>> getVocabularyRegistry().register('z3ext layers', LayersVocabulary())
>>> voc = LayersVocabulary()(site)
>>> term = voc.getTerm(IMyLayer)
>>> term.value == u'mylayer'
True
>>> term.title == 'My layer'
True
>>> term.token == u'mylayer'
True

All layers applied in IBeforeTraverseEvent event for ISite object. We will use handler directly.

>>> from z3ext.skintool.subscribers import threadServiceSubscriber
>>> from zope.app.publication.interfaces import BeforeTraverseEvent

Let's check layer for our request.

>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMySkin.providedBy(request)
False
>>> IMyLayer.providedBy(request)
False

This is because we should configure skin tool to use our layer and site object should implement ISkinable interface.

>>> interface.directlyProvides(site, interfaces.ISkinable)

Let's configure skin tool

>>> tool = component.getUtility(interfaces.ISkinTool)
>>> tool.skin = u'myskin'
>>> tool.layers = [u'mylayer']
>>> skinToolModified()

Let's try again

>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMySkin.providedBy(request)
True
>>> IMyLayer.providedBy(request)
True

We have skin configuration data:

>>> tool.skinData
<z3ext.skintool.skindatatype.SkinData<ui.portalskin.skindata> ...>

And default attributes:

>>> tool.skinData.param1

Change layers config

>>> tool.layers = []
>>> skinToolModified()
>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMyLayer.providedBy(request)
False

Skin can depends on other layers

>>> class IMySkin2(interface.Interface):
...     pass
>>> zcml.skinDirective(IMySkin2, u'myskin2', u'My skin2', '', (IMyLayer,))
>>> tool.skin = u'myskin2'
>>> skinToolModified()
>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMySkin2.providedBy(request)
True
>>> IMyLayer.providedBy(request)
True

We can define default layer, that will added automaticly

>>> class IDefaultLayer(interface.Interface):
...     pass

We have to register utility IDefaultLayer

>>> component.provideUtility(IDefaultLayer, interfaces.IDefaultLayer, 'default')
>>> tool.layers = [u'mylayer']
>>> skinToolModified()
>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMyLayer.providedBy(request)
True
>>> IDefaultLayer.providedBy(request)
True
z3ext:layer directive

We can do same with z3ext:layer directive. We need load zcml file:

>>> import z3ext.skintool
>>> from zope.configuration import xmlconfig
>>> context = xmlconfig.file('meta.zcml', z3ext.skintool)
>>> context = xmlconfig.string("""
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
...    xmlns="http://namespaces.zope.org/zope" i18n_domain="z3ext">
...  <z3ext:layer
...    name="mylayer3"
...    layer="z3ext.skintool.README.IMyLayer"
...    title="My zcml layer" />
... </configure>""", context)
>>> voc = LayersVocabulary()(site)
>>> term = voc.getTerm(IMyLayer)
>>> term.value == u'mylayer3'
True
>>> term.title == 'My zcml layer'
True
>>> term.token == u'mylayer3'
True
>>> tool.user_layers = ['mylayer3']
>>> skinToolModified()
>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMyLayer.providedBy(request)
True
>>> context = xmlconfig.string("""
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
...    xmlns="http://namespaces.zope.org/zope" i18n_domain="z3ext">
...  <z3ext:skin
...    name="myskin4"
...    layer="z3ext.skintool.README.IMySkin2"
...    title="My zcml skin4"
...    require="z3ext.skintool.README.IMyLayer" />
... </configure>""", context)
>>> tool.skin = u'myskin4'
>>> skinToolModified()
>>> threadServiceSubscriber(site, BeforeTraverseEvent(site, request))
>>> IMySkin2.providedBy(request)
True
>>> IMyLayer.providedBy(request)
True

CHANGES

1.2.0 (2009-08-11)
  • Added skin configurable schema
  • Change copyright holder
  • Check is skin exists, if not use z3ext as default
  • Do not use z3c.autoinclude
1.1.2 (2009-01-26)
  • Use custom fields for schema
1.1.1 (2008-12-03)
  • Do not use _v_skin attribute
1.1.0 (2008-11-21)
  • Added z3ext:skin directive
  • API refactored
  • Added translations: nl, ru
1.0.2 (2008-08-07)
  • Added INoSkinSwitching for skin that does not allow skin switching
1.0.1 (2008-05-16)
  • Replace 'autoinclude' with 'includeDependendcies'
1.0.0 (2008-03-28)
  • Code cleanup
  • Added tests
  • Code moved to svn.zope.org
0.13 (2008-02-28)

System Message: WARNING/2 (<string>, line 289)

Title underline too short.

0.13 (2008-02-28)
----------------
  • Use z3c.autoinclude
  • Do not generate InterfaceClass object, just apply list of layers
0.12 (2008-02-08)
  • Code cleanup
0.11 (2008-02-06)
  • Added ISkinable marker interface.

System Message: WARNING/2 (<string>, line 306)

Bullet list ends without a blank line; unexpected unindent.

Now object should implement ISkinable implicitly to support skintool

0.10 (2008-02-01)
  • Initial release.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.