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 Nov 22, 2014 3:33 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Odd GTK Builder Problem
PostPosted: Thu Aug 23, 2012 12:37 am 
Offline
Familiar Face

Joined: Fri Aug 03, 2012 12:06 am
Posts: 5
I am currently have a weird issue with using GTK Builder in a callback. I currently design my GUI in Glade, then use gtk_builder_get_object() to modify the object's label or callback. It works in most cases, except for just one. It's in a callback, and the code worked before. However, after making several unrelated changed, it stopped working.

Note: In my code, I displayed the labels by using gtk_builder_get_object() to grab a parent container, then I display that. Once its displayed, then I mess with the values.

Here is an abridged form of the code.

Code:
static void config_display_handler(GtkWidget *widget,
             gpointer data)
{
   int i;


   MasterStruct *master;
   ConfigStruct *config;

   GtkBuilder  *builder;

   master = data;
   config = master->active_config_ref;

   
   gchar *digit_label;
   gchar *markup;
   int *temp = (int *) g_malloc(sizeof(int) * REGULAR_CONFIG_LENGTH);

   builder = gtk_builder_new();
   gtk_builder_add_from_file(builder,
              "test1.xml",
              NULL);


   gchar *buffer = (gchar *) g_malloc(sizeof(gchar) * 20);
   GtkWidget *digits[REGULAR_CONFIG_LENGTH];


   double value = gtk_adjustment_get_value(config->adjust);

   // Extract number values to be placed onto labels by
   // placing each digit into the array   
   temp = number_to_labels_normal(value);

   // Construct label names, iterate and color, and label
   // the selected digit
   for(i = 0; i < REGULAR_CONFIG_LENGTH; i++)
   {
      sprintf(buffer, "%d", i);
      digit_label = g_strconcat("digit",buffer, NULL);
      digits[i] = GTK_LABEL(gtk_builder_get_object(builder,digit_label));
      g_print("address: %d\n", digits[i]);
      
      sprintf(buffer, "%d", temp[(REGULAR_CONFIG_LENGTH - 1)- i]);

      if(i == config->current_digit)
      {
         g_print("Printing red char\n");
         markup = g_markup_printf_escaped("<span color=\"red\">%s</span>",
                      buffer);
         gtk_label_set_markup(GTK_LABEL(digits[i]),
                    markup);
      }

      else
      {
         g_print("Printing character\n");
         markup = g_markup_printf_escaped("<span color=\"black\">%s</span>",
                                  buffer);
         gtk_label_set_markup(GTK_LABEL(digits[i]),
                    markup);

      }
   
      if(i == (REGULAR_CONFIG_LENGTH - 1) - REGULAR_DECIMAL_PLACE)
      {
         g_print("Printing period\n");
         markup = g_markup_printf_escaped("<span color=\"black\">%s</span>",
                                  ".");
         gtk_label_set_markup(GTK_LABEL(digits[i]),
                      markup);
      }
   }   
   g_free(digit_label);   
          g_free(buffer);

   g_object_unref(G_OBJECT(builder));
}


A little bit about what I already know:

I am using gtk-debug to print out the builder messages. For all other builder activity, there is debug output, but not for this particular function.

I am using Parasite to inspect the GTK widgets in real time. The addresses of the widgets using gtk_builder_get_object() do not match the address of the objects that are being displayed.

Any help would be greatly appreciated!


Top
 Profile  
 
 Post subject: Re: Odd GTK Builder Problem
PostPosted: Tue Sep 04, 2012 5:46 pm 
Offline
Familiar Face

Joined: Fri Aug 03, 2012 12:06 am
Posts: 5
Bump!


Top
 Profile  
 
 Post subject: Re: Odd GTK Builder Problem
PostPosted: Tue Sep 04, 2012 6:20 pm 
Offline
Never Seen the Sunlight

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

With only part of the needed information it is hard to work out what is really going on with your code.

Even with your code sample there are memory leaks due to allocating memory within a loop and not freeing it. Only the last allocated memory block is freed after the loop. Your code could also be simplified to make it easier to read by making better use of the Glib string functions.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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