home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / tests / testapp.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  6.1 KB  |  189 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import sys
  5. import wx
  6. import ctypes
  7.  
  8. try:
  9.     ctypes.windll.dwmapi
  10. except Exception:
  11.     pass
  12.  
  13. import gui.vista as gui
  14. import digsbysite
  15. import util
  16. import stdpaths
  17. from util.primitives.funcs import Delegate
  18. from util.primitives.mapping import Storage
  19.  
  20. def discover_digsby_root():
  21.     import os.path as os
  22.     return os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
  23.  
  24.  
  25. def _isdigsbyroot(p):
  26.     print >>sys.stderr, 'isdigsbyroot?', p
  27.     return (p / 'res' / 'skins' / 'default').isdir()
  28.  
  29.  
  30. class TestApp(wx.App):
  31.     
  32.     def __enter__(self):
  33.         pass
  34.  
  35.     
  36.     def __exit__(self, exc_type, exc_value, tb):
  37.         if exc_type is None:
  38.             self.MainLoop()
  39.         
  40.  
  41.  
  42. wxMSW = 'wxMSW' in wx.PlatformInfo
  43.  
  44. def testapp(pypath = None, appname = 'Digsby', skinname = 'default', prefs = None, username = 'megazord', on_message = (lambda message: pass), plugins = True, logging = True):
  45.     if wxMSW:
  46.         preload_comctrls()
  47.     
  48.     import gettext
  49.     import os.path as os
  50.     import options
  51.     (sys.opts, _args) = options.parser.parse_args()
  52.     import logextensions
  53.     digsbysite.COLORIZE_EXCEPTIONS = sys.opts.console_color
  54.     gettext.install(appname, unicode = True)
  55.     app = TestApp()
  56.     app.SetAppName(appname)
  57.     init = init
  58.     import stdpaths
  59.     init()
  60.     if wxMSW:
  61.         import gui.native.win.winutil as winutil
  62.         winutil.disable_callback_filter()
  63.     
  64.     skin = skin
  65.     import gui
  66.     setuplogging = setuplogging
  67.     import gui.toolbox
  68.     if logging:
  69.         import logging
  70.         setuplogging(level = logging.INFO)
  71.     
  72.     wx.Log.SetActiveTarget(wx.LogStderr())
  73.     app.PreShutdown = Delegate()
  74.     if pypath is None:
  75.         pypath = discover_digsby_root()
  76.     
  77.     sys.path.insert(0, pypath)
  78.     skin.set_resource_paths([
  79.         util.program_dir() / 'res',
  80.         stdpaths.userdata,
  81.         stdpaths.config])
  82.     if plugins:
  83.         init_plugins = init_plugins
  84.         import main
  85.         app.plugins = init_plugins()
  86.     else:
  87.         app.plugins = []
  88.     skin.skininit(os.path.join(pypath, 'res'), skinname = skinname)
  89.     ThreadPool = ThreadPool
  90.     import util.threads.threadpool
  91.     ThreadPool(5)
  92.     flatten = flatten
  93.     import prefs.prefsdata
  94.     import syck
  95.     ObservableDict = ObservableDict
  96.     import util.observe
  97.     prefs_path = os.path.join(pypath, 'res', 'defaults.yaml')
  98.     prefs = None if prefs is not None else ObservableDict()
  99.     prefs.update({
  100.         'appearance.skin': skinname,
  101.         'appearance.variant': None,
  102.         'debug.shell.font': shellfont() })
  103.     import common
  104.     common.set_active_prefs(prefs, { })
  105.     ObservableDict = ObservableDict
  106.     import util.observe
  107.     sys.modules['digsbyprofile'] = Storage()
  108.     import digsbyprofile
  109.     default_notifications = default_notifications
  110.     import common.notifications
  111.     p = digsbyprofile.profile = Storage(name = username, username = username, prefs = prefs, on_message = on_message, notifications = default_notifications)
  112.     f = file(prefs_path)
  113.     defaults = Storage(flatten(syck.load(f)))
  114.     f.close()
  115.     user = ObservableDict(defaults)
  116.     user.update(prefs)
  117.     localprefs = localprefs
  118.     import prefs.prefsdata
  119.     import prefs
  120.     p.defaultprefs = prefs.defaultprefs()
  121.     p.localprefs = localprefs()
  122.     import common
  123.     common.setfakeprefs(user)
  124.     
  125.     def toggle_prefs(user = user, defaults = defaults):
  126.         import prefs
  127.         prefs.edit(user, defaults, None)
  128.  
  129.     
  130.     def toggle_crust(app = app):
  131.         if not getattr(app, 'crust', None):
  132.             import gui.shell as gui
  133.             wins = wx.GetTopLevelWindows()
  134.             parent = None if wins else None
  135.             app.crust = gui.shell.PyCrustFrame(None)
  136.             if parent is not None:
  137.                 parent.crust = app.crust
  138.             
  139.             app.crust.Bind((wx.EVT_CLOSE,), (lambda evt: app.Exit()))
  140.         
  141.         app.crust.toggle_shown()
  142.         if app.crust.IsShown():
  143.             app.crust.crust.SetFocus()
  144.         
  145.  
  146.     
  147.     def on_key(e):
  148.         code = e.GetKeyCode()
  149.         if code == wx.WXK_F11:
  150.             toggle_prefs()
  151.         elif code == wx.WXK_F12:
  152.             toggle_crust()
  153.         elif code == wx.WXK_F5:
  154.             skin = skin
  155.             import gui
  156.             skin.reload()
  157.         else:
  158.             e.Skip()
  159.  
  160.     app.Bind(wx.EVT_KEY_DOWN, on_key)
  161.     app.toggle_crust = toggle_crust
  162.     initialize_webkit = initialize_webkit
  163.     SetStatusPrompt = SetStatusPrompt
  164.     import main
  165.     initialize_webkit()
  166.     app.SetStatusPrompt = SetStatusPrompt
  167.     return app
  168.  
  169. if 'wxMSW' in wx.PlatformInfo:
  170.     
  171.     def preload_comctrls():
  172.         windll = windll
  173.         import ctypes
  174.         windll.comctl32.InitCommonControls()
  175.  
  176.  
  177.  
  178. def shellfont():
  179.     
  180.     try:
  181.         import ctypes
  182.         ctypes.windll.dwmapi
  183.     except:
  184.         font = 'Courier New'
  185.  
  186.     font = 'Consolas'
  187.     return font
  188.  
  189.