1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010, 2011, 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "binomial-dialog.h"
21 #include "psppire-dialog.h"
22 #include "psppire-var-view.h"
23 #include "psppire-acr.h"
24 #include "dialog-common.h"
26 #include "builder-wrapper.h"
32 struct binomial_dialog
39 GtkWidget *prop_entry;
41 GtkWidget *cutpoint_button;
42 GtkWidget *cutpoint_entry;
46 set_sensitivity (GtkToggleButton *button, GtkWidget *w)
48 gboolean state = gtk_toggle_button_get_active (button);
49 gtk_widget_set_sensitive (w, state);
54 get_proportion (const struct binomial_dialog *bin_d, double *prop)
56 const gchar *text = gtk_entry_get_text (GTK_ENTRY (bin_d->prop_entry));
58 *prop = g_strtod (text, &endptr);
67 dialog_state_valid (gpointer data)
70 struct binomial_dialog *bin_d = data;
73 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
77 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
80 if ( ! get_proportion (bin_d, &prop))
83 if (prop < 0 || prop > 1.0)
91 refresh (struct binomial_dialog *bin_d)
93 GtkTreeModel *liststore =
94 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
96 gtk_list_store_clear (GTK_LIST_STORE (liststore));
98 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin_d->button1), TRUE);
100 gtk_entry_set_text (GTK_ENTRY (bin_d->prop_entry), "0.5");
102 gtk_entry_set_text (GTK_ENTRY (bin_d->cutpoint_entry), "");
108 generate_syntax (const struct binomial_dialog *scd)
114 string = g_string_new ("NPAR TEST\n\t/BINOMIAL");
116 if ( get_proportion (scd, &prop))
117 g_string_append_printf (string, "(%g)", prop);
119 g_string_append (string, " =");
121 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string);
123 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->cutpoint_button)))
125 const gchar *cutpoint = gtk_entry_get_text (GTK_ENTRY (scd->cutpoint_entry));
126 g_string_append_printf (string, "(%s)", cutpoint);
129 g_string_append (string, ".\n");
133 g_string_free (string, FALSE);
140 /* Pops up the Chi-Square dialog box */
142 binomial_dialog (PsppireDataWindow *dw)
146 struct binomial_dialog bin_d;
148 GtkBuilder *xml = builder_new ("binomial.ui");
151 GtkWidget *dialog = get_widget_assert (xml, "binomial-dialog");
155 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
157 g_object_get (dw->data_editor, "var-store", &vs, NULL);
159 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
161 bin_d.var_view = get_widget_assert (xml, "variables-treeview");
162 bin_d.button1 = get_widget_assert (xml, "radiobutton3");
163 bin_d.prop_entry = get_widget_assert (xml, "proportion-entry");
165 bin_d.cutpoint_entry = get_widget_assert (xml, "cutpoint-entry");
166 bin_d.cutpoint_button = get_widget_assert (xml, "radiobutton4");
168 g_object_get (vs, "dictionary", &bin_d.dict, NULL);
169 g_object_set (dict_view,
171 "predicate", var_is_numeric,
174 g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity),
175 bin_d.cutpoint_entry);
177 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &bin_d);
179 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
180 dialog_state_valid, &bin_d);
182 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
187 case GTK_RESPONSE_OK:
188 g_free (execute_syntax_string (dw, generate_syntax (&bin_d)));
190 case PSPPIRE_RESPONSE_PASTE:
191 g_free (paste_syntax_to_window (generate_syntax (&bin_d)));
197 g_object_unref (xml);