The Gnome Chemistry Utils  0.14.0
testgcuperiodic.c
Go to the documentation of this file.
1 /*
2  * Gnome Chemisty Utils
3  * tests/testgcuperiodic.c
4  *
5  * Copyright (C) 2008-2011 Jean Bréfort <jean.brefort@normalesup.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #include <gcugtk/gcuperiodic.h>
24 #include <gcu/chemistry.h>
25 #include <glib.h>
26 #include <gtk/gtk.h>
27 #include <stdio.h>
28 
37 void on_changed (G_GNUC_UNUSED GcuPeriodic* periodic, guint Z, G_GNUC_UNUSED gpointer data)
38 {
39  printf ("Selected element:%d\n", Z);
40 }
41 
46 void on_color_scheme_none (GtkToggleButton* btn, GtkWidget* periodic)
47 {
48  if (gtk_toggle_button_get_active (btn))
49  g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_NONE, NULL);
50 }
51 
56 void on_color_scheme_default (GtkToggleButton* btn, GtkWidget* periodic)
57 {
58  if (gtk_toggle_button_get_active (btn))
59  g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, NULL);
60 }
61 
66 int main (int argc, char *argv[])
67 {
68  GtkWidget *window;
69  GtkWidget *periodic;
70  GtkGrid *grid;
71  GtkLabel *label;
72  GtkRadioButton *btn;
73  GSList *btn_group;
74 
75  gtk_init (&argc, &argv);
76 
77  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
78  gtk_window_set_title (GTK_WINDOW (window), "GcuPeriodic test");
79  g_signal_connect (G_OBJECT (window), "destroy",
80  G_CALLBACK (gtk_main_quit),
81  NULL);
82 
83  periodic = gcu_periodic_new ();
84  grid = (GtkGrid *) gtk_grid_new ();
85  label = (GtkLabel*) gtk_label_new ("Color scheme:");
86  gtk_grid_attach (grid, GTK_WIDGET (label), 0, 0, 1, 1);
87  btn = (GtkRadioButton*) gtk_radio_button_new_with_label (NULL, "None");
88  g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_none, (gpointer) periodic);
89  gtk_grid_attach (grid, GTK_WIDGET (btn), 1, 0, 1, 1);
90  btn_group = gtk_radio_button_get_group (btn);
91  btn = (GtkRadioButton*) gtk_radio_button_new_with_label (btn_group, "Default");
92  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE);
93  g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_default, (gpointer) periodic);
94  gtk_grid_attach (grid, GTK_WIDGET (btn), 2, 0, 1, 1);
95  gtk_grid_attach (grid, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 1, 3, 1);
96 
97  g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, "expand", TRUE, NULL);
98  g_signal_connect (G_OBJECT (periodic), "element_changed", (GCallback) on_changed, NULL);
99  gtk_grid_attach (grid, GTK_WIDGET (GCU_PERIODIC (periodic)), 0, 2, 3, 1);
100  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid));
101  gtk_widget_show_all (window);
102 
103  gtk_main ();
104 
105  return 0;
106 }