src/ztfy/utils/browser/encoding.py
branchZTK-1.1
changeset 148 d3668ecd9137
parent 115 4ec3baf668c2
equal deleted inserted replaced
147:044dc196ec8a 148:d3668ecd9137
       
     1 ### -*- coding: utf-8 -*- ####################################################
       
     2 ##############################################################################
       
     3 #
       
     4 # Copyright (c) 2008-2012 Thierry Florac <tflorac AT ulthar.net>
       
     5 # All Rights Reserved.
       
     6 #
       
     7 # This software is subject to the provisions of the Zope Public License,
       
     8 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
    10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    12 # FOR A PARTICULAR PURPOSE.
       
    13 #
       
    14 ##############################################################################
       
    15 
       
    16 __docformat__ = "restructuredtext"
       
    17 
       
    18 # import standard packages
       
    19 
       
    20 # import Zope3 interfaces
       
    21 from z3c.form.interfaces import ISelectWidget, IFieldWidget
       
    22 from zope.publisher.interfaces.browser import IBrowserRequest
       
    23 
       
    24 # import local interfaces
       
    25 
       
    26 # import Zope3 packages
       
    27 from z3c.form.browser.select import SelectWidget
       
    28 from z3c.form.widget import FieldWidget
       
    29 from zope.component import adapter
       
    30 from zope.interface import implementer, implementsOnly
       
    31 
       
    32 # import local packages
       
    33 from ztfy.utils.encoding import IEncodingField
       
    34 
       
    35 from ztfy.utils import _
       
    36 
       
    37 
       
    38 class IEncodingSelectWidget(ISelectWidget):
       
    39     """ENcoding select widget interface"""
       
    40 
       
    41 
       
    42 class EncodingSelectWidget(SelectWidget):
       
    43     """Encoding select widget"""
       
    44 
       
    45     implementsOnly(IEncodingSelectWidget)
       
    46 
       
    47     noValueMessage = _("-- automatic selection --")
       
    48 
       
    49 
       
    50 @adapter(IEncodingField, IBrowserRequest)
       
    51 @implementer(IFieldWidget)
       
    52 def EncodingSelectFieldWidget(field, request):
       
    53     """IFieldWidget factory for IEncodingSelectWidget"""
       
    54     return FieldWidget(field, EncodingSelectWidget(request))