Back to index

moin  1.9.0~rc2
ShowSmileys.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - List all defined smileys
00004 
00005     <<ShowSmileys>> will display a table of all the available smileys.
00006 
00007     Based on code by Nick Trout <trout@users.sf.net>
00008 
00009     @copyright: 2003 Juergen Hermann <jh@web.de>
00010     @license: GNU GPL, see COPYING for details.
00011 """
00012 
00013 from MoinMoin import config
00014 from MoinMoin.util.dataset import TupleDataset, Column
00015 from MoinMoin.widget.browser import DataBrowserWidget
00016 
00017 COLUMNS = 4
00018 
00019 Dependencies = ['user'] # different users have different themes and different user prefs (text/gfx)
00020 
00021 def macro_ShowSmileys(macro):
00022     _ = macro.request.getText
00023     fmt = macro.formatter
00024 
00025     # create data description
00026     data = TupleDataset()
00027     data.columns = []
00028     for dummy in range(COLUMNS):
00029         data.columns.extend([
00030             Column('markup', label=_('Markup')),
00031             Column('image', label=_('Display'), align='center'),
00032             Column('', label=''),
00033         ])
00034     data.columns[-1].hidden = 1
00035 
00036     # iterate over smileys, in groups of size COLUMNS
00037     smileys = config.smileys
00038     for idx in range(0, len(smileys), COLUMNS):
00039         row = []
00040         for off in range(COLUMNS):
00041             if idx+off < len(smileys):
00042                 markup = smileys[idx+off]
00043                 row.extend([fmt.code(1) + fmt.text(markup) + fmt.code(0), fmt.smiley(markup), '', ])
00044             else:
00045                 row.extend(['&nbsp;'] * 3)
00046         data.addRow(tuple(row))
00047 
00048     # display table
00049     if data:
00050         browser = DataBrowserWidget(macro.request)
00051         browser.setData(data)
00052         return browser.render(method="GET")
00053 
00054     return ''
00055