Package: zw.widget
Zaehlwerk WidgetsSome widgets for the z3c.form framework.Color widgetEmail widgetLines widgetTinyMCE widgetColorWidgetThe widget can render an input field with color preview:>>> from zope.interface.verify import verifyClass
>>> from z3c.form.interfaces import IWidget
>>> from zw.widget.color.widget import ColorWidgetThe ColorWidget is a widget:>>> verifyClass(IWidget, ColorWidget)
 TrueThe widget can render a input field only by adapting a request:>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = ColorWidget(request)Such a field provides IWidget:>>> IWidget.providedBy(widget)
 TrueWe also need to register the template for at least the widget and
request:>>> import os.path
>>> import zope.interface
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> import zw.widget.color
>>> import z3c.form.widget
>>> template = os.path.join(os.path.dirname(zw.widget.color.__file__),
...   'color_input.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
...     (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
...     IPageTemplate, name='input')If we render the widget we get the HTML:>>> print widget.render()
<input type="text" class="color-widget" value="" />Adding some more attributes to the widget will make it display more:>>> widget.id = 'id'
>>> widget.name = 'name'
>>> widget.value = u'value'

>>> print widget.render()
<span id="" class="color-widget color-sample"
      style="background-color: #value;">
</span>
<input type="text" id="id" name="name" class="color-widget"
       value="value" />EmailWidgetThe widget can render an ordinary input field:>>> from zope.interface.verify import verifyClass
>>> from z3c.form.interfaces import IWidget, INPUT_MODE, DISPLAY_MODE
>>> from zw.widget.email.widget import EmailWidgetThe EmailWidget is a widget:>>> verifyClass(IWidget, EmailWidget)
 TrueThe widget can render a input field only by adapting a request:>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = EmailWidget(request)Such a field provides IWidget:>>> IWidget.providedBy(widget)
 TrueWe also need to register the template for at least the widget and
request:>>> import os.path
>>> import zope.interface
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> import zw.widget.email
>>> import z3c.form.widget
>>> template = os.path.join(os.path.dirname(zw.widget.email.__file__),
...   'email_input.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
...     (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
...     IPageTemplate, name='input')If we render the widget we get the HTML:>>> print widget.render()
<input type="text" class="email-widget" value="" />Adding some more attributes to the widget will make it display more:>>> widget.id = 'id'
>>> widget.name = 'name'
>>> widget.value = u'name@domain.tld'

>>> print widget.render()
<input type="text" id="id" name="name" class="email-widget"
       value="name@domain.tld" />More interesting is to the display view:>>> widget.mode = DISPLAY_MODE
>>> template = os.path.join(os.path.dirname(zw.widget.email.__file__),
...                         'email_display.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
...     (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
...     IPageTemplate, name='display')
>>> print widget.render()
<span id="id" class="email-widget">
  <a href="mailto:name@domain.tld">
    name@domain.tld
  </a>
</span>But if we are not authenticated it should be obscured:>>> widget.obscured = True
>>> print widget.render()
<span id="id" class="email-widget">
    name@domain.tld
</span>LinesWidgetThe widget can render a HTML text input field, which collects list
items by line.>>> from zope.interface.verify import verifyClass
>>> from z3c.form.interfaces import IWidget
>>> from zw.widget.lines.widget import LinesWidgetThe LinesWidget is a widget:>>> verifyClass(IWidget, LinesWidget)
 TrueThe widget can render a textarea field only by adapteing a request:>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = LinesWidget(request)Such a field provides IWidget:>>> IWidget.providedBy(widget)
 TrueWe also need to register the template for at least the widget and
request:>>> import os.path
>>> import zope.interface
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> import zw.widget.lines
>>> import z3c.form.widget
>>> template = os.path.join(os.path.dirname(zw.widget.lines.__file__),
...   'lines_input.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
...     (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
...     IPageTemplate, name='input')If we render the widget we get the HTML:>>> print widget.render()
<textarea class="lines-widget"></textarea>Adding some more attributes to the widget will make it display more:>>> widget.id = 'id'
>>> widget.name = 'name'
>>> widget.value = u'value'>>> print widget.render()
<textarea id="id" name="name" class="lines-widget">value</textarea>TinyWidgetThe widget can render a HTML text input field based on the TinyMCE
JavaScript Content Editor from Moxicode Systems..http://tinymce.moxiecode.com>>> from zope.interface.verify import verifyClass
>>> from zope.app.form.interfaces import IInputWidget
>>> from z3c.form.interfaces import IWidget
>>> from zw.widget.tiny.widget import TinyWidgetThe TinyWidget is a widget:>>> verifyClass(IWidget, TinyWidget)
 TrueThe widget can render a textarea field only by adapteing a request:>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
>>> widget = TinyWidget(request)Such a field provides IWidget:>>> IWidget.providedBy(widget)
 TrueWe also need to register the template for at least the widget and
request:>>> import os.path
>>> import zope.interface
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.pagetemplate.interfaces import IPageTemplate
>>> import zw.widget.tiny
>>> import z3c.form.widget
>>> template = os.path.join(os.path.dirname(zw.widget.tiny.__file__),
...   'tiny_input.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
...     (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
...     IPageTemplate, name='input')If we render the widget we get the HTML:>>> print widget.render()
<textarea class="tiny-widget" cols="60" rows="10"></textarea>Adding some more attributes to the widget will make it display more:>>> widget.id = 'id'
>>> widget.name = 'name'
>>> widget.value = u'value'>>> print widget.render()
<textarea id="id" name="name" class="tiny-widget" cols="60"
          rows="10">value</textarea>TODO: Testing for ECMAScript code…CHANGESVersion 0.1.6.2 (2009-01-09)Lines: converter should work only on LinesWidgetVersion 0.1.6.1 (2008-12-28)packaging problem in setup.pyVersion 0.1.6 (2008-12-28)tinyMCE update (3.2.1.1)tinyMCE is not included in the sources but downloaded.z3c.autoinclude dependency removedVersion 0.1.5 (2008-11-18)tinyMCE update (3.2.1)Version 0.1.4 (2008-06-08)tinyMCE update (3.0.9)Version 0.1.3 (2008-06-08)tinyMCE bug fix for gecko based browsersVersion 0.1.2 (2008-04-13)email widget for z3c.schema.email added.Version 0.1 (2008-02-17)Initial release