GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Sep 20, 2014 11:59 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Communicating from a thread to a gtk window
PostPosted: Wed Nov 07, 2012 3:06 am 
Offline
Familiar Face

Joined: Wed Nov 07, 2012 2:34 am
Posts: 5
Apologies in advance, I don't have a lot of experience in multithreaded programming nor in gtk, and I'm working on this project that involves both.

I have a Python program that's currently used to crunch a bunch of numbers. I want to add a gtk interface to it to display results as they're computed, and to allow parameters to be changed while it's running... I'd also like the thread to be agnostic to the toolkit I use, so I don't want any gtk code in there.

I've moved all my calculations to a separate Python thread. The question is how to properly pass data to and from that thread. Probably a queue, sure, but more specifically, I'm not sure how to handle checking it. That is, the gtk interface is executing its own main loop. Somewhere in there, I need to regularly check some queue to see if there's a message from the thread. What's the way to do that without interfering with the main loop?

Since I don't know how to write any of this, I can't provide any sample code, but here's a simple two-part program that would exemplify what I want to do. I'd like a gtk window with a button and a number box. When the button gets pressed, I'd like the thread to sleep for a second, then randomly choose a number and put it in the number box. So basically, I want two-way communication without the thread knowing anything about gtk.

What's the right way to write code like this? Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group