Hi,

works fine for me... glade fine & C file attached, compiled with "gcc
-ggdb -o gtk_test `pkg-config --cflags --libs gtk+-2.0 libglade-2.0`
gtk_test.c"

Cheers,
Dave.

Verena Mattern wrote:
> I have a problem modifying my gtk widgets. I know that you shouldn't 
> hard-code colors, but my boss wants his GUI (Buttons) in different colors. 
> Who am I to argue ;)


-- 
maemo.org docsmaster
Email: [EMAIL PROTECTED]
Jabber: [EMAIL PROTECTED]

/* This program displays a simple window and has a simple callback for
 *  * when the OK button is clicked.
 *   */

#include <gtk/gtk.h>
#include <glade/glade.h>

void
red_button_clicked (GtkWidget *widget, gpointer user_data)
{
  printf ("Red\n");
}

void
amber_button_clicked (GtkWidget *widget, gpointer user_data)
{
  printf ("Amber\n");
}

void
green_button_clicked (GtkWidget *widget, gpointer user_data)
{
  printf ("Green\n");
}

int
main (int argc, char *argv[])
{
  GladeXML  *main_window;
  GtkWidget *widget;
  GdkColor color;


  gtk_init (&argc, &argv);

  /* load the interface */
  main_window = glade_xml_new ("gtk_test.glade", NULL, NULL);

  /* connect the signals in the interface */

  /* Have the red button call the red_button_clicked callback */
  widget = glade_xml_get_widget (main_window, "button1");
  g_signal_connect (G_OBJECT (widget), "clicked",
                    G_CALLBACK (red_button_clicked),
                    NULL);
  gdk_color_parse ("red", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color);
  gdk_color_parse ("hot pink", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &color);
  gdk_color_parse ("dark red", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &color);


  /* Have the amber button call the amber_button_clicked callback */
  widget = glade_xml_get_widget (main_window, "button2");
  g_signal_connect (G_OBJECT (widget), "clicked",
                    G_CALLBACK (amber_button_clicked),
                    NULL);
  gdk_color_parse ("yellow", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color);
  gdk_color_parse ("light yellow", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &color);
  gdk_color_parse ("orange", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &color);


  /* Have the green button call the green_button_clicked callback */
  widget = glade_xml_get_widget (main_window, "button3");
  g_signal_connect (G_OBJECT (widget), "clicked",
                    G_CALLBACK (green_button_clicked),
                    NULL);
  gdk_color_parse ("green", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color);
  gdk_color_parse ("light green", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &color);
  gdk_color_parse ("dark green", &color);
  gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &color);


  /* Have the delete event (window close) end the program */
  widget = glade_xml_get_widget (main_window, "window1");
  g_signal_connect (G_OBJECT (widget), "delete_event",
                    G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show_all(widget);

  glade_xml_signal_autoconnect (main_window);

  /* start the event loop */
  gtk_main ();

  return 0;
}

Attachment: gtk_test.glade
Description: application/glade

_______________________________________________
maemo-developers mailing list
[email protected]
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to