Author: jmorliaguet Date: Wed Apr 5 15:08:28 2006 New Revision: 2782 Added: cpsskins/branches/jmo-perspectives/profiles/default/color.xml (contents, props changed) cpsskins/branches/jmo-perspectives/standard/fields/ cpsskins/branches/jmo-perspectives/standard/fields/__init__.py (contents, props changed) cpsskins/branches/jmo-perspectives/standard/fields/color.py (contents, props changed) cpsskins/branches/jmo-perspectives/standard/fields/color.zcml (contents, props changed) cpsskins/branches/jmo-perspectives/standard/fields/configure.zcml (contents, props changed) cpsskins/branches/jmo-perspectives/standard/io/color.py (contents, props changed) cpsskins/branches/jmo-perspectives/standard/io/color.xml (contents, props changed) cpsskins/branches/jmo-perspectives/standard/io/color.zcml (contents, props changed) Removed: cpsskins/branches/jmo-perspectives/ftests/test_io.py cpsskins/branches/jmo-perspectives/standard/io/README.txt Modified: cpsskins/branches/jmo-perspectives/configuration/__init__.py cpsskins/branches/jmo-perspectives/configuration/meta.zcml cpsskins/branches/jmo-perspectives/elements/configure.zcml cpsskins/branches/jmo-perspectives/elements/interfaces.py cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py cpsskins/branches/jmo-perspectives/profiles/default/__init__.py cpsskins/branches/jmo-perspectives/setup/README.txt cpsskins/branches/jmo-perspectives/setup/configure.zcml cpsskins/branches/jmo-perspectives/standard/configure.zcml cpsskins/branches/jmo-perspectives/standard/io/configure.zcml cpsskins/branches/jmo-perspectives/ui/panels/settings.pt Log:
- added a "field" resource type - added a "Color" field (for storing colors) Modified: cpsskins/branches/jmo-perspectives/configuration/__init__.py ============================================================================== --- cpsskins/branches/jmo-perspectives/configuration/__init__.py (original) +++ cpsskins/branches/jmo-perspectives/configuration/__init__.py Wed Apr 5 15:08:28 2006 @@ -20,6 +20,7 @@ from cpsskins.configuration.displays.display import IDisplay, Display from cpsskins.configuration.engines.engine import IEngine, Engine from cpsskins.configuration.filters.filter import IFilter, Filter +from cpsskins.configuration.fields.field import IField, Field from cpsskins.configuration.presentations.presentation import ( IPresentation, Presentation) from cpsskins.configuration.renderers.renderer import IRenderer, Renderer Modified: cpsskins/branches/jmo-perspectives/configuration/meta.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/configuration/meta.zcml (original) +++ cpsskins/branches/jmo-perspectives/configuration/meta.zcml Wed Apr 5 15:08:28 2006 @@ -16,6 +16,8 @@ <include package=".formats" file="meta.zcml" /> + <include package=".fields" file="meta.zcml" /> + <include package=".widgets" file="meta.zcml" /> <include package=".storages" file="meta.zcml" /> Modified: cpsskins/branches/jmo-perspectives/elements/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/elements/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/elements/configure.zcml Wed Apr 5 15:08:28 2006 @@ -99,6 +99,12 @@ type=".interfaces.IElementType" /> + <!-- Fields --> + + <interface + interface=".interfaces.IField" + type=".interfaces.IElementType" + /> <!-- this adapter makes elements presentable --> Modified: cpsskins/branches/jmo-perspectives/elements/interfaces.py ============================================================================== --- cpsskins/branches/jmo-perspectives/elements/interfaces.py (original) +++ cpsskins/branches/jmo-perspectives/elements/interfaces.py Wed Apr 5 15:08:28 2006 @@ -85,6 +85,11 @@ IDisplay.setTaggedValue('name', u'display') +class IField(IElement): + """A field element""" + +IField.setTaggedValue('name', u'field') + class IDisplayable(Interface): def getDisplay(perspective, default): Modified: cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py ============================================================================== --- cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py (original) +++ cpsskins/branches/jmo-perspectives/ftests/test_appsetup.py Wed Apr 5 15:08:28 2006 @@ -27,13 +27,23 @@ from zope.component import provideUtility from zope.component.interfaces import IFactory -from cpsskins.setup.interfaces import IResourceType, IDataImporter +from cpsskins import elements +from cpsskins.elements.interfaces import IElement, IIdentifiable, IType +from cpsskins.setup.interfaces import IResourceType +from cpsskins.setup.interfaces import IDataImporter, IDataExporter from cpsskins.setup.test.dummy import IDummyResource, DummyResourceImporter from cpsskins.setup.test.dummy import DummyFactory + def setUp(test): - # export adapter + # export adapters ztapi.provideAdapter(IDummyResource, IDataImporter, DummyResourceImporter) + ztapi.provideAdapter(IDummyResource, IIdentifiable, + elements.element.Identifiable) + + from cpsskins.standard.io import element + ztapi.browserViewProviding(IElement, element.Exporter, IDataExporter) + ztapi.provideAdapter(IElement, IDataImporter, element.Importer) # register the setting provideUtility(DummyFactory, IFactory, 'dummy') Modified: cpsskins/branches/jmo-perspectives/profiles/default/__init__.py ============================================================================== --- cpsskins/branches/jmo-perspectives/profiles/default/__init__.py (original) +++ cpsskins/branches/jmo-perspectives/profiles/default/__init__.py Wed Apr 5 15:08:28 2006 @@ -20,3 +20,4 @@ from cpsskins.setup.registration import register register('cpsskins.profiles.default', 'perspectives.xml') +register('cpsskins.profiles.default', 'color.xml') Added: cpsskins/branches/jmo-perspectives/profiles/default/color.xml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/profiles/default/color.xml Wed Apr 5 15:08:28 2006 @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8" ?> +<settings> + <setting name="redcolor" title="Red color"> + <color value="#ff0000" /> + </setting> + <setting name="greencolor" title="Green color"> + <color value="#00ff00" /> + </setting> +</settings> Modified: cpsskins/branches/jmo-perspectives/setup/README.txt ============================================================================== --- cpsskins/branches/jmo-perspectives/setup/README.txt (original) +++ cpsskins/branches/jmo-perspectives/setup/README.txt Wed Apr 5 15:08:28 2006 @@ -275,3 +275,251 @@ In that case the file's modification date is compared with the date when the settings were last loaded. + + +=============== +IMPORT / EXPORT +=============== + +This package contains XML exporters and importers. + +To be exported and imported, resources must be uniformally identifiable. + +Their name is obtained by combining element type, resource type and content +type names. Finally the resource's own identifier is used. + + +Classification of resources +=========================== + +Resources are classified according to their "element type", "resource type" +and "content type". + + +1) Element types +---------------- + +Element types provide a first-level categorization of resources: + +- 'canvas' (contains all elements that can be put on the canvas) + +- 'display' (contains all elements that can be displayed) + +- 'format' (contains all elements that can be formatted) + +- 'engine' + +- 'filter' + +- 'palette' + +- 'perspective' + +- 'relation' + + +The element type of a given resource is obtained by querying the resource's +IElementType. + + >>> from zope.app.testing import ztapi + >>> from zope.app.interface import queryType + + >>> from cpsskins.elements.interfaces import IElementType + >>> from cpsskins.elements.theme import Theme + + >>> resource = Theme() + >>> element_type = queryType(resource, IElementType) + >>> element_type.getTaggedValue('name') + u'canvas' + +or more succintly: + + >>> from cpsskins.elements.interfaces import IType + >>> IType(resource).elementname + u'canvas' + + +2) Resource types +----------------- + +Resource types provide a second-level categorization of resources. + +- 'box', 'area', 'boxgroup' (display elements) + +- 'widget', 'style', 'effect', 'layout' (format elements) + +- 'portlet', 'cell', 'slot' (canvas element) + +- 'color' (palette element) + +The resource type of a given resource is obtained by querying the resource's +IResourceType. + + >>> from cpsskins.setup.interfaces import IResourceType + >>> from cpsskins.standard.formats.style import Style + + >>> resource = Style() + >>> resource_type = queryType(resource, IResourceType) + >>> resource_type.getTaggedValue('name') + u'style' + +or: + + >>> IType(resource).resourcename + u'style' + + +3) Content types +---------------- + +Content types provide a third-level categorization of resources. + +Typically they are used to identify third-party resources when the element +type and the resource type are not specific enough. + +- 'cpsskins.actions', 'cpsskins.breadcrumbs', ... + +The content type is identical to the resource type for resources that have no +third-level type of categorization (i.e. perpective, theme, ...) + +The content type of a given resource is obtained by querying the resource's +IContentType. + + >>> from zope.app.content.interfaces import IContentType + >>> from cpsskins.standard.portlets.actions.portlet import Actions + + >>> resource = Actions() + >>> content_type = queryType(resource, IContentType) + >>> content_type.getTaggedValue('name') + 'cpsskins.actions' + +or: + + >>> IType(resource).contentname + 'cpsskins.actions' + + +URI +--- + +To identify resources, a URI (Uniform Resource Identifier) is used. +A URI consists of a combination of the element type, resource type and content +type separated with a '-' sign. + +The last part of the URI is the element's identifier as it is used in a +relation (cf. cpsskins.relations.interfaces.IRelatable). + + >>> from cpsskins.relations.interfaces import IRelatable + >>> from cpsskins.elements.interfaces import IElement + + >>> class Relatable(object): + ... def __init__(self, element): + ... self.element = element + ... def __str__(self): + ... return '12345' + + >>> ztapi.provideAdapter(IElement, IRelatable, Relatable) + + >>> resource = Style() + >>> unicode(IRelatable(resource)) + u'12345' + +For instance a portlet will be uniformally identified as: + + >>> from cpsskins.elements.interfaces import IIdentifiable + >>> resource = Actions() + + >>> IIdentifiable(resource).getURI() + u'canvas-portlet-cpsskins.actions-12345' + +If the resource type is the same as the content type, the name is written only +once: + + >>> resource = Style() + >>> IIdentifiable(resource).getURI() + u'format-style-12345' + + +Export of resources +=================== + +Resources can be exported using the IDataExporter adapter. + + >>> from zope.publisher.browser import TestRequest + >>> from zope.component import getMultiAdapter + >>> request = TestRequest() + + >>> from cpsskins.setup.interfaces import IDataExporter, IDataImporter + +Export of styles +---------------- + + >>> resource = Style() + >>> resource[u'div.body'] = {'color': u'red', 'border': u'none'} + >>> exporter = getMultiAdapter((resource, request), IDataExporter) + + >>> print exporter() + <?xml version="1.0"?> + <style uri="format-style-12345"> + <selector name="div.body"> + <property name="color" value="red"/> + <property name="border" value="none"/> + </selector> + </style> + <BLANKLINE> + + +Export of relations +------------------- + + >>> from cpsskins.relations import TestRelate, Predicate + + >>> from cpsskins.relations import MonadicRelation + >>> resource = MonadicRelation(predicate=Predicate(u'_ A'), + ... first=TestRelate(u'first')) + + >>> exporter = getMultiAdapter((resource, request), IDataExporter) + + +Export of elements +------------------ + + >>> from cpsskins.elements.cell import Cell + >>> resource = Cell(u'Some cell') + + >>> exporter = getMultiAdapter((resource, request), IDataExporter) + >>> print exporter() + <?xml version="1.0"?> + <element uri="canvas-cell-12345" title="Some cell"/> + <BLANKLINE> + + +Export of container elements +---------------------------- + + >>> from cpsskins.tests.setup import addThemeManager, addThemeSkeleton + >>> root = getRootFolder() + >>> theme = addThemeSkeleton(tmutil) + + >>> exporter = getMultiAdapter((theme, request), IDataExporter) + + to finish + + +Accessing resources +=================== + +Resources can be used instead of setting + + >>> from cpsskins.standard.fields.color import Color + + >>> color = Color(r=255, g=0, b=0) + >>> root[u'color'] = color + >>> print color + #ff0000 + + >>> IIdentifiable(color).getURI() + + + >>> resource = Style() + >>> resource[u'div.body'] = {'color': u'resource://color-red'} Modified: cpsskins/branches/jmo-perspectives/setup/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/setup/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/setup/configure.zcml Wed Apr 5 15:08:28 2006 @@ -2,6 +2,7 @@ xmlns="http://namespaces.zope.org/zope" xmlns:i18n="http://namespaces.zope.org/i18n" xmlns:zcml="http://namespaces.zope.org/zcml" + xmlns:cpsskins="http://namespaces.zope.org/cpsskins" i18n_domain="cpsskins" > Modified: cpsskins/branches/jmo-perspectives/standard/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/standard/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/standard/configure.zcml Wed Apr 5 15:08:28 2006 @@ -40,4 +40,9 @@ <include package=".ds" /> + + <!-- Standard fields --> + + <include package=".fields" /> + </configure> Added: cpsskins/branches/jmo-perspectives/standard/fields/__init__.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/fields/__init__.py Wed Apr 5 15:08:28 2006 @@ -0,0 +1,19 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + Added: cpsskins/branches/jmo-perspectives/standard/fields/color.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/fields/color.py Wed Apr 5 15:08:28 2006 @@ -0,0 +1,60 @@ +############################################################################## +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from persistent import Persistent + +from zope.component.factory import Factory +from zope.interface import implements, Interface + +from cpsskins.elements import Element +from cpsskins.elements.interfaces import IField + +class IColor(IField): + """A web color.""" + + def hex(): + """HEX representation: #fcfcfc + """ + + def rgb(): + """RBG representation: rgb(123, 255, 200) + """ + +IColor.setTaggedValue('name', u'color') + +class Color(Persistent, Element): + """A web color with red, green and blue components (0-255) + """ + implements(IColor) + + def __init__(self, r=0, g=0, b=0): + self.color = r, g, b + + def __str__(self): + return self.hex() + + def hex(self): + return "#%0.2x%0.2x%0.2x" % self.color + + def rgb(self): + return "rgb(%s,%s,%s)" % self.color + +ColorFactory = Factory(Color, "Color Factory", + "A Factory that creates colors") + Added: cpsskins/branches/jmo-perspectives/standard/fields/color.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/fields/color.zcml Wed Apr 5 15:08:28 2006 @@ -0,0 +1,18 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:cpsskins="http://namespaces.zope.org/cpsskins"> + + <!-- Field --> + <cpsskins:field + name="color" + schema=".color.IColor" + factory=".color.ColorFactory" + /> + + <cpsskins:setting + name="color" + schema=".color.IColor" + factory=".color.ColorFactory" + /> + +</configure> Added: cpsskins/branches/jmo-perspectives/standard/fields/configure.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/fields/configure.zcml Wed Apr 5 15:08:28 2006 @@ -0,0 +1,7 @@ +<configure + xmlns="http://namespaces.zope.org/zope"> + + <!-- Color --> + <include file="color.zcml" /> + +</configure> Added: cpsskins/branches/jmo-perspectives/standard/io/color.py ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/io/color.py Wed Apr 5 15:08:28 2006 @@ -0,0 +1,55 @@ +############################################################################ +# +# Copyright (c) 2005-2006 Nuxeo and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +""" + +$Id$ +""" +__docformat__ = "reStructuredText" + +from xml.dom.minidom import parseString + +from zope.app import pagetemplate +from zope.component import adapts +from zope.interface import implements + +from cpsskins.standard.fields.color import IColor +from cpsskins.setup.interfaces import IDataExporter, IDataImporter + +class Exporter(object): + """Export a color. + """ + implements(IDataExporter) + + template = pagetemplate.ViewPageTemplateFile('color.xml') + + def __call__(self): + return self.template() + +class Importer(object): + """Import a color. + """ + adapts(IColor) + implements(IDataImporter) + + def __init__(self, context): + self.context = context + + def load(self, xml=u''): + context = self.context + dom = parseString(xml) + colors = dom.getElementsByTagName('color') + if colors: + color = colors[0] + context.value = color.getAttribute('value') + Added: cpsskins/branches/jmo-perspectives/standard/io/color.xml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/io/color.xml Wed Apr 5 15:08:28 2006 @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<color xmlns:tal="http://xml.zope.org/namespaces/tal" + tal:attributes="value context/value" +/> Added: cpsskins/branches/jmo-perspectives/standard/io/color.zcml ============================================================================== --- (empty file) +++ cpsskins/branches/jmo-perspectives/standard/io/color.zcml Wed Apr 5 15:08:28 2006 @@ -0,0 +1,18 @@ +<configure + xmlns="http://namespaces.zope.org/zope" + xmlns:browser="http://namespaces.zope.org/browser"> + + <!-- XML export --> + <browser:view + provides="cpsskins.setup.interfaces.IDataExporter" + for="cpsskins.standard.fields.color.IColor" + class=".color.Exporter" + permission="zope.ManageContent" + /> + + <!-- XML import --> + <adapter + factory=".color.Importer" + /> + +</configure> Modified: cpsskins/branches/jmo-perspectives/standard/io/configure.zcml ============================================================================== --- cpsskins/branches/jmo-perspectives/standard/io/configure.zcml (original) +++ cpsskins/branches/jmo-perspectives/standard/io/configure.zcml Wed Apr 5 15:08:28 2006 @@ -7,4 +7,6 @@ <include file="style.zcml" /> + <include file="color.zcml" /> + </configure> Modified: cpsskins/branches/jmo-perspectives/ui/panels/settings.pt ============================================================================== --- cpsskins/branches/jmo-perspectives/ui/panels/settings.pt (original) +++ cpsskins/branches/jmo-perspectives/ui/panels/settings.pt Wed Apr 5 15:08:28 2006 @@ -8,7 +8,7 @@ src="/++skin++cpsskins/@@/++resource++settings-48.png" /> <span class="description">manage settings ...</span> <ul> - <li tal:repeat="section python: ['perspective', 'style']"> + <li tal:repeat="section python: ['perspective', 'style', 'color']"> <a class="section" tal:attributes="href string:javascript:CPSSkins.getModelById('settings-section').setData({'url': '@@settings-section.html?section=$section'})" tal:content="section">SECTION</a></li> </ul> <br style="clear:both"/> -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins