1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2010 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 <language/syntax-string-source.h>
23 #include "psppire-dialog.h"
24 #include "psppire-var-view.h"
25 #include "psppire-acr.h"
26 #include "dialog-common.h"
34 struct binomial_dialog
41 GtkWidget *prop_entry;
43 GtkWidget *cutpoint_button;
44 GtkWidget *cutpoint_entry;
48 set_sensitivity (GtkToggleButton *button, GtkWidget *w)
50 gboolean state = gtk_toggle_button_get_active (button);
51 gtk_widget_set_sensitive (w, state);
56 get_proportion (const struct binomial_dialog *bin_d, double *prop)
58 const gchar *text = gtk_entry_get_text (GTK_ENTRY (bin_d->prop_entry));
60 *prop = g_strtod (text, &endptr);
69 dialog_state_valid (gpointer data)
72 struct binomial_dialog *bin_d = data;
75 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
79 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
82 if ( ! get_proportion (bin_d, &prop))
85 if (prop < 0 || prop > 1.0)
93 refresh (struct binomial_dialog *bin_d)
95 GtkTreeModel *liststore =
96 gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view));
98 gtk_list_store_clear (GTK_LIST_STORE (liststore));
100 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin_d->button1), TRUE);
102 gtk_entry_set_text (GTK_ENTRY (bin_d->prop_entry), "0.5");
104 gtk_entry_set_text (GTK_ENTRY (bin_d->cutpoint_entry), "");
110 generate_syntax (const struct binomial_dialog *scd)
116 string = g_string_new ("NPAR TEST\n\t/BINOMIAL");
118 if ( get_proportion (scd, &prop))
119 g_string_append_printf (string, "(%g)", prop);
121 g_string_append (string, " =");
123 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string);
125 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->cutpoint_button)))
127 const gchar *cutpoint = gtk_entry_get_text (GTK_ENTRY (scd->cutpoint_entry));
128 g_string_append_printf (string, "(%s)", cutpoint);
131 g_string_append (string, ".\n");
135 g_string_free (string, FALSE);
142 /* Pops up the Chi-Square dialog box */
144 binomial_dialog (PsppireDataWindow *dw)
148 struct binomial_dialog bin_d;
150 GtkBuilder *xml = builder_new ("binomial.ui");
153 GtkWidget *dialog = get_widget_assert (xml, "binomial-dialog");
157 GtkWidget *dict_view = get_widget_assert (xml, "dict-view");
159 g_object_get (dw->data_editor, "var-store", &vs, NULL);
161 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
163 bin_d.var_view = get_widget_assert (xml, "variables-treeview");
164 bin_d.button1 = get_widget_assert (xml, "radiobutton3");
165 bin_d.prop_entry = get_widget_assert (xml, "proportion-entry");
167 bin_d.cutpoint_entry = get_widget_assert (xml, "cutpoint-entry");
168 bin_d.cutpoint_button = get_widget_assert (xml, "radiobutton4");
170 g_object_get (vs, "dictionary", &bin_d.dict, NULL);
171 g_object_set (dict_view,
173 "predicate", var_is_numeric,
176 g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity),
177 bin_d.cutpoint_entry);
179 g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &bin_d);
181 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
182 dialog_state_valid, &bin_d);
184 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
189 case GTK_RESPONSE_OK:
191 gchar *syntax = generate_syntax (&bin_d);
193 struct getl_interface *sss = create_syntax_string_source (syntax);
194 execute_syntax (sss);
199 case PSPPIRE_RESPONSE_PASTE:
201 gchar *syntax = generate_syntax (&bin_d);
202 paste_syntax_to_window (syntax);
210 g_object_unref (xml);