I write some simple program with Python and PyGObject. I wanted her to inform the user about the progress through the ProgressBar. I googled that this process should be a separate thread, otherwise the interface hold on, and now have some like this for tests:
import time
import threading
from gi.repository import Gtk, GObject
GObject.threads_init()
def tread_function():
progress.set_fraction(0)
time.sleep(5)
progress.set_fraction(0.25)
time.sleep(5)
progress.set_fraction(0.5)
time.sleep(5)
progress.set_fraction(0.75)
time.sleep(5)
progress.set_fraction(1)
def clickOk(*args):
t = threading.Thread(target=tread_function)
t.start()
def clickCancel(*args):
pass
buttonOk = Gtk.Button("Start Count")
buttonOk.connect("clicked", clickOk)
buttonCancel = Gtk.Button("Cancel Count")
buttonCancel.connect("clicked", clickCancel)
progress = Gtk.ProgressBar()
progress.set_show_text(True)
vBox = Gtk.VBox()
vBox.pack_start(buttonOk, True, True, 10)
vBox.pack_start(buttonCancel, True, True, 10)
vBox.pack_start(progress, True, True, 10)
window = Gtk.Window()
window.connect('destroy', Gtk.main_quit)
window.add(vBox)
window.show_all()
Gtk.main()
Now when the interface does not hold on, I would like to give a chance user to stop the work to its full completion, if he made a mistake in settings. But I can not googled, or find in documentation how to kill a thread before its complete execution.