GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 17, 2014 6:43 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: GTK+ programming style
PostPosted: Fri May 11, 2007 10:07 am 
Offline
Familiar Face

Joined: Tue Jan 23, 2007 6:13 pm
Posts: 34
I was wondering how do you write GTK+ code.
How do you design your applications?
Let's take the example that you have 3 windows for 1 application.
A main window and 2 other windows for properties and preferencies.
Then how do you communicate with each other? How do you take the information from all the entry points from these windows.
I am interested how to store the data and to pass it to all the other windows.

I personally make a structure attached to the main window GObject. Then i just pass the structure to the other windows. Then all other windows have the access to this structure and they just set your variables there.
Probably this is not very beautiful way but is only one I know.

But ... I am interested about your opinion. What do you think? How do you do all these operations?


Top
 Profile  
 
 Post subject: Re: GTK+ programming style
PostPosted: Fri May 11, 2007 1:22 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
hydra wrote:
I was wondering how do you write GTK+ code.
How do you design your applications?
Let's take the example that you have 3 windows for 1 application.
A main window and 2 other windows for properties and preferencies.
Then how do you communicate with each other? How do you take the information from all the entry points from these windows.
I am interested how to store the data and to pass it to all the other windows.


Preference and property dialogs, according to the GNOME HIG, should be non-modal. This means that you should perform setup and then use the "response" signal from the dialog to know when to interact. If I want to apply changes when a setting is changed immediately, I usually just connect signals to the dialog's widgets to watch their values.

You can also have all three of these windows in a single Glade file. If you load the Glade file, you can create it as a static variable so that is only loaded once. Then, you can just use gtk_widget_show_all() and gtk_widget_hide_all() to hide/show the dialog and never have to recreate it. Remember that if you use gtk_dialog_run(), it will be forced to be modal.

The only problem with passing your main GObject to the dialog is that you have to include its definition in the dialog's sources. This is a little backwards as you would usually include the dialog's header in the sources. (Or possibly you have a circular include structure? If so, don't do that ... :))

If you use Glade, then the dialogs will not take that much code to setup. Then, you can just connect signals to all of the widgets and the dialog to handle everything.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 12, 2007 2:21 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
If your application is a GNOME application, you can use GConf for everything. If you tinker around with the preferences dialog in Gedit for example, you'll notice that although the window is on top of the main window, settings are applied immediately AND you can still work in the editor.... non modal as Andrew mentioned.

You can be notified via signal when one of your applications preferences are changed, whether it be from your own dialog of from some other means (GConf command line or another GUI GConf editor) and update your GUI appropriately.

For modal dialogs, it's as simple as having the calling function read the values and apply settings for a GTK_RESPONSE_OK or GTK_RESPONSE_APPLY response value.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 5:52 pm 
Offline
Familiar Face

Joined: Tue Jan 23, 2007 6:13 pm
Posts: 34
Thank you for your suggestions. I am looking for a cross-platform way to achieve this goal.
My applications run on Windows as well as Linux and Solaris. So, I need some method that is not dependent on Gnome.


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 5 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