[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZMI - IconDirective.py:1.3 zmi-meta.zcml:1.3
Jim Fulton
jim@zope.com
Thu, 13 Jun 2002 19:16:15 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZMI
In directory cvs.zope.org:/tmp/cvs-serv10697/lib/python/Zope/App/ZMI
Modified Files:
IconDirective.py zmi-meta.zcml
Log Message:
Got icons working, and, along the way:
- Implemented the icon directive
- Implemented
http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ResourcesProposal
- Added a special view, named '', for service manager containers that
allows resources to have URLs like:
http://foo.com/@@/resourcename
- Fixed some server code that caused HTTP response data to get
promoted to unicode
- Updated the folder contents page to display icons.
- Ported icons for folder, file, image, and zptpage. Many more icons
need to be ported or created.
=== Zope3/lib/python/Zope/App/ZMI/IconDirective.py 1.2 => 1.3 ===
$Id$
"""
+import os
+import re
-def IconDirective(_context, for_, file):
- #stub
- return ()
+from Zope.App.ComponentArchitecture.metaConfigure import handler
+from Zope.Configuration.Action import Action
+from Zope.ComponentArchitecture import getResource
+from Zope.App.Publisher.Browser.metaConfigure import resource
+from Zope.App.Traversing.GetResource import getResource
+from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+
+IName = re.compile('I[A-Z][a-z]')
+
+class IconView:
+
+ def __init__(self, context, request, rname, alt):
+ self.context = context
+ self.request = request
+ self.rname = rname
+ self.alt = alt
+
+ def __call__(self):
+ resource = getResource(self.context, self.rname, self.request)
+ src = resource()
+
+ return ('<img src="%s" alt="%s" width="16" height="16" border="0" />'
+ % (src, self.alt))
+
+class IconViewFactory:
+
+ def __init__(self, rname, alt):
+ self.rname = rname
+ self.alt = alt
+
+ def __call__(self, context, request):
+ return IconView(context, request, self.rname, self.alt)
+
+def IconDirective(_context, for_, file, layer='default',
+ alt=None):
+
+ for_ = _context.resolve(for_)
+ iname = for_.__name__
+
+ if alt is None:
+ alt = iname
+ if IName.match(alt):
+ alt = alt[1:] # Remove leading 'I'
+
+ rname = '-'.join(for_.__module__.split('.'))
+ rname = "%s-%s-zmi_icon" % (rname, iname)
+
+ ext = os.path.splitext(file)[1]
+ if ext:
+ rname += ext
+
+ vfactory = IconViewFactory(rname, alt)
+
+ return resource(_context, image=file, name=rname, layer=layer)() + [
+ Action(
+ discriminator = ('view', 'zmi_icon', vfactory, layer),
+ callable = handler,
+ args = ('Views', 'provideView',
+ for_, 'zmi_icon', IBrowserPresentation,
+ vfactory, layer)),
+
+ ]
+
+
=== Zope3/lib/python/Zope/App/ZMI/zmi-meta.zcml 1.2 => 1.3 ===
</directive>
- <directive name="icon" attributes="for file package alt layer"
+ <directive name="icon" attributes="for file image alt layer"
handler="Zope.App.ZMI.IconDirective." />
</directives>