home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / uberwidgets / formattedinput2 / fontutil.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  3.6 KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from util import Storage, try_this
  5. import wx
  6. from wx import Font, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL
  7.  
  8. def FontFromFacename(facename):
  9.     return Font(10, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL, False, facename)
  10.  
  11.  
  12. def FamilyNameFromFont(font):
  13.     return font.GetFamilyString()[2:].lower()
  14.  
  15. FontAttrs = 'pointSize family style weight underline faceName encoding'.split()
  16.  
  17. def FontToTuple(font):
  18.     args = []
  19.     for a in FontAttrs:
  20.         if a == 'underline':
  21.             a = 'Underlined'
  22.         else:
  23.             a = str(a[0].upper() + a[1:])
  24.         if a == 'Encoding':
  25.             args.append(int(getattr(font, a)))
  26.             continue
  27.         args.append(getattr(font, a))
  28.     
  29.     return tuple(args)
  30.  
  31. if getattr(wx, 'WXPY', False):
  32.     
  33.     def TupleToFont(t):
  34.         t = list(t)
  35.         if len(t) >= 7:
  36.             t[6] = wx.FontEncoding(t[6])
  37.         
  38.         return Font(*t)
  39.  
  40. else:
  41.     
  42.     def TupleToFont(t):
  43.         return Font(*t)
  44.  
  45.  
  46. def StorageToFont(s):
  47.     font = None(None, Font, s.size, FONTFAMILY_DEFAULT if s.italic else wx.FONTSTYLE_NORMAL if s.bold else wx.FONTWEIGHT_NORMAL, s.underline, s.face)
  48.     fgc = s.foregroundcolor
  49.     bgc = s.backgroundcolor
  50.     return (font, fgc, bgc)
  51.  
  52.  
  53. def StyleToStorage(textattr):
  54.     font = textattr.Font
  55.     return Storage(backgroundcolor = tuple(textattr.BackgroundColour), foregroundcolor = tuple(textattr.TextColour), family = FamilyNameFromFont(font), face = font.FaceName, size = font.PointSize, underline = font.Underlined, bold = font.Weight == wx.BOLD, italic = font.Style == wx.ITALIC)
  56.  
  57.  
  58. def StyleToDict(textattr):
  59.     return dict(TextColour = tuple(textattr.GetTextColour()), BackgroundColour = tuple(textattr.GetBackgroundColour()), Font = FontToTuple(textattr.GetFont()))
  60.  
  61.  
  62. def StorageToStyle(s):
  63.     (font, fgc, bgc) = StorageToFont(s)
  64.     if not (try_this,)((lambda : wx.Colour(*fgc)), None):
  65.         pass
  66.     fgc = wx.BLACK
  67.     if not (try_this,)((lambda : wx.Colour(*bgc)), None):
  68.         pass
  69.     bgc = wx.WHITE
  70.     return wx.TextAttr(fgc, bgc, font)
  71.  
  72.