[Glade-users] First project ....

Hi ......

I've been lurking on this list for weeks.  I'm a Linux Newbie.  When I 
discovered Glade (an earlier version that the current release) I was 
delighted.  Within minutes, I'd created a box that said "Hello World" and 
got the thing to compile and run.  Then I got a button up and running that 
produced a function in callbacks.c.  So far so good.  Getting it to do 
anything has been the problem.  When I looked on the website and took 
the latest version, at least there was an example.  A lovely little editor 
that compiled and ran and I could see how the coding is done.

BUT ......  it was all far too complicated for a C programmer with no 
knowledge of the environment .....  Please include a pack of easy start 
suff for the absolute beginner.  I needed to know about the 
documentation I needed from various sources.  Especially, I needed to 
find and get the GTK API documentation, which is excellent.  The GTK 
site also offers a C and C++ primer.  

Finally, the one thing every beginner needs to know is how to output to a 
window, and how to get text from a window.  Something like the code 
fragment I eventually made would have saved me a lot of time, so here it 

  GtkWidget *main_window, *text;
  /*  gchar *window_txt; */    /* uncomment when using the example of 
text retrieval below */

  char *mytxt="The Classic \"Hello World!\" string\n";

  /* We use the Glade utility function lookup_widget() to get a pointer to 
     widget. The first argument is any widget in the window/dialog and
     the second argument is the name of the widget you want to get. */

  main_window = lookup_widget (GTK_WIDGET (button), "window1");
  /* above line is not neccessary but avoids a warning */

  text = lookup_widget (main_window, "text1");

  /* text in window needs to be editable before you can delete it,
  assuming your window is not already an editable text window. The
  first parneter is the start point for the delete and the second is
  the end point.  Use - 0 and -1 to delete all text in the window */

  gtk_text_set_editable (GTK_TEXT (text), TRUE);
  gtk_editable_delete_text (GTK_EDITABLE (text), 0, -1);
  gtk_text_set_editable (GTK_TEXT (text), FALSE);

  /* gnome variable type gchar* is used to retrieve text.  Parameters are 
same as for
  delete (above). The function g_free() must be used after the call to get 
the text.
  Once again we need to make the text editable if it is not already so */

  gtk_text_set_editable (GTK_TEXT (text), TRUE);
  window_txt = gtk_editable_get_chars (GTK_EDITABLE (text), 0, -1);    */

  gtk_text_set_editable (GTK_TEXT (text), FALSE);  */  /* maybe you 
want to leave it editable? */

  /* it can be pasted back into the window as is, just for a test*/
  gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, window_txt, -1);  

  /* then de-allocate the buffer that was automatically created */
  /*  g_free(window_txt);    */

  /* put the famous "Hello World" string into the window */
  gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, mytxt, -1);

After all that - thanks.  I really love Glade.  Just want to make it easier for 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]