ov1d1u
ov1d1u

Reputation: 1077

gtkBuilder's get_object in a thread

It's said that you should not call GUI functions from a thread, but I'm wondering if this is applicable only when you call functions which affects GUI directly or it's applicable on every function provided by GUI library. By example, it is safe to call:

gobject.idle_add(self.gui.get_object('button1').set_sensitive, False)

in a thread? Because self.gui.get_object is a function from the GUI framework but self.gui.get_object('button1') is actually calling it.

Thank you for your answers.

Upvotes: 4

Views: 173

Answers (2)

nyxdis
nyxdis

Reputation: 416

The call you showed there seems safe. As already posted, you can read (get_object) just fine in any thread, but should only modify (set_sensitive) in the main thread. Exactly this is done here, idle_add adds the event to the main loop which is running in the main thread.

Upvotes: 1

Vivek S
Vivek S

Reputation: 5540

Threading with GUI is bit tricky.If you want to do it right, you should not update GUI from within any other thread than main thread (common limitation in GUI libs). However you can make multiple read calls from several threads.

Upvotes: 0

Related Questions