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 get_proportion (const struct binomial_dialog *bin_d, double *prop)
48 const gchar *text = gtk_entry_get_text (GTK_ENTRY (bin_d->prop_entry));
50 *prop = g_strtod (text, &endptr);
59 dialog_state_valid (gpointer data)
62 struct binomial_dialog *bin_d = data;
65 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
69 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
72 if ( ! get_proportion (bin_d, &prop))
75 if (prop < 0 || prop > 1.0)
83 refresh (struct binomial_dialog *bin_d)
85 GtkTreeModel *liststore =
86 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
88 gtk_list_store_clear (GTK_LIST_STORE (liststore));
90 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin_d->button1), TRUE);
92 gtk_entry_set_text (GTK_ENTRY (bin_d->prop_entry), "0.5");
94 gtk_entry_set_text (GTK_ENTRY (bin_d->cutpoint_entry), "");
100 generate_syntax (const struct binomial_dialog *scd)
106 string = g_string_new ("NPAR TEST\n\t/BINOMIAL");
108 if ( get_proportion (scd, &prop))
109 g_string_append_printf (string, "(%g)", prop);
111 g_string_append (string, " =");
113 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string);
115 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->cutpoint_button)))
117 const gchar *cutpoint = gtk_entry_get_text (GTK_ENTRY (scd->cutpoint_entry));
118 g_string_append_printf (string, "(%s)", cutpoint);
121 g_string_append (string, ".\n");
125 g_string_free (string, FALSE);
132 /* Pops up the Chi-Square dialog box */
134 binomial_dialog (PsppireDataWindow *dw)
138 struct binomial_dialog bin_d;
140 GtkBuilder *xml = builder_new ("binomial.ui");
143 GtkWidget *dialog = get_widget_assert (xml, "binomial-dialog");
147 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
149 g_object_get (dw->data_editor, "var-store", &vs, NULL);
151 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
153 bin_d.var_view = get_widget_assert (xml, "variables-treeview");
154 bin_d.button1 = get_widget_assert (xml, "radiobutton3");
155 bin_d.prop_entry = get_widget_assert (xml, "proportion-entry");
157 bin_d.cutpoint_entry = get_widget_assert (xml, "cutpoint-entry");
158 bin_d.cutpoint_button = get_widget_assert (xml, "radiobutton4");
160 g_object_get (vs, "dictionary", &bin_d.dict, NULL);
161 g_object_set (dict_view,
163 "predicate", var_is_numeric,
166 g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
167 bin_d.cutpoint_entry);
169 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &bin_d);
171 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
172 dialog_state_valid, &bin_d);
174 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
179 case GTK_RESPONSE_OK:
180 g_free (execute_syntax_string (dw, generate_syntax (&bin_d)));
182 case PSPPIRE_RESPONSE_PASTE:
183 g_free (paste_syntax_to_window (generate_syntax (&bin_d)));
189 g_object_unref (xml);