# HG changeset patch # User Damien Correia # Date 1536067530 -7200 # Node ID bac52cf36b150074243ef8e23e858d30181e9c71 # Parent a6d503cd9bb1818e91d24765585450b172cc2c08 Updated Frame Paragraph renderer, added pictogram support diff -r a6d503cd9bb1 -r bac52cf36b15 src/pyams_default_theme/component/paragraph/frame.py --- a/src/pyams_default_theme/component/paragraph/frame.py Tue Sep 04 15:20:52 2018 +0200 +++ b/src/pyams_default_theme/component/paragraph/frame.py Tue Sep 04 15:25:30 2018 +0200 @@ -9,6 +9,9 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_content.reference.pictograms import IPictogramTable +from pyams_utils.registry import query_utility +from pyams_utils.zodb import volatile_property __docformat__ = 'restructuredtext' @@ -22,7 +25,8 @@ from pyams_content.component.paragraph.interfaces.frame import IFrameParagraph from pyams_content.features.renderer.interfaces import IContentRenderer from pyams_default_theme.component.paragraph.interfaces.frame import IFrameParagraphRendererSettings, \ - ILateralFrameParagraphRendererSettings, IDefaultFrameParagraphRendererSettings + ILateralFrameParagraphRendererSettings, IDefaultFrameParagraphRendererSettings, ILeftFrameParagraphRendererSettings, \ + IRightFrameParagraphRendererSettings from pyams_i18n.interfaces import II18n from pyams_skin.layer import IPyAMSLayer @@ -42,7 +46,8 @@ # FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.frame.renderer:default' - +LEFT_LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.frame.renderer:lateral:left' +RIGHT_LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.frame.renderer:lateral:right' @implementer(IFrameParagraphRendererSettings) class BaseFrameParagraphRendererSettings(Persistent, Location): @@ -50,6 +55,7 @@ display_illustration = FieldProperty(IFrameParagraphRendererSettings['display_illustration']) display_associations = FieldProperty(IFrameParagraphRendererSettings['display_associations']) + _pictogram_name = FieldProperty(IDefaultFrameParagraphRendererSettings['pictogram_name']) def can_display_illustration(self): if not self.display_illustration: @@ -65,19 +71,28 @@ associations = IAssociationContainer(frame, None) return (associations is not None) and (len(associations.get_visible_items()) > 0) + @property + def pictogram_name(self): + return self._pictogram_name + + @pictogram_name.setter + def pictogram_name(self, value): + if value != self._pictogram_name: + self._pictogram_name = value + del self.pictogram + + @volatile_property + def pictogram(self): + table = query_utility(IPictogramTable) + if table is not None: + return table.get(self._pictogram_name) + @implementer(IDefaultFrameParagraphRendererSettings) class DefaultFrameParagraphRendererSettings(BaseFrameParagraphRendererSettings): """Framed text paragraph lateral renderer settings""" -@adapter_config(context=IFrameParagraph, provides=IDefaultFrameParagraphRendererSettings) -def default_frame_paragraph_renderer_settings_factory(context): - """Frame paragraph default renderer settings factory""" - return get_annotation_adapter(context, FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY, - DefaultFrameParagraphRendererSettings) - - @implementer(ILateralFrameParagraphRendererSettings) class LateralFrameParagraphRendererSettings(BaseFrameParagraphRendererSettings): """Framed text paragraph lateral renderer settings""" @@ -85,14 +100,38 @@ relative_width = FieldProperty(ILateralFrameParagraphRendererSettings['relative_width']) -LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY = 'pyams_content.frame.renderer:lateral' +@implementer(ILeftFrameParagraphRendererSettings) +class LeftFrameParagraphRendererSettings(LateralFrameParagraphRendererSettings): + """Left Framed text paragraph lateral renderer settings""" + + +@implementer(IRightFrameParagraphRendererSettings) +class RightFrameParagraphRendererSettings(LateralFrameParagraphRendererSettings): + """Right Framed text paragraph lateral renderer settings""" -@adapter_config(context=IFrameParagraph, provides=ILateralFrameParagraphRendererSettings) -def lateral_frame_paragraph_renderer_settings_factory(context): +# +# Adapter Framed text paragraph default renderer +# + +@adapter_config(context=IFrameParagraph, provides=IDefaultFrameParagraphRendererSettings) +def default_frame_paragraph_renderer_settings_factory(context): + """Frame paragraph default renderer settings factory""" + return get_annotation_adapter(context, FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY, + DefaultFrameParagraphRendererSettings) + + +@adapter_config(context=IFrameParagraph, provides=ILeftFrameParagraphRendererSettings) +def left_lateral_frame_paragraph_renderer_settings_factory(context): """Frame text paragraph lateral renderer settings factory""" - return get_annotation_adapter(context, LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY, - LateralFrameParagraphRendererSettings) + return get_annotation_adapter(context, LEFT_LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY, + LeftFrameParagraphRendererSettings) + +@adapter_config(context=IFrameParagraph, provides=IRightFrameParagraphRendererSettings) +def right_lateral_frame_paragraph_renderer_settings_factory(context): + """Frame text paragraph lateral renderer settings factory""" + return get_annotation_adapter(context, RIGHT_LATERAL_FRAME_PARAGRAPH_RENDERER_SETTINGS_KEY, + RightFrameParagraphRendererSettings) # @@ -134,7 +173,7 @@ label = _("Small frame on the left") weight = 2 - settings_interface = ILateralFrameParagraphRendererSettings + settings_interface = ILeftFrameParagraphRendererSettings @adapter_config(name='right', context=(IFrameParagraph, IPyAMSLayer), provides=IContentRenderer) @@ -145,4 +184,4 @@ label = _("Small frame on the right") weight = 3 - settings_interface = ILateralFrameParagraphRendererSettings + settings_interface = IRightFrameParagraphRendererSettings diff -r a6d503cd9bb1 -r bac52cf36b15 src/pyams_default_theme/component/paragraph/interfaces/frame.py --- a/src/pyams_default_theme/component/paragraph/interfaces/frame.py Tue Sep 04 15:20:52 2018 +0200 +++ b/src/pyams_default_theme/component/paragraph/interfaces/frame.py Tue Sep 04 15:25:30 2018 +0200 @@ -18,7 +18,8 @@ # import interfaces # import packages -from zope.interface import Interface +from pyams_content.reference.pictograms import PICTOGRAM_VOCABULARY +from zope.interface import Interface, Attribute from zope.schema import Bool, Choice from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm @@ -54,6 +55,13 @@ def can_display_associations(self): """Check if associations can be displayed""" + pictogram_name = Choice(title=_("Pictogram"), + description=_("Name of the pictogram associated with this frame paragraph"), + required=False, + vocabulary=PICTOGRAM_VOCABULARY) + + pictogram = Attribute("Selected pictogram object") + class IDefaultFrameParagraphRendererSettings(IFrameParagraphRendererSettings): """Framed paragraph default renderer settings interface""" @@ -68,3 +76,11 @@ required=True, values=list(range(1, 13)), default=4) + + +class ILeftFrameParagraphRendererSettings(ILateralFrameParagraphRendererSettings): + """Left Framed paragraph lateral renderer settings interface""" + + +class IRightFrameParagraphRendererSettings(ILateralFrameParagraphRendererSettings): + """Right Framed paragraph lateral renderer settings interface""" diff -r a6d503cd9bb1 -r bac52cf36b15 src/pyams_default_theme/component/paragraph/zmi/frame.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/zmi/frame.py Tue Sep 04 15:25:30 2018 +0200 @@ -0,0 +1,42 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + +# import standard library + +# import interfaces +from pyams_content.component.paragraph.interfaces.frame import IFrameParagraph + +# import packages +from pyams_content.features.renderer.zmi import RendererPropertiesEditForm +from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION +from pyams_content.reference.pictograms.zmi.widget import PictogramSelectFieldWidget +from pyams_form.form import ajax_config +from pyams_skin.layer import IPyAMSLayer +from pyams_pagelet.pagelet import pagelet_config +from pyramid.decorator import reify + + +@pagelet_config(name='renderer-properties.html', context=IFrameParagraph, layer=IPyAMSLayer, + permission=MANAGE_CONTENT_PERMISSION) +@ajax_config(name='renderer-properties.json', context=IFrameParagraph, layer=IPyAMSLayer) +class DefaultFrameRendererPropertiesEditForm(RendererPropertiesEditForm): + """Internal link properties edit form""" + + @reify + def fields(self): + fields = super(DefaultFrameRendererPropertiesEditForm, self).fields + if 'pictogram_name' in fields: + fields['pictogram_name'].widgetFactory = PictogramSelectFieldWidget + return fields +