Back to index

plone3  3.1.7
helpers.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
00004 #
00005 # This software is distributed under the terms of the Kupu
00006 # License. See LICENSE.txt for license text. For a list of Kupu
00007 # Contributors see CREDITS.txt.
00008 #
00009 ##############################################################################
00010 # Helper classes
00011 # Filter list: filter name, title, enabled by default, css class
00012 FILTERS = [
00013     ('save-button', 'Save button', True, 'kupu-save'),
00014     ('bg-basicmarkup', 'Bold/Italic group', True, None),
00015     ('bold-button', 'Bold button', True, 'kupu-bold'),
00016     ('italic-button', 'Italic button', True, 'kupu-italic'),
00017     ('bg-subsuper', 'Subscript/Superscript group', False, None),
00018     ('subscript-button', 'Subscript button', False, 'kupu-subscript'),
00019     ('superscript-button', 'Superscript button', False, 'kupu-superscript'),
00020     ('bg-colorchooser', 'Colour chooser group', False, None),
00021     ('forecolor-button', 'Psychedelic foreground', False, 'kupu-forecolor'),
00022     ('hilitecolor-button', 'Psychedelic background', False, 'kupu-hilitecolor'),
00023     ('bg-justify', 'Justify group', True, None),
00024     ('justifyleft-button', 'Justify left button', True, 'kupu-justifyleft'),
00025     ('justifycenter-button', 'Justify center button', True, 'kupu-justifycenter'),
00026     ('justifyright-button', 'Justify right button', True, 'kupu-justifyright'),
00027     ('bg-list', 'List group', True, None),
00028     ('list-ol-addbutton', 'Add ordered list button', True, 'kupu-insertorderedlist'),
00029     ('list-ul-addbutton', 'Add unordered list button', True, 'kupu-insertunorderedlist'),
00030     ('definitionlist', 'Definition list', True, 'kupu-insertdefinitionlist'),
00031     ('bg-indent', 'Indent group', True, None),
00032     ('outdent-button', 'Outdent button', True, 'kupu-outdent'),
00033     ('indent-button', 'Indent button', True, 'kupu-indent'),
00034     ('bg-drawers', 'Drawers group', True, None),
00035     ('imagelibdrawer-button', 'Image drawer button', True, 'kupu-image'),
00036     ('linklibdrawer-button', 'Link drawer button', True, 'kupu-inthyperlink'),
00037     ('linkdrawer-button', 'External link drawer button', True, 'kupu-exthyperlink'),
00038     ('embed-tab', 'Embed tab in External link drawer', False, None),
00039     ('anchors-button', 'Anchor drawer button', True, 'kupu-anchors'),
00040     ('manage-anchors-tab', 'Manage Anchors tab in anchor drawer', True, None),
00041     ('toc-tab', 'Table of Contents in anchor drawer', False, None),
00042     ('tabledrawer-button', 'Table drawer button', True, 'kupu-table'),
00043     ('bg-remove', 'Remove group', True, None),
00044     ('removeimage-button', 'Remove image button', True, 'kupu-removeimage'),
00045     ('removelink-button', 'Remove link button', True, 'kupu-removelink'),
00046     ('bg-undo', 'Undo group', False, None),
00047     ('undo-button', 'Undo button', False, 'kupu-undo'),
00048     ('redo-button', 'Redo button', False, 'kupu-redo'),
00049     ('spellchecker', 'Spellchecker', False, 'kupu-spellchecker'),
00050     ('source', 'Source', True, 'kupu-source'),
00051     ('styles', 'Styles pulldown', True, None),
00052     ('ulstyles', 'Unordered list style pulldown', False, None),
00053     ('olstyles', 'Ordered list style pulldown', True, None),
00054     ('zoom', 'Zoom button', True, 'kupu-zoom'),
00055 ]
00056 FILTERDICT = dict([(k,v) for (k,title,v,cl) in FILTERS])
00057 
00058 class ButtonFilter:
00059     """Helper class to control visibility of buttons.
00060     Works from both a whitelist and a blacklist in the widget.
00061     The configlet also provides a master list of visibilities
00062     """
00063     __allow_access_to_unprotected_subobjects__ = 1
00064 
00065     def __init__(self, tool, context, field=None):
00066         def isButtonAllowed(name):
00067             visible = visible_buttons.get(name, None)
00068             if visible is None:
00069                 visible = FILTERDICT.get(name, True)
00070             if allow_buttons is not None:
00071                 return visible and name in allow_buttons
00072             if filter_buttons is not None:
00073                return visible and name not in filter_buttons
00074             return visible
00075 
00076         widget = getattr(field, 'widget', None)
00077         filter_buttons = getattr(widget, 'filter_buttons', None)
00078         allow_buttons = getattr(widget, 'allow_buttons', None)
00079         visible_buttons, gvisible = tool.getToolbarFilters(context, field)
00080         if gvisible is None:
00081             gvisible = FILTERDICT.keys()
00082         else:
00083             for k in FILTERDICT.keys():
00084                 setattr(self, k, False)
00085         for k in gvisible:
00086             setattr(self, k, isButtonAllowed(k))