GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 8:31 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: how to detect gtk_main_quit
PostPosted: Wed Jun 13, 2012 10:08 pm 
Offline

Joined: Wed Jun 13, 2012 10:00 pm
Posts: 2
Hello,

I have a little GUI that mostly works. It needs to detect other hardware changing state and update the GUI, I do this with gtk_entry_set_text.
Since it needs to keep checking the hardware, I use gtk_main_iteration_do (0); which works fine, but I don't see any change in what this
function returns when the user exes out the GUI. I see a report that gtk_main_quit has been called, but gtk_main_iteration_do (0)
keeps returning 1. I tried gtk_main_level() but that didn't show a difference either. So, I just need to know how to detect the
GUI has shut down.

In case it matters, this is running on a Beagle Board (TI OMAP 3530 ARM CPU) with gtk+-2.0 and a 2.6.31.6 Linux kernel.

Thanks for any pointers anyone can provide!

Jon


Top
 Profile  
 
 Post subject: Re: how to detect gtk_main_quit
PostPosted: Thu Jun 14, 2012 6:57 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 781
Location: UK
Hi,

Not really sure what you are doing here. Have you called gtk_main() at any point? You can not quit main if you have not entered it.

Using gtk_main_iteration_do () to busy loop is generally considered bad practice when you are using it on your whole application. There are many other ways to monitor your hardware.

- If you hardware has a file descriptor monitor it. There are Glib functions to set up a call-back when there is a change in the state of the file descriptor. Such as data is available to read etc.

- Add a timer call-back function. Again in the Glib library. A call-back function is then called periodically where you can then read your hardware.

- Add an idle call-back function. Again the the Glib library. A call-back function is called when-ever Glib or GTK has nothing to do or you can set the priority to be higher, but this could mess things up if you make calls to GTK within the call-back.

- If it is available use threads, with hardware monitoring in one thread and the GUI in another. Use some sort of inter process communication to pass data between them.

Which method you use depend on what hardware you are using, how timely you need to read the data, how quickly it needs to be displayed or is it also being stored else where. Remember that most monitors update at a rate of 60Hz which is every 16.667ms.

_________________
E.


Top
 Profile  
 
 Post subject: Re: how to detect gtk_main_quit
PostPosted: Thu Jun 14, 2012 8:35 pm 
Offline

Joined: Wed Jun 13, 2012 10:00 pm
Posts: 2
errol wrote:
Hi,

Not really sure what you are doing here. Have you called gtk_main() at any point? You can not quit main if you have not entered it.


Great, thanks for the help! I added this :
g_timeout_add(1000, timer_handler, G_OBJECT (builder));
to call a function to update the GUI display every second, it works great and solves several problems.

Jon


Top
 Profile  
 
 Post subject: Re: how to detect gtk_main_quit
PostPosted: Thu Jun 14, 2012 10:37 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 781
Location: UK
Yeah!

Good that it works now, simple when you know how. Have a look around the Glib library it has many very useful things in there. This is where all the non GUI bits that GTK needs is placed.

_________________
E.


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

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 4 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group