The Gnome Chemistry Utils
0.13.7
|
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 3 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 GtkGrid *grid; 00071 GtkLabel *label; 00072 GtkRadioButton *btn; 00073 GSList *btn_group; 00074 00075 gtk_init (&argc, &argv); 00076 00077 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 00078 gtk_window_set_title (GTK_WINDOW (window), "GcuPeriodic test"); 00079 g_signal_connect (G_OBJECT (window), "destroy", 00080 G_CALLBACK (gtk_main_quit), 00081 NULL); 00082 00083 periodic = gcu_periodic_new (); 00084 grid = (GtkGrid *) gtk_grid_new (); 00085 label = (GtkLabel*) gtk_label_new ("Color scheme:"); 00086 gtk_grid_attach (grid, GTK_WIDGET (label), 0, 0, 1, 1); 00087 btn = (GtkRadioButton*) gtk_radio_button_new_with_label (NULL, "None"); 00088 g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_none, (gpointer) periodic); 00089 gtk_grid_attach (grid, GTK_WIDGET (btn), 1, 0, 1, 1); 00090 btn_group = gtk_radio_button_get_group (btn); 00091 btn = (GtkRadioButton*) gtk_radio_button_new_with_label (btn_group, "Default"); 00092 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE); 00093 g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_default, (gpointer) periodic); 00094 gtk_grid_attach (grid, GTK_WIDGET (btn), 2, 0, 1, 1); 00095 gtk_grid_attach (grid, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 1, 3, 1); 00096 00097 g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, "expand", TRUE, NULL); 00098 g_signal_connect (G_OBJECT (periodic), "element_changed", (GCallback) on_changed, NULL); 00099 gtk_grid_attach (grid, GTK_WIDGET (GCU_PERIODIC (periodic)), 0, 2, 3, 1); 00100 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid)); 00101 gtk_widget_show_all (window); 00102 00103 gtk_main (); 00104 00105 return 0; 00106 }