The Gnome Chemistry Utils  0.12.13
testgcuperiodic.c
Go to the documentation of this file.
1 /*
2  * Gnome Chemisty Utils
3  * tests/testgcuperiodic.c
4  *
5  * Copyright (C) 2008-2010 Jean Bréfort <jean.brefort@normalesup.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include <gcu/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  GtkVBox* vbox;
71  GtkHBox* hbox;
72  GtkLabel* label;
73  GtkRadioButton *btn;
74  GSList* btn_group;
75 
76  gtk_init (&argc, &argv);
77 
78  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
79  gtk_window_set_title (GTK_WINDOW (window), "GcuPeriodic test");
80  g_signal_connect (G_OBJECT (window), "destroy",
81  G_CALLBACK (gtk_main_quit),
82  NULL);
83 
84  g_object_set (G_OBJECT (window), "allow-shrink", FALSE, NULL);
85 
86  periodic = gcu_periodic_new ();
87  vbox = (GtkVBox*) gtk_vbox_new (FALSE, 0);
88  hbox = (GtkHBox*) gtk_hbox_new (FALSE, 0);
89  label = (GtkLabel*) gtk_label_new ("Color scheme:");
90  gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label), TRUE, TRUE, 0);
91  btn = (GtkRadioButton*) gtk_radio_button_new_with_label (NULL, "None");
92  g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_none, (gpointer) periodic);
93  gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (btn), TRUE, TRUE, 0);
94  btn_group = gtk_radio_button_get_group (btn);
95  btn = (GtkRadioButton*) gtk_radio_button_new_with_label (btn_group, "Default");
96  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (btn), TRUE);
97  g_signal_connect (G_OBJECT (btn), "toggled", (GCallback) on_color_scheme_default, (gpointer) periodic);
98  gtk_box_pack_end (GTK_BOX (hbox), GTK_WIDGET (btn), TRUE, TRUE, 0);
99  gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), TRUE, TRUE, 0);
100  gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), TRUE, TRUE, 0);
101 
102  g_object_set (G_OBJECT (periodic), "color-style", GCU_PERIODIC_COLOR_DEFAULT, NULL);
103  g_signal_connect (G_OBJECT (periodic), "element_changed", (GCallback) on_changed, NULL);
104  gtk_box_pack_end (GTK_BOX (vbox), GTK_WIDGET (GCU_PERIODIC (periodic)), TRUE, TRUE, 0);
105  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
106  gtk_widget_show_all (window);
107 
108  gtk_main ();
109 
110  return 0;
111 }