Hi,
We are trying to create a gtk application which should run without much of
manual intervention. Few buttons are placed in a row and each button has
an image at the top which changes to red on selection. This image changes
to green when the button goes out of selection. So the whole process has
to be done in a scan mode without any manual intervention.
The problem with our code (attached with this mail) is that the events are
generated and the callback functions are called. But the window is not
refreshed properly. The window gets updated only when there is any
mouse/keyboard movement.
Thanks in Advance,
Regards
Nisha
---
Nisha P Kurur
DON Lab (BSB 328)
Dept. of CSE
IITM, Chennai - 36
Phone (044) 2257 5364/9804/9853
--#include common.h
GtkWidget *window;
GtkWidget *table;
GtkWidget *button[9];
GtkWidget *image_enable[9];
static void button_pressed_callback(GtkWidget *widget, GdkEvent *event,
gpointer image);
static void button_released_callback(GtkWidget *widget, GdkEvent *event,
gpointer image);
void button_selection();
/* Create a new hbox with an image and a label packed into it
* and return the box. */
static GtkWidget *xpm_label_box(gchar *label_text, gchar *xpm_filename)
{
GtkWidget *box;
GtkWidget *label;
GtkWidget *image;
/* Create box for image and label */
box = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 2);
/* Now on to the image stuff */
image = gtk_image_new_from_file (xpm_filename);
/* Create a label for the button */
label = gtk_label_new (label_text);
/* Pack the image and label into the box */
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3);
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 3);
gtk_widget_show (label);
gtk_widget_show (image);
return box;
}
/*
static void hiding_showing_images(GtkWidget *widget, gint index)
{
GtkWidget *image;
// guint index = (guint *)img;
g_print(INDEX = %d, FLAG = %d \n,index ,flag);
if(flag == 1)
{
g_print(INSIDE LEAVE\n);
gtk_widget_hide(image_enable[index-1]);
image = gtk_image_new_from_file(radio_green.jpg);
gtk_table_attach_defaults (GTK_TABLE (table), image, index-1,
index, 0, 1);
gtk_widget_show (image);
image_enable[index-1] = image;
flag = 0;
}
else
{
g_print(INSIDE ENTER\n);
gtk_widget_hide(image_enable[index-1]);
image = gtk_image_new_from_file(radio_red.jpg);
gtk_table_attach_defaults (GTK_TABLE (table), image, index-1,
index, 0, 1);
gtk_widget_show (image);
image_enable[index-1] = image;
flag = 1;
}
}
*/
/* Callback method */
static void button_released_callback(GtkWidget *widget, GdkEvent *event,
gpointer img)
{
GtkWidget *image;
guint index = (guint *)img;
g_print(INSIDE LEAVE\n);
gtk_widget_hide(image_enable[index-1]);
image = gtk_image_new_from_file(radio_green.jpg);
gtk_table_attach_defaults (GTK_TABLE (table), image, index-1, index, 0,
1);
gtk_widget_show (image);
image_enable[index-1] = image;
}
static void button_pressed_callback(GtkWidget *widget, GdkEvent *event,
gpointer img)
{
GtkWidget *image;
guint index = (guint *)img;
g_print(INSIDE ENTER\n);
gtk_widget_hide(image_enable[index-1]);
image = gtk_image_new_from_file(radio_red.jpg);
gtk_table_attach_defaults (GTK_TABLE (table), image, index-1, index, 0,
1);
gtk_widget_show (image);
image_enable[index-1] = image;
}
static GtkWidget *create_button(guint index)
{
GtkWidget *box;
GtkWidget *button;
GtkWidget *image;
image = gtk_image_new_from_file(radio_green.jpg);
button = gtk_button_new();
switch(index)
{
case 1:
{
box = xpm_label_box( ABC , soccer.gif);
gtk_container_add (GTK_CONTAINER (button), box);
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
gtk_table_attach_defaults (GTK_TABLE (table), image, 0, 1, 0, 1);
image_enable[0] = image;
g_signal_connect(G_OBJECT(button), button_press_event,
G_CALLBACK (button_pressed_callback), (gpointer)index);
g_signal_connect(G_OBJECT(button), button_release_event,
G_CALLBACK(button_released_callback), (gpointer)index);
break;
}
case 2:
{
box = xpm_label_box( DEF , soccer.gif);
gtk_container_add (GTK_CONTAINER (button), box);