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 Dec 20, 2014 10:19 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: glade1 , glade3 + anjuta, others
PostPosted: Tue Nov 20, 2007 11:55 am 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Hello,

I am new to GTK+ programming and Linux programming in general, I am trying to understand how I can develop a small and simple application using C and GTK+.


Method 1

First of all I installed on my ubuntu 7.04 the Glade(1) version and I saw that from the application was possible to design the GUI layout and push the button generate Code. From my understading I saw that was quite good , because I got generated the files main.c , interface.c and callbacks.c . Editing the callbacks I was able to put the code behind the buttons and entries created with the glade interface. After using the make Command I found in the SRC directory of the glade project the executable to startup My program. This method was quite good , except that I had to build the code manually , because If I edit the main.c , callbacks.c etc.. with an IDE I could not get success in building the application and I had to type the command manually in shell, the same happened if I try to run the application created directly form the IDE.

Method 2

I have then searched around on the web to get more details on this programming techniques , and I found that glade1 with its automated code generator has been deprecated, now it is Recommended to use anjuta IDE in combination with Glade3. With anjuta you write the code and with glade3 only the GUI.

I read some HOWto, and if I understood well I saw that the best way to develop applications with those software is to generate a libglade 2.0 project in anjuta , then edit the file project.glade created automatically by the anjuta IDE using the glade3 program and modify the GUI design.

I did some test using this process, but I saw the files structure is changed, I ma not sure if I understood well, but in this case if I use glade3 to setup the signals and I use the auto connect features , I just need to put in the main.c file of anjuta the function that is called by the callback. I did some test and I saw it works. The alternative is to just design the GUI and then write the callback and function inside the main.c f, however the callbacks.c and the other files which were generated by glade1 are not anymore available. Using this last combination of software I was able to write the function for a simple program that prints a message on the shell as soon as a button is pressed. This code is from the main.c of anjuta libglade 2.0 project.

Code:
….
void on_BT_OK_clicked (GtkWidget *Widget, gpointer user_data)
{   
printf("ciao\n");   
}
int main (int argc, char *argv[])
{
   GtkWidget *window1;
   GladeXML *xml;

   #ifdef ENABLE_NLS
      bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
      textdomain (PACKAGE);
   #endif

   gnome_init (PACKAGE, VERSION, argc, argv);
   glade_gnome_init ();

   xml = glade_xml_new (PACKAGE_SOURCE_DIR"/esercizio_autoconnect.glade", NULL, NULL);
   glade_xml_signal_autoconnect (xml);
   window1 = glade_xml_get_widget (xml, "window1");
   gtk_widget_show (window1);
   gtk_main ();
   return 0;
}



The way of using glade3 and anjuta with the signals set in glad3 looks nice , but I do not understand where the code that was in callbacks and interface is now located. Following this method , I also tried to develop a small program which gets the data written in an entry filed and after processing it , returns the output in another entry. I followand old tutorial.

However this was written using the glade1 with the autocode generator and the function associated to the button_clicked has inside the lookup_widget
If I use glade1 then I can get this example working, if I use the method3 trying to put it in the main.c , when I build with anjuta I get an error saying that lookup_widget is undeclared.

Code:
void
on_ok_button_clicked (GtkButton *button, gpointer user_data)
{
GtkWidget *entry = lookup_widget(GTK_WIDGET(button), "entry1");
GtkWidget *info_entry = lookup_widget (GTK_WIDGET(button), "info_entry");
GtkWidget *rad_currency = lookup_widget(GTK_WIDGET(button), "rad_currency");
GtkWidget *rad_capital = lookup_widget(GTK_WIDGET(button), "rad_capital");
GtkWidget *info_label = lookup_widget(GTK_WIDGET(button), "info_label");
gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
gchar *countries[2], *capitals[2], *currencies[2];
GtkWidget *dialog, *dg_label, *dg_OK;
gint x;
countries [0] = "India"; countries [1] = "France";
capitals [0] = "Delhi"; capitals [1] = "Paris";
currencies [0] = "Rupees"; currencies [1] = "Francs";
for (x=0; x<2; x++)
{
………


What is the meaning of the lookup_widget ? If I understood well to get the text from the entry field is associated to the pointer *entry_text the gtk_entry_get_text () …
I am a bit confused…


Method 3

As I understood another method would be writing all the code on your own , I just purchased the book foundation GTK+ programming book , I think it is very good to really understand all behind the gtk+ programming technique , but I am not sure if this is what I am looking for and if this is the most common method used by programmers. In this case if I understood well you do not use glade3 + anjuta , but any IDE which uses gcc.


I would appreciate if someone can provide some comments on my considerations, I apologize if what I wrote is not correct , but I think I am a bit confused...

Thanks
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 11:56 am 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
This is the tutorial I saw with Galde1 , mentioned in my last post

http://wingtk.sourceforge.net/ishan/glade.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 6:16 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Here's my tutorial, though it too is a little outdated: Tutorial: Simple Gnome Application Using libglade and C/GTK+

The older method of glade generating code is deprecated for good reasons and you can easily find information as to why. The important thing is that using libglade is the way to go.

You can see a VERY simple example using libglade on these forums at this post: http://gtkforums.com/about187.html

Anjuta is not necessary and it might be beneficial to first dink around with compiling the programs yourself so you know what Anjuta is doing. Anjuta creates a project with it's auto tools (autoconf, automake, etc) for you. However, it can be somewhat confusing for a new user as it does a lot of things for you using what it deems to be the convention--which may change from version to version.

You could use Gedit or OpenLDev for GTK+ code too. The GUI created in glade is completely separate from the code which uses it. It's an XML file (with a .glade extension). From the glade file, you then build the widgets in your C program from the glade file using libglade. Once you have the widgets you need, you unreference the glade file and the rest writes like any other C/GTK+ program.

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:04 pm 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Micah Carrick wrote:
Here's my tutorial, though it too is a little outdated: Tutorial: Simple Gnome Application Using libglade and C/GTK+


Thank you Micah for your fast answer, I have already seen your tutorial (together with other 2/3 tutorials available on google) while trying to do some exercises during last weekend, it is helpful,

Quote:
The important thing is that using libglade is the way to go.

Hmm using libglade, you mean using the libglae through the glade software to design the GUI I think (?)

Quote:
You can see a VERY simple example using libglade on these forums at this post: http://gtkforums.com/about187.html


I think I can use this example for create the project.glade with glade and integrate it with my main.c . This is a very good example.

Quote:
Anjuta is not necessary and it might be beneficial to first dink around with compiling the programs yourself so you know what Anjuta is doing. Anjuta creates a project with it's auto tools (autoconf, automake, etc) for you. However, it can be somewhat confusing for a new user as it does a lot of things for you using what it deems to be the convention--which may change from version to version.

You could use Gedit or OpenLDev for GTK+ code too. The GUI created in glade is completely separate from the code which uses it. It's an XML file (with a .glade extension). From the glade file, you then build the widgets in your C program from the glade file using libglade. Once you have the widgets you need, you unreference the glade file and the rest writes like any other C/GTK+ program.


I agree, I got confused with it , this evening I downloaded the OpenLDEV , it is very nice and light IDE , I created a GTK+ project and I went through the examples of the foundations GTK+ book .. I am happy with it. If I understood well , I do not need to create the signals from glade3 , while I do it directly from my main.c ... I'm going to do some testing.

Sorry for the stupid questions , but I am trying to understand how it works...

Regards
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 8:36 pm 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
cannot post long messages ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 8:41 pm 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Hi I wrote a message in my text editor to put a reply to this message, but if i copy and past I get the error "The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later."

If I write the message in the form it works..


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 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