The Gnome Chemistry Utils: testgtkperiodic.c Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# testgtkperiodic.c

Go to the documentation of this file.

    00001 #include <gcu/gtkperiodic.h>
    00002 #include <gcu/chemistry.h>
    00003 #include <glib.h>
    00004 #include <gtk/gtk.h>
    00005 #include <stdio.h>
    00006
    00015 void on_changed (GtkPeriodic* periodic, guint Z, gpointer data)
    00016 {
    00017         printf ("Selected element:%d\n", Z);
    00018 }
    00019
    00024 void on_color_scheme_none (GtkToggleButton* btn, GtkWidget* periodic)
    00025 {
    00026         if (gtk_toggle_button_get_active (btn))
    00027                 g_object_set (G_OBJECT (periodic), "color-style", GTK_PERIODIC_COLOR_NONE, NULL);
    00028 }
    00029
    00034 void on_color_scheme_default (GtkToggleButton* btn, GtkWidget* periodic)
    00035 {
    00036         if (gtk_toggle_button_get_active (btn))
    00037                 g_object_set (G_OBJECT (periodic), "color-style", GTK_PERIODIC_COLOR_DEFAULT, NULL);
    00038 }
    00039
    00044 int main (int argc, char *argv[])
    00045 {
    00046         GtkWidget *window;
    00047         GtkWidget *periodic;
    00048         GtkVBox* vbox;
    00049         GtkHBox* hbox;
    00050         GtkLabel* label;
    00051         GtkRadioButton *btn;
    00052         GSList* btn_group;
    00053
    00054         gtk_init (&argc, &argv);
    00055
    00056         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    00057         gtk_window_set_title (GTK_WINDOW (window), "GtkPeriodic test");
    00058         g_signal_connect (G_OBJECT (window), "destroy",
    00059                  G_CALLBACK (gtk_main_quit),
    00060                  NULL);
    00061
    00062         g_object_set (G_OBJECT (window), "allow-shrink", FALSE, NULL);
    00063
    00064         periodic = gtk_periodic_new ();
    00065         vbox = (GtkVBox*) gtk_vbox_new (FALSE, 0);
    00066         hbox = (GtkHBox*) gtk_hbox_new (FALSE, 0);
    00067         label = (GtkLabel*) gtk_label_new ("Color scheme:");
    00068         gtk_box_pack_start_defaults (GTK_BOX (hbox), GTK_WIDGET (label));
    00069         btn = (GtkRadioButton*) gtk_radio_button_new_with_label (NULL, "None");
    00070         g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_none, (gpointer) periodic);
    00071         gtk_box_pack_start_defaults (GTK_BOX (hbox), GTK_WIDGET (btn));
    00072         btn_group = gtk_radio_button_get_group (btn);
    00073         btn = (GtkRadioButton*) gtk_radio_button_new_with_label (btn_group, "Default");
    00074         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE);
    00075         g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_default, (gpointer) periodic);
    00076         gtk_box_pack_end_defaults (GTK_BOX (hbox), GTK_WIDGET (btn));
    00077         gtk_box_pack_start_defaults (GTK_BOX (vbox), GTK_WIDGET (hbox));
    00078         gtk_box_pack_start_defaults (GTK_BOX (vbox), gtk_hseparator_new ());
    00079
    00080         g_object_set (G_OBJECT (periodic), "color-style", GTK_PERIODIC_COLOR_DEFAULT, NULL);
    00081         g_signal_connect (G_OBJECT (periodic), "element_changed", (GCallback) on_changed, NULL);
    00082         gtk_box_pack_end_defaults (GTK_BOX (vbox), GTK_WIDGET (GTK_PERIODIC (periodic)));
    00083         gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
    00084         gtk_widget_show_all (window);
    00085
    00086         gtk_main ();
    00087
    00088         return 0;
    00089 }