home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / events.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  2.3 KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import wx
  6. import pprint
  7. import traceback
  8. import sys
  9. from threading import currentThread
  10. from weakref import ref
  11. MAINTHREAD_NAME = 'MainThread'
  12.  
  13. class ThreadsafeGUIProxy(object):
  14.     
  15.     def __init__(self, target):
  16.         self.target = target
  17.  
  18.     
  19.     def __getattr__(self, attr):
  20.         method = getattr(self.target, attr)
  21.         if currentThread().getName() == MAINTHREAD_NAME:
  22.             return (lambda : method(*a, **k))
  23.         return (lambda : wx.CallAfter(method, *a, **k))
  24.  
  25.  
  26. from traceback import print_exc
  27.  
  28. def callevent(e):
  29.     e.ref = None
  30.     
  31.     try:
  32.         for callAfterCallback, a, k in e._callables:
  33.             
  34.             try:
  35.                 callAfterCallback(*a, **k)
  36.             continue
  37.             except Exception:
  38.                 e = None
  39.                 print_exc()
  40.                 continue
  41.             
  42.  
  43.     except AttributeError:
  44.         e.callable(*e.args, **e.kw)
  45.  
  46.  
  47. from wx import GetApp, NewEventType, PyEvent
  48.  
  49. def CallAfterCombining(callable, *args, **kw):
  50.     app = GetApp()
  51.     
  52.     try:
  53.         r = app._last
  54.     except AttributeError:
  55.         pass
  56.  
  57.     e = r()
  58.     if e is not None and e.ref is r:
  59.         return e._callables.append((callable, args, kw))
  60.     
  61.     try:
  62.         evt = PyEvent(0, app._CallAfterId)
  63.     except AttributeError:
  64.         e.ref is r
  65.         e.ref is r
  66.         id = app._CallAfterId = NewEventType()
  67.         app.Connect(-1, -1, id, callevent)
  68.         evt = PyEvent(0, id)
  69.     except:
  70.         e.ref is r
  71.  
  72.     evt._callables = [
  73.         (callable, args, kw)]
  74.     app.AddPendingEvent(evt)
  75.  
  76.