Author: jmorliaguet
Date: Wed Dec  7 17:06:17 2005
New Revision: 1978

Modified:
   cpsskins/branches/jmo-perspectives/configuration/settings/metaconfigure.py
   cpsskins/branches/jmo-perspectives/configuration/settings/metadirectives.py
   cpsskins/branches/jmo-perspectives/perspectives/configure.zcml
   cpsskins/branches/jmo-perspectives/perspectives/perspective.py
   cpsskins/branches/jmo-perspectives/setup/setting.py
Log:

- we register setting *factories* using zcml

  individual setting *instances* will be registered using some XML import



Modified: 
cpsskins/branches/jmo-perspectives/configuration/settings/metaconfigure.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/configuration/settings/metaconfigure.py  
(original)
+++ cpsskins/branches/jmo-perspectives/configuration/settings/metaconfigure.py  
Wed Dec  7 17:06:17 2005
@@ -17,34 +17,46 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.component import queryUtility
-from zope.component.interfaces import IFactory
+from zope.component import queryUtility, provideUtility
 from zope.configuration.exceptions import ConfigurationError
+from zope.component.interfaces import IFactory
+from zope.interface import alsoProvides
+
+from cpsskins.setup.interfaces import ISetting, IResourceType
 
-from cpsskins.setup.interfaces import ISetting
-from cpsskins.setup.interfaces import IResourceImporter, IResourceManager
+def setting(_context, name=u'', schema=None, factory=None):
 
-def setting(_context, name=u'', factory=None, resource=None):
+    if not name:
+        raise ConfigurationError("Must provide a setting name.")
 
     if queryUtility(ISetting, name) is not None:
         raise ConfigurationError(
-            "The '%s' setting has already been registered." % name)
+            "The '%s' setting directive has already been registered." % name)
 
     if not factory:
         raise ConfigurationError("Must specify a resource factory.")
 
-    if not resource:
-        raise ConfigurationError("Must specify a resource file.")
+    if not schema:
+        raise ConfigurationError("Must specify a resource schema.")
+
+    provideUtility(factory, IFactory, name)
+
+    alsoProvides(schema, IResourceType)
+
+    schema.setTaggedValue('name', name)
 
-    f = open(resource)
-    xml = f.read()
-    f.close()
+    # XXX this is meta-configuration resources for setting instancs
+    # must be registered elsewhere
+    #
+    #f = open(resource)
+    #xml = f.read()
+    #f.close()
 
-    resource_object = factory()
-    IResourceImporter(resource_object).load(xml)
+    #resource_object = factory()
+    #IResourceImporter(resource_object).load(xml)
 
     # register the resource as a global setting
-    resources = getUtility(IResourceManager)
-    resources.register(name=name, title=resource_object.title,
-                       resource=resource_object)
+    #resources = getUtility(IResourceManager)
+    #resources.register(name=name, title=resource_object.title,
+    #                   resource=resource_object)
 

Modified: 
cpsskins/branches/jmo-perspectives/configuration/settings/metadirectives.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/configuration/settings/metadirectives.py 
(original)
+++ cpsskins/branches/jmo-perspectives/configuration/settings/metadirectives.py 
Wed Dec  7 17:06:17 2005
@@ -17,20 +17,24 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.configuration.fields import GlobalObject, Path
+from zope.configuration.fields import GlobalObject
 from zope.interface import Interface
 from zope.i18nmessageid import MessageFactory
-from zope.schema import DottedName
+from zope.schema import TextLine
 
 _ = MessageFactory("cpsskins")
 
 class ISettingDirective(Interface):
 
-    name = DottedName(
+    name = TextLine(
         title=_("Name"),
-        description=_("The name of the style."),
+        description=_("The name of the setting."),
         required=False,
-        min_dots=1,
+        )
+
+    schema = GlobalObject(
+        title=u"Resource schema",
+        description=u"The schema of the resource",
         )
 
     factory = GlobalObject(
@@ -39,9 +43,3 @@
         required=False,
         )
 
-    resource = Path(
-        title=_("Resource"),
-        description=_("The resource file."),
-        required=False,
-        )
-

Modified: cpsskins/branches/jmo-perspectives/perspectives/configure.zcml
==============================================================================
--- cpsskins/branches/jmo-perspectives/perspectives/configure.zcml      
(original)
+++ cpsskins/branches/jmo-perspectives/perspectives/configure.zcml      Wed Dec 
 7 17:06:17 2005
@@ -2,6 +2,7 @@
     xmlns="http://namespaces.zope.org/zope";
     xmlns:browser="http://namespaces.zope.org/browser";
     xmlns:i18n="http://namespaces.zope.org/i18n";
+    xmlns:cpsskins="http://namespaces.zope.org/cpsskins";
     i18n_domain="cpsskins"
     >
 
@@ -26,6 +27,13 @@
       provides="cpsskins.relations.interfaces.IRelatable"
   />
 
+  <!-- register the 'perspective' XML directive -->
+  <cpsskins:setting
+      name="perspective"
+      factory=".perspective.PerspectiveFactory"
+      schema=".interfaces.IPerspective"
+  />
+
   <!-- XML export -->
   <browser:page
       name="exporter"

Modified: cpsskins/branches/jmo-perspectives/perspectives/perspective.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/perspectives/perspective.py      
(original)
+++ cpsskins/branches/jmo-perspectives/perspectives/perspective.py      Wed Dec 
 7 17:06:17 2005
@@ -19,17 +19,14 @@
 
 from zope.app.publisher.browser import BrowserView
 from zope.component import adapts
-from zope.interface import implements, alsoProvides
+from zope.component.interfaces import IFactory
+from zope.interface import implements, alsoProvides, implementedBy
 
 from cpsskins.perspectives.interfaces import IPerspective
 from cpsskins.relations.interfaces import IRelatable
 from cpsskins.setup.interfaces import IResourceType
 from cpsskins.setup.interfaces import IResourceExporter, IResourceImporter
 
-alsoProvides(IPerspective, IResourceType)
-
-IPerspective.setTaggedValue('name', 'perspective')
-
 class Perspective(object):
     """A perspective
 
@@ -53,6 +50,21 @@
     def __eq__(self, other):
         return str(self) == other
 
+class PerspectiveFactory(object):
+
+    implements(IFactory)
+
+    title = "Perspective Factory"
+    description = "A Factory that create Perspectives"
+
+    def __call__(self):
+        return Perspective()
+
+    def getInterfaces(self):
+        return implementedBy(Perspective)
+
+PerspectiveFactory = PerspectiveFactory()
+
 class Relatable(object):
     """This adapter makes perspectives relatable.
     """

Modified: cpsskins/branches/jmo-perspectives/setup/setting.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/setup/setting.py (original)
+++ cpsskins/branches/jmo-perspectives/setup/setting.py Wed Dec  7 17:06:17 2005
@@ -28,9 +28,8 @@
     """
     implements(ISetting)
 
-    def __init__(self, title=u'', type=None, readonly=False, resource=None):
+    def __init__(self, title=u'', readonly=False, resource=None):
         self.title = title
-        self.type = type
         self.readonly = readonly
         self.resource = resource
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to