Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Python async tkcontext

By: a guest on Oct 15th, 2012  |  syntax: Python  |  size: 0.97 KB  |  views: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import threading
  2.  
  3. import contexts
  4.  
  5. class TkContext(contexts.CallableContext):
  6.     def __init__(self, app):
  7.         self.app = app
  8.         self._post_signal = threading.Condition()
  9.  
  10.     @staticmethod
  11.     def invoke(callable, args, kwargs):
  12.         callable(*args, **kwargs)
  13.  
  14.     @staticmethod
  15.     def invoke_and_notify(signal, callable, args, kwargs):
  16.         with signal:
  17.             callable(*args, **kwargs)
  18.             signal.notify_all()
  19.  
  20.     def post(self, callable, *args, **kwargs):
  21.         '''Adds a callable to invoke within this context.'''
  22.         self.app.after(0, TkContext.invoke, callable, args, kwargs)
  23.  
  24.     def submit(self, callable, *args, **kwargs):
  25.         '''Adds a callable to invoke within this context and returns when it
  26.        has been completed.
  27.        '''
  28.         with self._post_signal:
  29.             self.app.after(0, TkContext.invoke_and_notify, self._post_signal, callable, args, kwargs)
  30.             self._post_signal.wait()
clone this paste RAW Paste Data