xamox
xamox

Reputation: 2779

How can I intercept GTK main loop, or have a callback event for the main function using python gtk?

I have a basic program working that displays a slider. I understand the concept of them using callbacks based on events. What I want to do is say update an image, or update the log automatically without having a user interact, so it would basically be calling this event all the time. I'm not sure if there is a callback for it or not but any suggestions would be appreciated.

Upvotes: 2

Views: 2832

Answers (2)

liberforce
liberforce

Reputation: 11454

This looks like polling, which is bad, as it's ressource consuming. In fact you should still use events, as the event that should trigger the update should be fired when your image has changed.

If you want to execute stuff in the background however, maybe what you want is an idle event handler, which is run each time the program has no more event to process. Use g_idle_add for that.

If what you want is to perform an action, say, every 5 seconds, then used a timer event instead, as Jeremy proposed. You should use g_timeout_add_seconds for a time multiple of a second (it avoids waking up the CPU for no reason, which is useful for good power management), or g_timeout_add for milliseconds granularity.

Upvotes: 3

dumbmatter
dumbmatter

Reputation: 9663

If I'm understanding you right, you can use gobject.timeout_add to do this.

Upvotes: 5

Related Questions