Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gtk, gobject, threading, time
- gobject.threads_init()
- class T(threading.Thread):
- pause = threading.Event()
- stop = False
- def start(self, *args):
- super(T, self).start()
- def run(self):
- while not self.stop:
- self.pause.wait()
- gobject.idle_add(self.rungui)
- time.sleep(0.1)
- def rungui(self):
- print "printed"
- class Start:
- def toggle_thread(self, *args):
- thread = T()
- if not thread.is_alive():
- thread.start()
- thread.pause.set()
- self.button.set_label('Pause Thread')
- return
- if thread.pause.is_set():
- thread.pause.clear()
- self.button.set_label('Resume Thread')
- else:
- thread.pause.set()
- self.button.set_label('Pause Thread')
- def __init__(self):
- thread = T()
- window = gtk.Window()
- self.button = gtk.ToggleButton('Start Thread')
- self.button.connect('toggled', self.toggle_thread, None)
- window.add(self.button)
- self.button.show()
- window.show()
- def main(self):
- gtk.main()
- if __name__ == "__main__":
- start = Start()
- start.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement