Hi,
In my application, I have embedded a GtkProgressBar in a stack of widgets, which are used as the title widget for a GtkNotebook page. The GtkProgressBar is supposed to get updated and be a progress indicator for a background process.
However, when using pulsing, the GtkProgressBar is not working properly. I’ve included an example application that when run shows the issue.
#!/usr/bin/python
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
import time
import threading
def run_thread(cb, widget, event):
while not event.isSet():
GLib.idle_add(cb, widget)
time.sleep(0.01)
def add_notebook_page(notebook, title, page):
box = Gtk.HBox()
overlay = Gtk.Overlay()
label = Gtk.Label(title)
stack = Gtk.Stack()
progress = Gtk.ProgressBar()
stack.add_named(progress, "progress")
overlay.add(stack)
overlay.add_overlay(label)
box.pack_start(overlay, True, True, 2)
button = Gtk.Button("X")
box.pack_start(button, False, False, 2)
box.show_all()
box.progress_ref = progress
notebook.append_page(page, box)
return
class App:
def __init__(self):
window = Gtk.Window()
window.connect("destroy", self.on_window_destroy)
box = Gtk.VBox()
button = Gtk.Button("Go")
box.pack_start(button, True, False, 0)
self.notebook = Gtk.Notebook()
page = Gtk.Label("This is a notebook page")
add_notebook_page(self.notebook, "test tab title", page)
box.pack_start(self.notebook, True, True, 0)
button.connect("clicked", self.on_button_clicked)
window.add(box)
window.show_all()
self.event = threading.Event()
self.thread = None
self.iteration = 0
def pulse(self, widget):
print "Iteration %u" % self.iteration
for i in range(widget.get_n_pages()):
child = widget.get_nth_page(i)
tab = widget.get_tab_label(child)
progress = tab.progress_ref
progress.pulse()
self.iteration += 1
return False
def on_window_destroy(self, window):
self.event.set()
if self.thread:
self.thread.join()
Gtk.main_quit()
def on_button_clicked(self, button):
self.thread = threading.Thread(
None, run_thread, "thread-1", (self.pulse, self.notebook, self.event))
self.thread.start()
if __name__ == "__main__":
app = App()
Gtk.main()
When you run the above application and hit the “Go” button, the progress bar starts being updated but then it just stops. The point at which it stops seems random.
Can anyone seem what’s wrong? Thank you.