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!