[Checkins] SVN: Zope3/trunk/ - icon directive now supports width
and height
Roman Joost
rj at gocept.com
Fri Feb 16 09:06:13 EST 2007
Log message for revision 72646:
- icon directive now supports width and height
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/publisher/browser/icon.py
U Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2007-02-16 09:45:11 UTC (rev 72645)
+++ Zope3/trunk/doc/CHANGES.txt 2007-02-16 14:06:12 UTC (rev 72646)
@@ -10,6 +10,8 @@
New features
+ - icon zcml directive supports now 'width' and 'height'
+
- Added a master checkbox to the ZMI and toggles all other checkboxes in
the folder listing.
Modified: Zope3/trunk/src/zope/app/publisher/browser/icon.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/icon.py 2007-02-16 09:45:11 UTC (rev 72645)
+++ Zope3/trunk/src/zope/app/publisher/browser/icon.py 2007-02-16 14:06:12 UTC (rev 72646)
@@ -31,11 +31,13 @@
class IconView(object):
- def __init__(self, context, request, rname, alt):
+ def __init__(self, context, request, rname, alt, width, height):
self.context = context
self.request = request
self.rname = rname
self.alt = alt
+ self.width = width
+ self.height = height
def __call__(self):
# The context is important here, since it becomes the parent of the
@@ -43,8 +45,8 @@
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))
+ return ('<img src="%s" alt="%s" width="%s" height="%s" border="0" />'
+ % (src, self.alt, self.width, self.height))
def url(self):
resource = getResource(self.context, self.rname, self.request)
@@ -53,15 +55,19 @@
class IconViewFactory(object):
- def __init__(self, rname, alt):
+ def __init__(self, rname, alt, width, height):
self.rname = rname
self.alt = alt
+ self.width = width
+ self.height = height
def __call__(self, context, request):
- return IconView(context, request, self.rname, self.alt)
+ return IconView(context, request, self.rname, self.alt,
+ self.width, self.height)
def IconDirective(_context, name, for_, file=None, resource=None,
- layer=IDefaultBrowserLayer, title=None):
+ layer=IDefaultBrowserLayer, title=None,
+ width=16, height=16):
iname = for_.getName()
@@ -89,7 +95,7 @@
"attributes for resource directives must be specified"
)
- vfactory = IconViewFactory(resource, title)
+ vfactory = IconViewFactory(resource, title, width, height)
_context.action(
discriminator = ('view', name, vfactory, layer),
Modified: Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2007-02-16 09:45:11 UTC (rev 72645)
+++ Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2007-02-16 14:06:12 UTC (rev 72646)
@@ -727,3 +727,21 @@
directive. Defaults to "default".""",
required=False
)
+
+ width = Int(
+ title=u"The width of the icon.",
+ description=u"""
+ The width will be used for the <img width="..." />
+ attribute. Defaults to 16.""",
+ required=False,
+ default=16
+ )
+
+ height = Int(
+ title=u"The height of the icon.",
+ description=u"""
+ The height will be used for the <img height="..." />
+ attribute. Defaults to 16.""",
+ required=False,
+ default=16
+ )
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py 2007-02-16 09:45:11 UTC (rev 72645)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py 2007-02-16 14:06:12 UTC (rev 72646)
@@ -110,7 +110,26 @@
'width="16" height="16" border="0" />'
% rname)
+ # Make sure that the width and height attributes work
+ xmlconfig(StringIO(template % (
+ '''
+ <browser:icon name="zmi_icon_w_width_and_height"
+ for="zope.app.component.tests.views.IC"
+ file="%s"
+ width="20" height="12" />
+ ''' % path
+ )))
+ view = zapi.getMultiAdapter((ob, request),
+ name='zmi_icon_w_width_and_height')
+ rname = ('zope-app-component-tests-views-IC-'
+ 'zmi_icon_w_width_and_height.gif')
+ self.assertEqual(
+ view(),
+ '<img src="http://127.0.0.1/@@/%s" alt="IC" '
+ 'width="20" height="12" border="0" />'
+ % rname)
+
# Make sure that the image was installed as a resource:
resource = ProxyFactory(zapi.getAdapter(request, name=rname))
self.assertRaises(Forbidden, getattr, resource, '_testData')
More information about the Checkins
mailing list