I am building an user interface using Python, Gtk3 and Glade. I want to change several things on the UI at the same time (i.e start an animation and display a new text) which leads to the application freezing.

I have read that Gtk wasn't thread safe so I didn't used the Thread module. Instead, I used Glib.idle_add and Gdk.threads_add_idle functions. I am tryig to update a treeview, display some text and show an animated logo at the same time. The application works but it freezes a few seconds and then everything appears at the same time. I try to set different priorities to the threads but it does'nt seem to fix it.

Gtk.threads_add_idle(Glib.PRIORITY_DEFAULT, label.set_text, "text_to_set")
Gtk.threads_add_igle(GLib.PRIORITY_DEFAULT, function_to_display_logo)

I expect the different texts and the treeview and the logo to be displayed without any freeze. Does anyone know how I can fix that ?

2 Answers

0
M.Brbr On Best Solutions

I found out what my error was. I was using the GLib.idle_add function too many times even in some cases where I had no use for it.

For example in the main code I had :

Glib.idle_add(my_function,buffer)

but my_function looked like this :

def myfuntion(buffer):
    GLib.idle_add(buffer.set_text,"text")

I deleted the GLib.idle_add call in the main code and now it works perfectly.

0
floppy_molly On

Please have a look here at a script example in https://github.com/f4iteightiz/UWR_scoreboard : a GTK window is updated all 0,2s for example (countdowns of several timers appearing in labels; I think anything else could be updated) and it stay reactiv the whole time. No freezing noticeable.