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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  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 contextlib import contextmanager
  12. from logging import getLogger
  13. log = getLogger('msgstyles')
  14.  
  15. class MessageStyle(object):
  16.     
  17.     def should_always_show_timestamp(self):
  18.         return getattr(self, '_ignore_show_tstamp_flag', False)
  19.  
  20.     should_always_show_timestamp = property(should_always_show_timestamp)
  21.     
  22.     def set_always_show_timestamp(self, val):
  23.         self._ignore_show_tstamp_flag = val
  24.  
  25.  
  26.  
  27. class MessageStyleException(Exception):
  28.     pass
  29.  
  30. CONVO_THEME_DIR = 'MessageStyles'
  31. msgStyleTypes = { }
  32.  
  33. def register_message_style_type(name, constructor):
  34.     msgStyleTypes[name] = constructor
  35.  
  36.  
  37. def get_user_themes_dirs():
  38.     import stdpaths
  39.     dirs = []
  40.     for user_themes_dir in (stdpaths.userdata / CONVO_THEME_DIR, stdpaths.config / CONVO_THEME_DIR):
  41.         traceguard.__enter__()
  42.         
  43.         try:
  44.             if not user_themes_dir.isdir():
  45.                 user_themes_dir.makedirs()
  46.         finally:
  47.             pass
  48.  
  49.         dirs.append(user_themes_dir)
  50.     
  51.     return dirs
  52.  
  53.  
  54. def get_themes():
  55.     p = skin.resourcedir() / CONVO_THEME_DIR
  56.     themes = []
  57.     userdirs = get_user_themes_dirs()
  58.     userthemes = []
  59.     for dir in userdirs:
  60.         userdir = dir.abspath()
  61.         
  62.         try:
  63.             None(userthemes.extend((lambda .0: for pth in .0:
  64. pth.abspath()) if userdir.exists() else []))
  65.         continue
  66.         except Exception:
  67.             e = None
  68.             print_exc()
  69.             continue
  70.         
  71.  
  72.     
  73.     systemthemes = p.dirs()
  74.     subdirs = userthemes + systemthemes
  75.     for subdir in subdirs:
  76.         ext = subdir.ext[1:]
  77.         if ext in msgStyleTypes:
  78.             traceguard.__enter__()
  79.             
  80.             try:
  81.                 themes.append(msgStyleTypes[ext](subdir.abspath()))
  82.             finally:
  83.                 pass
  84.  
  85.             continue
  86.         traceguard
  87.     
  88.     return themes
  89.  
  90. get_themes = memoize(get_themes)
  91.  
  92. def get_theme(name, variant = None):
  93.     for theme in get_themes():
  94.         if theme.theme_name == name:
  95.             theme.variant = variant
  96.             return theme
  97.             continue
  98.     
  99.     raise MessageStyleException('theme "%s" not found' % name)
  100.  
  101.  
  102. def get_theme_safe(name, variant = None):
  103.     
  104.     try:
  105.         return get_theme(name, variant)
  106.     except Exception:
  107.         print_exc()
  108.  
  109.     BasicMessageStyle = BasicMessageStyle
  110.     import basicmsgstyle
  111.     return BasicMessageStyle()
  112.  
  113.