# BlinkingTextGTK.py (c) Kari Laitinen # 2006-08-22 File created. # 2006-08-22 Last modification. import gtk from threading import Thread from threading import Event from time import sleep #Initializing the gtk's thread engine gtk.threads_init() class AnimationThread ( Thread ) : def __init__( self, given_label ) : Thread.__init__( self ) self.label_in_window = given_label self.thread_must_be_stopped = Event() print " thread init done " def stop_this_thread( self ) : self.thread_must_be_stopped.set() def run( self ) : self.text_must_be_shown = True while not self.thread_must_be_stopped.isSet() : print " %s " % self.thread_must_be_stopped.isSet(), # Acquiring the gtk global mutex gtk.threads_enter() if self.text_must_be_shown == True : self.label_in_window.set_text( "HELLO" ) self.text_must_be_shown = False else : self.label_in_window.set_text( "" ) self.text_must_be_shown = True # Releasing the gtk global mutex gtk.threads_leave() sleep( 1.0 ) print " yy ", print " run method ends " class BlinkingText : def __init__( self ) : self.application_window = gtk.Window( gtk.WINDOW_TOPLEVEL ) self.application_window.set_title( "ANIMATION BY USING A THREAD" ) self.application_window.connect( "destroy", self.exit_this_application ) self.application_window.set_size_request( 600, 500 ) self.label_for_the_text = gtk.Label( "HELLO" ) self.application_window.add( self.label_for_the_text ) self.label_for_the_text.show() self.application_window.show() self.animation_thread = AnimationThread( self.label_for_the_text ) self.animation_thread.start() print " init done " def run( self ) : gtk.main() def exit_this_application( self, widget, data=None ) : self.animation_thread.stop_this_thread() gtk.main_quit() print "exit called" if __name__ == "__main__": this_application = BlinkingText() this_application.run()