 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
hydra Familiar Face
Joined: 23 Jan 2007 Posts: 35
|
Posted: Fri May 11, 2007 10:07 am Post subject: GTK+ programming style |
|
|
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? |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 386 Location: Fairfax, Virginia
|
Posted: Fri May 11, 2007 1:22 pm Post subject: Re: GTK+ programming style |
|
|
| 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. |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 481 Location: Portland, OR USA
|
Posted: Sat May 12, 2007 2:21 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
hydra Familiar Face
Joined: 23 Jan 2007 Posts: 35
|
Posted: Sun May 13, 2007 5:52 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|