home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / imwin / styles / msgstyles.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  4.1 KB  |  135 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import re
  6. from gui import skin
  7. from common import pref
  8. from path import path
  9. from util import traceguard, memoize
  10. from traceback import print_exc
  11. from logging import getLogger
  12. log = getLogger('msgstyles')
  13.  
  14. class MessageStyle(object):
  15.     
  16.     def should_always_show_timestamp(self):
  17.         return getattr(self, '_ignore_show_tstamp_flag', False)
  18.  
  19.     should_always_show_timestamp = property(should_always_show_timestamp)
  20.     
  21.     def set_always_show_timestamp(self, val):
  22.         self._ignore_show_tstamp_flag = val
  23.  
  24.     
  25.     def header(self):
  26.         
  27.         try:
  28.             return ''.join((lambda .0: for header in .0:
  29. header.text())(get_user_files('Header.html')))
  30.         except Exception:
  31.             print_exc()
  32.             return ''
  33.  
  34.  
  35.     header = property(header)
  36.  
  37.  
  38. class MessageStyleException(Exception):
  39.     pass
  40.  
  41. CONVO_THEME_DIR = 'MessageStyles'
  42. msgStyleTypes = { }
  43.  
  44. def register_message_style_type(name, constructor):
  45.     msgStyleTypes[name] = constructor
  46.  
  47.  
  48. def get_user_files(filename):
  49.     import stdpaths
  50.     dirs = []
  51.     for user_themes_dir in (stdpaths.userdata / CONVO_THEME_DIR, stdpaths.config / CONVO_THEME_DIR):
  52.         fname = user_themes_dir / filename
  53.         if fname.isfile():
  54.             dirs.append(fname)
  55.             continue
  56.     
  57.     return dirs
  58.  
  59.  
  60. def get_user_themes_dirs():
  61.     import stdpaths
  62.     dirs = []
  63.     for user_themes_dir in (stdpaths.userdata / CONVO_THEME_DIR, stdpaths.config / CONVO_THEME_DIR):
  64.         traceguard.__enter__()
  65.         
  66.         try:
  67.             if not user_themes_dir.isdir():
  68.                 user_themes_dir.makedirs()
  69.         finally:
  70.             pass
  71.  
  72.         dirs.append(user_themes_dir)
  73.     
  74.     return dirs
  75.  
  76.  
  77. def get_themes():
  78.     p = skin.resourcedir() / CONVO_THEME_DIR
  79.     themes = []
  80.     userdirs = get_user_themes_dirs()
  81.     userthemes = []
  82.     for dir in userdirs:
  83.         userdir = dir.abspath()
  84.         
  85.         try:
  86.             None(userthemes.extend((lambda .0: for pth in .0:
  87. pth.abspath()) if userdir.isdir() else []))
  88.         continue
  89.         except Exception:
  90.             e = None
  91.             print_exc()
  92.             continue
  93.         
  94.  
  95.     
  96.     systemthemes = p.dirs()
  97.     subdirs = userthemes + systemthemes
  98.     for subdir in subdirs:
  99.         ext = subdir.ext[1:]
  100.         if ext in msgStyleTypes:
  101.             traceguard.__enter__()
  102.             
  103.             try:
  104.                 themes.append(msgStyleTypes[ext](subdir.abspath()))
  105.             finally:
  106.                 pass
  107.  
  108.             continue
  109.         traceguard.__exit__
  110.     
  111.     return themes
  112.  
  113. get_themes = memoize(get_themes)
  114.  
  115. def get_theme(name, variant = None):
  116.     for theme in get_themes():
  117.         if theme.theme_name == name:
  118.             theme.variant = variant
  119.             return theme
  120.     
  121.     raise MessageStyleException('theme "%s" not found' % name)
  122.  
  123.  
  124. def get_theme_safe(name, variant = None):
  125.     
  126.     try:
  127.         return get_theme(name, variant)
  128.     except Exception:
  129.         print_exc()
  130.  
  131.     BasicMessageStyle = BasicMessageStyle
  132.     import basicmsgstyle
  133.     return BasicMessageStyle()
  134.  
  135.