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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import util.primitives.functional as functional
  5. import peak.util.addons as peak
  6. import hooks
  7. import simplejson
  8. from util import Storage
  9. COMBINE_INFOBOX_CSS = False
  10.  
  11. class JScript(functional.AttrChain):
  12.     
  13.     def __init__(self):
  14.         self.script = []
  15.  
  16.     
  17.     def __call__(self, method, *a, **k):
  18.         callstr = ''.join((method, '(', ', '.join([
  19.             '%s'] * len(a)), ');'))
  20.         self.script.append(callstr % tuple((lambda .0: for arg in .0:
  21. simplejson.dumps(arg))(a)))
  22.  
  23.     
  24.     def js(self):
  25.         return '\n'.join(self.script)
  26.  
  27.  
  28.  
  29. mock_app_context = lambda **k: Storage(resource = (lambda : Storage(url = (lambda : ''))
  30. ), **k)
  31.  
  32.  
  33. def init_host(bridge, baseUrl = 'file:///infoboxapp', protocol = None):
  34.     
  35.     def get_plugin_head_content():
  36.         return hooks.each('infobox.content.head', protocol)
  37.  
  38.     plugins = Storage(head = get_plugin_head_content)
  39.     InfoboxProviderBase = InfoboxProviderBase
  40.     import providers
  41.     
  42.     class InfoboxAppProvider((None,), 'InfoboxAppProvider', (InfoboxProviderBase,)):
  43.         
  44.         def get_context(self):
  45.             context = InfoboxProviderBase.get_context(self)
  46.             context['plugins'] = plugins
  47.             return context
  48.  
  49.         
  50.         def get_app_context(self, context):
  51.             return mock_app_context(plugins = Storage(head = get_plugin_head_content))
  52.  
  53.  
  54.     ip = InfoboxAppProvider()
  55.     app_content = ip.get_html(file = 'infoboxapp.tenjin')
  56.     bridge.SetPageSource(app_content, baseUrl)
  57.  
  58.  
  59. def set_hosted_content(webview, account, infobox_js = None):
  60.     script = JScript()
  61.     key = u'%s_%s' % (account.protocol, account.username)
  62.     IInfoboxHTMLProvider = IInfoboxHTMLProvider
  63.     import interfaces
  64.     ip = IInfoboxHTMLProvider(account)
  65.     ip.load_files(ip.get_context())
  66.     dir = ip.app.get_res_dir('base')
  67.     dirty = account._dirty
  68.     if dirty:
  69.         new_content = ''
  70.         account.loaded_count = getattr(account, 'loaded_count', 0) + 1
  71.         if not getattr(account, '_did_load_head', False):
  72.             account._did_load_head = True
  73.             new_content += ip.get_html(file = 'head.tenjin', dir = dir)
  74.         
  75.         new_content += ip.get_html(file = 'content.tenjin', dir = dir)
  76.         script.updateContent(key, new_content)
  77.         account._dirty = False
  78.     
  79.     jsscript = 'callOnHide();\n'
  80.     script.swapToContent(key)
  81.     jsscript += script.js()
  82.     jsscript = SkinMemoizedCssScript(webview).get_css(jsscript)
  83.     css_url = simplejson.dumps((dir / 'infobox.css').url())
  84.     jsscript = 'document.getElementById("appCSS").setAttribute("href", %s);\n' % css_url + jsscript
  85.     if dirty:
  86.         jsscript += 'clearOnHide();\n'
  87.         if infobox_js is None:
  88.             ijs_file = dir / 'infobox.js'
  89.             if ijs_file.isfile():
  90.                 infobox_js = ijs_file.bytes()
  91.             
  92.         
  93.         if not infobox_js:
  94.             pass
  95.         infobox_js = ''
  96.         infobox_js += '\n'.join(hooks.each('infobox.content.infoboxjs', account))
  97.         jsscript += '(function() {if (window.DCallbacks !== undefined) {var D = new DCallbacks(%s);}; %s})();\n' % (simplejson.dumps(key), infobox_js)
  98.         jsscript = 'callWithInfoboxOnLoad(function() {' + jsscript + '});'
  99.         jsscript += '\ncallSwapIn(currentContentName);'
  100.     
  101.     account.last_script = jsscript
  102.     webview.RunScript(jsscript)
  103.  
  104.  
  105. class SkinMemoizedCssScript(peak.util.addons.AddOn):
  106.     
  107.     def get_css(self, script):
  108.         pref = pref
  109.         import common
  110.         skin_tuple = getattr(self, 'skin_tuple', None)
  111.         new_skin_tuple = (pref('appearance.skin'), pref('appearance.variant'))
  112.         if skin_tuple != new_skin_tuple:
  113.             self.skin_tuple = new_skin_tuple
  114.             import gui
  115.             print 'new css'
  116.             gen_css = gui.skin.get_css()
  117.             script = "$('#gen_css').html(%s);" % simplejson.dumps(gen_css) + script
  118.         
  119.         return script
  120.  
  121.  
  122.