1 """
   2     MoinMoin - Show Smileys Macro.
   3 
   4     Copyright (c) 2003 by Nick Trout <trout@users.sf.net>
   5     All rights reserved, see COPYING for details.
   6 
   7     Display all of the available smileys on this wiki.
   8     eg. [[ShowSmileys()]] will display a table of the smileys and
   9         [[ShowSmileys(list)]] will display a bullet list.
  10 
  11     Todo:
  12     * Use result.append() instead of str += 
  13     * Tables 3-4 columns wide
  14     * or use TableBrowser widget to display icons (maybe a 3rd option)
  15     * make it work with cvs current, smileys live in config. now
  16 
  17     $Id: $
  18 """
  19 
  20 # Imports
  21 from MoinMoin import wikiutil
  22 from cgi import escape
  23 
  24 
  25 def execute(macro, args):
  26     disptype = 'table'
  27     if args:
  28         if args == 'list':
  29             return smileyList(macro)
  30     return smileyTable(macro)
  31 
  32 
  33 def smileysOrder(smileylist):
  34     """ Put the smileys in a preferred order rather than the random order
  35         they are in as dictionary keys.
  36     """
  37     ordered = smileylist
  38     ordered.sort()
  39     return ordered
  40 
  41 
  42 def smileyList(macro):
  43     """ Create a bullet list of the smileys available. """
  44     smileys = wikiutil.smileys
  45     fmt = macro.formatter
  46     str = ''
  47 
  48     # show smileys as a list with items
  49     str += fmt.bullet_list(1)
  50     
  51     # <smiley text> : <smiley icon>
  52     for smtext in smileysOrder(smileys.keys()):
  53         item = fmt.listitem(1) + fmt.code(1)
  54         item += '%-4s : ' % escape(smtext)
  55         item += fmt.code(0) + wikiutil.getSmiley(smtext, fmt) + fmt.listitem(0)
  56         str += item
  57         
  58     str += fmt.bullet_list(0)
  59     return str
  60 
  61 
  62 def smileyTable(macro):
  63     """ Create a table list of the smileys available. """
  64     smileys = wikiutil.smileys
  65     fmt = macro.formatter
  66     str = ''
  67 
  68     # show smileys as a table
  69     str += fmt.table(1)
  70     
  71     # <smiley text> : <smiley icon>
  72     for smtext in smileysOrder(smileys.keys()):
  73         item =  fmt.table_row(1)
  74         item += fmt.table_cell(1)
  75         item += fmt.code(1)
  76         item += '%-4s' % escape(smtext)
  77         item += fmt.code(0)
  78         item += fmt.table_cell(0)
  79         item += fmt.table_cell(1)
  80         item += wikiutil.getSmiley(smtext, fmt)
  81         item += fmt.table_cell(0)
  82         item += fmt.table_row(0)
  83         str += item
  84         
  85     str += fmt.table(0)
  86     return str

MoinMoin: macro/ShowSmileys.py (last edited 2007-10-29 19:20:31 by localhost)