This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Additional widgets for z3c.form

Project Description

Zaehlwerk Widgets

Some widgets for the z3c.form framework.

  • Color widget
  • Email widget
  • Lines widget
  • TinyMCE widget

ColorWidget

The 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 ColorWidget

The ColorWidget is a widget:

>>> verifyClass(IWidget, ColorWidget)
 True

The 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)
 True

We 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" />

EmailWidget

The 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 EmailWidget

The EmailWidget is a widget:

>>> verifyClass(IWidget, EmailWidget)
 True

The 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)
 True

We 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>

LinesWidget

The 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 LinesWidget

The LinesWidget is a widget:

>>> verifyClass(IWidget, LinesWidget)
 True

The 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)
 True

We 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>

TinyWidget

The 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 TinyWidget

The TinyWidget is a widget:

>>> verifyClass(IWidget, TinyWidget)
 True

The 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)
 True

We 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…

CHANGES

Version 0.1.6.2 (2009-01-09)

  • Lines: converter should work only on LinesWidget

Version 0.1.6.1 (2008-12-28)

  • packaging problem in setup.py

Version 0.1.6 (2008-12-28)

  • tinyMCE update (3.2.1.1)
  • tinyMCE is not included in the sources but downloaded.
  • z3c.autoinclude dependency removed

Version 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 browsers

Version 0.1.2 (2008-04-13)

  • email widget for z3c.schema.email added.

Version 0.1 (2008-02-17)

  • Initial release
Release History

Release History

This version
History Node

0.1.6.2

History Node

0.1.6.1

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
zw.widget-0.1.6.2.tar.gz (26.0 kB) Copy SHA256 Checksum SHA256 Source Jan 9, 2009

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting