Package dtk :: Package ui :: Module threads

Source Code for Module dtk.ui.threads

 1  #! /usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3   
 4  # Copyright (C) 2011 ~ 2012 Deepin, Inc. 
 5  #               2011 ~ 2012 Wang Yong 
 6  #  
 7  # Author:     Wang Yong <lazycat.manatee@gmail.com> 
 8  # Maintainer: Wang Yong <lazycat.manatee@gmail.com> 
 9  #  
10  # This program is free software: you can redistribute it and/or modify 
11  # it under the terms of the GNU General Public License as published by 
12  # the Free Software Foundation, either version 3 of the License, or 
13  # any later version. 
14  #  
15  # This program is distributed in the hope that it will be useful, 
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18  # GNU General Public License for more details. 
19  #  
20  # You should have received a copy of the GNU General Public License 
21  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
22   
23  import gtk 
24  import threading as td 
25   
26 -def post_gui(func):
27 ''' 28 Post GUI code in main thread. 29 30 You should use post_gui wrap graphics function if function call from other threads. 31 32 Usage: 33 34 >>> @post_gui 35 >>> def graphics_fun(): 36 >>> .... 37 ''' 38 def wrap(*a, **kw): 39 gtk.gdk.threads_enter() 40 ret = func(*a, **kw) 41 gtk.gdk.threads_leave() 42 return ret
43 return wrap 44
45 -class AnonymityThread(td.Thread):
46 ''' 47 Anonymity thread. 48 ''' 49
50 - def __init__(self, callback):
51 ''' 52 Initialize AnonymityThread class. 53 54 @param callback: Callback run in thread. 55 ''' 56 td.Thread.__init__(self) 57 self.setDaemon(True) # make thread exit when main program exit 58 59 self.callback = callback
60
61 - def run(self):
62 '''Run.''' 63 self.callback()
64