home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / skin / skintransform.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  7.0 KB  |  248 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import division
  5. from gui.toolbox import colorfor
  6. import wx
  7. from util import strlist, LowerStorage, autoassign
  8. import traceback
  9. import sys
  10. from gui.textutil import CopyFont, default_font
  11. from logging import getLogger
  12. log = getLogger('skintransform')
  13. from gui.skin import SkinException
  14. from gui.skin.skinparse import makeBrush, makeImage, makeFont, makePadding
  15. from gui.skin.skinobjects import Margins
  16. SUBSIGIL = '$'
  17.  
  18. def which_rule(k):
  19.     k = k.lower()
  20.     for rule in erules:
  21.         if k.endswith(rule):
  22.             return rule
  23.             continue
  24.     
  25.  
  26.  
  27. def subs_common(s, common):
  28.     words = s.split()
  29.     for i, word in enumerate(list(words)):
  30.         if word.startswith(SUBSIGIL):
  31.             val = common.get(word[1:].lower(), None)
  32.             if val is None:
  33.                 continue
  34.             
  35.             words[i] = val
  36.             continue
  37.     
  38.     return ' '.join((lambda .0: for w in .0:
  39. unicode(w))(words))
  40.  
  41.  
  42. def transform(skintree, do_string_subs = True):
  43.     if do_string_subs:
  44.         common = skintree.setdefault('common', { })
  45.     else:
  46.         common = { }
  47.     
  48.     def apply_string_substitution(elem):
  49.         if isinstance(elem, dict):
  50.             for k, v in elem.iteritems():
  51.                 if isinstance(v, basestring):
  52.                     elem[k] = subs_common(v, common)
  53.                     continue
  54.                 elem[k] = apply_string_substitution(v)
  55.             
  56.         elif isinstance(elem, list):
  57.             newlist = []
  58.             for e in elem:
  59.                 if isinstance(e, basestring):
  60.                     e = subs_common(e, common)
  61.                 
  62.                 newlist.append(e)
  63.             
  64.             elem[:] = newlist
  65.         
  66.         return elem
  67.  
  68.     
  69.     def recursive_transform(elem):
  70.         if isinstance(elem, dict):
  71.             for k, v in elem.iteritems():
  72.                 if k in rules:
  73.                     elem[k] = rules[k](v)
  74.                     continue
  75.                 if k.lower() not in erule_excludes and k.lower().endswith(tuple(erules.keys())):
  76.                     elem[k] = erules[which_rule(k)](v)
  77.                     continue
  78.                 recursive_transform(v)
  79.             
  80.         
  81.         return elem
  82.  
  83.     if do_string_subs:
  84.         return recursive_transform(apply_string_substitution(skintree))
  85.     else:
  86.         return recursive_transform(skintree)
  87.  
  88.  
  89. def r_backgrounds(v):
  90.     if v is None:
  91.         return v
  92.     
  93.     for key, value in v.iteritems():
  94.         v[key] = makeBrush(value)
  95.     
  96.     return v
  97.  
  98.  
  99. def r_background(v):
  100.     return makeBrush(v)
  101.  
  102.  
  103. def r_frame(v):
  104.     return makeBrush(v)
  105.  
  106.  
  107. def r_framesize(s):
  108.     return Margins(s)
  109.  
  110.  
  111. def er_margins(s):
  112.     return Margins(s)
  113.  
  114.  
  115. def er_padding(s):
  116.     return makePadding(s)
  117.  
  118.  
  119. def er_colors(v):
  120.     for colorname, color in v.iteritems():
  121.         v[colorname] = colorfor(color)
  122.     
  123.     return v
  124.  
  125.  
  126. def er_color(v):
  127.     return colorfor(v)
  128.  
  129.  
  130. def er_icons(v):
  131.     skin = skin
  132.     import gui
  133.     for iconname, iconpath in v.iteritems():
  134.         v[iconname] = skin.load_bitmap(iconpath)
  135.     
  136.     return v
  137.  
  138.  
  139. def er_icon(v):
  140.     skin = skin
  141.     import gui
  142.     if v.startswith('skin:'):
  143.         return skin.get(v[5:], v)
  144.     
  145.     bitmap = skin.load_bitmap(v)
  146.     if not bitmap.Ok():
  147.         raise SkinException('invalid bitmap %s' % v)
  148.     else:
  149.         return bitmap
  150.  
  151.  
  152. def er_images(v):
  153.     for key, value in v.iteritems():
  154.         v[key] = makeImage(value)
  155.     
  156.     return v
  157.  
  158.  
  159. def er_image(v):
  160.     return makeBrush(v)
  161.  
  162.  
  163. def r_directionicons(v):
  164.     skincore = skin
  165.     import gui
  166.     img = skincore.load_image
  167.     up = None if 'up' in v else None
  168.     down = None if 'down' in v else None
  169.     left = None if 'left' in v else None
  170.     right = None if 'right' in v else None
  171.     count = len(filter(None, [
  172.         up,
  173.         down,
  174.         left,
  175.         right]))
  176.     if count == 2:
  177.         if (left or right) and up:
  178.             pass
  179.         if not down:
  180.             if not left:
  181.                 left = right.Mirror(True)
  182.             
  183.             if not right:
  184.                 right = left.Mirror(True)
  185.             
  186.             if not up:
  187.                 up = down.Mirror(False)
  188.             
  189.             if not down:
  190.                 down = up.Mirror(False)
  191.             
  192.         elif count != 4:
  193.             while not up and down and left and right:
  194.                 if not up:
  195.                     up = left.Rotate90()
  196.                 
  197.                 if not right:
  198.                     right = up.Rotate90()
  199.                 
  200.                 if not down:
  201.                     down = right.Rotate90()
  202.                 
  203.                 if not left:
  204.                     left = down.Rotate90()
  205.                     continue
  206.         
  207.     return LowerStorage({
  208.         'up': wx.BitmapFromImage(up),
  209.         'down': wx.BitmapFromImage(down),
  210.         'left': wx.BitmapFromImage(left),
  211.         'right': wx.BitmapFromImage(right) })
  212.  
  213.  
  214. def r_color(v):
  215.     return wx.Brush(colorfor(v))
  216.  
  217.  
  218. def er_fonts(v):
  219.     for key, value in v.iteritems():
  220.         v[key] = r_font(value)
  221.     
  222.     return v
  223.  
  224.  
  225. def r_fontcolor(v):
  226.     return colorfor(v)
  227.  
  228.  
  229. def r_font(v):
  230.     return makeFont(v)
  231.  
  232. erule_excludes = [
  233.     'emoticon',
  234.     'emoticons',
  235.     'buddyicons']
  236. rules = { }
  237. for func in locals().values():
  238.     if callable(func) and func.__name__.startswith('r_'):
  239.         rules[func.__name__[2:]] = func
  240.         continue
  241.  
  242. erules = { }
  243. for func in locals().values():
  244.     if callable(func) and func.__name__.startswith('er_'):
  245.         erules[func.__name__[3:]] = func
  246.         continue
  247.  
  248.