The Gnome Chemistry Utils 0.13.3
|
00001 /* 00002 * Gnome Chemisty Utils 00003 * tests/testgcuperiodic.c 00004 * 00005 * Copyright (C) 2008-2011 Jean Bréfort <jean.brefort@normalesup.org> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of the 00010 * License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00020 * USA 00021 */ 00022 00023 #include <gcugtk/gcuperiodic.h> 00024 #include <gcu/chemistry.h> 00025 #include <glib.h> 00026 #include <gtk/gtk.h> 00027 #include <stdio.h> 00028 00037 void on_changed (G_GNUC_UNUSED GcuPeriodic* periodic, guint Z, G_GNUC_UNUSED gpointer data) 00038 { 00039 printf ("Selected element:%d\n", Z); 00040 } 00041 00046 void on_color_scheme_none (GtkToggleButton* btn, GtkWidget* periodic) 00047 { 00048 if (gtk_toggle_button_get_active (btn)) 00049 g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_NONE, NULL); 00050 } 00051 00056 void on_color_scheme_default (GtkToggleButton* btn, GtkWidget* periodic) 00057 { 00058 if (gtk_toggle_button_get_active (btn)) 00059 g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, NULL); 00060 } 00061 00066 int main (int argc, char *argv[]) 00067 { 00068 GtkWidget *window; 00069 GtkWidget *periodic; 00070 GtkVBox* vbox; 00071 GtkHBox* hbox; 00072 GtkLabel* label; 00073 GtkRadioButton *btn; 00074 GSList* btn_group; 00075 00076 gtk_init (&argc, &argv); 00077 00078 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 00079 gtk_window_set_title (GTK_WINDOW (window), "GcuPeriodic test"); 00080 g_signal_connect (G_OBJECT (window), "destroy", 00081 G_CALLBACK (gtk_main_quit), 00082 NULL); 00083 00084 g_object_set (G_OBJECT (window), "allow-shrink", FALSE, NULL); 00085 00086 periodic = gcu_periodic_new (); 00087 vbox = (GtkVBox*) gtk_vbox_new (FALSE, 0); 00088 hbox = (GtkHBox*) gtk_hbox_new (FALSE, 0); 00089 label = (GtkLabel*) gtk_label_new ("Color scheme:"); 00090 gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label), TRUE, TRUE, 0); 00091 btn = (GtkRadioButton*) gtk_radio_button_new_with_label (NULL, "None"); 00092 g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_none, (gpointer) periodic); 00093 gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (btn), TRUE, TRUE, 0); 00094 btn_group = gtk_radio_button_get_group (btn); 00095 btn = (GtkRadioButton*) gtk_radio_button_new_with_label (btn_group, "Default"); 00096 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE); 00097 g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_default, (gpointer) periodic); 00098 gtk_box_pack_end (GTK_BOX (hbox), GTK_WIDGET (btn), TRUE, TRUE, 0); 00099 gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), TRUE, TRUE, 0); 00100 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), TRUE, TRUE, 0); 00101 00102 g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, NULL); 00103 g_signal_connect (G_OBJECT (periodic), "element_changed", (GCallback) on_changed, NULL); 00104 gtk_box_pack_end (GTK_BOX (vbox), GTK_WIDGET (GCU_PERIODIC (periodic)), TRUE, TRUE, 0); 00105 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox)); 00106 gtk_widget_show_all (window); 00107 00108 gtk_main (); 00109 00110 return 0; 00111 }